vmwareworkstation下扩展Ubuntu磁盘空间

本文详细介绍了如何通过扩展虚拟机磁盘、创建新分区并将其加入到现有的逻辑卷中来增加Zabbix服务器的可用磁盘空间。包括使用fdisk进行磁盘分区、pvcreate创建物理卷、vgextend扩展卷组以及resize2fs调整文件系统大小等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天发现安装zabbix的Ubuntu虚拟机的磁盘控制不足导致数据库掉线了。需要扩展下磁盘空间。

操作思路如下图
这里写图片描述
方法:
1.先关闭虚拟机,在vmwareworkstation界面下扩展磁盘
2.打开虚拟机,df -h 查看文件系统空闲磁盘使用情况

root@zabbix:~# df -h
Filesystem                   Size  Used Avail Use% Mounted on
udev                         980M     0  980M   0% /dev
tmpfs                        201M  5.7M  195M   3% /run
/dev/mapper/zabbix--vg-root  7.1G  6.5G  227M  97% /
tmpfs                       1001M     0 1001M   0% /dev/shm
tmpfs                        5.0M     0  5.0M   0% /run/lock
tmpfs                       1001M     0 1001M   0% /sys/fs/cgroup
/dev/sda1                    472M  210M  238M  47% /boot

发现空闲的空间没变,fdisk -l查看磁盘情况

root@zabbix:~#  fdisk -l
Disk /dev/sda: 29.8 GiB, 31997296640 bytes, 62494720 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xebcdc8fd

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048   999423   997376  487M 83 Linux
/dev/sda2       1001470 20477951 19476482  9.3G  5 Extended
/dev/sda5       1001472 20477951 19476480  9.3G 8e Linux LVM


Disk /dev/mapper/zabbix--vg-root: 7.3 GiB, 7822376960 bytes, 15278080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/zabbix--vg-swap_1: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

这里看到了sda这个盘已经扩到了29.8G,但是系统只有sda1,5这2个分区(sda2只扩展出了sda5这一个分区)。

使用 fdisk /dev/sda为磁盘sda分区

root@zabbix:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

查看磁盘空闲的分区

Command (m for help): F
Unpartitioned space /dev/sda: 20 GiB, 21512585216 bytes, 42016768 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

   Start      End  Sectors Size
20477952 62494719 42016768  20G

新建一个分区 sda3

Command (m for help): n
Partition type
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): p
Partition number (3,4, default 3): 
First sector (999424-62494719, default 999424): 20477952
Last sector, +sectors or +size{K,M,G,T,P} (20477952-62494719, default 62494719): 

Created a new partition 3 of type 'Linux' and of size 20 GiB.

保存

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

重启后生效

root@zabbix:~# reboot

结果查看

root@zabbix:~# fdisk -l
Disk /dev/sda: 29.8 GiB, 31997296640 bytes, 62494720 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xebcdc8fd

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048   999423   997376  487M 83 Linux
/dev/sda2        1001470 20477951 19476482  9.3G  5 Extended
/dev/sda3       20477952 62494719 42016768   20G 83 Linux
/dev/sda5        1001472 20477951 19476480  9.3G 8e Linux LVM

Partition table entries are not in disk order.


Disk /dev/mapper/zabbix--vg-root: 7.3 GiB, 7822376960 bytes, 15278080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/zabbix--vg-swap_1: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

到此为止,已经完成了sda3这个新的分区的建立。

sda3加入pv物理卷

root@zabbix:~# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
root@zabbix:~# pvs
  PV         VG        Fmt  Attr PSize  PFree 
  /dev/sda3            lvm2 ---  20.04g 20.04g
  /dev/sda5  zabbix-vg lvm2 a--   9.29g     0 

查看现有vg卷组

root@zabbix:~# vgs
VG #PV #LV #SN Attr VSize VFree
zabbix-vg 1 2 0 wz–n- 9.29g 0

将新增PV /dev/sda3加入卷组 zabbix-vg

root@zabbix:~# vgextend zabbix-vg /dev/sda3
  Volume group "zabbix-vg" successfully extended
root@zabbix:~# vgs
  VG        #PV #LV #SN Attr   VSize  VFree 
  zabbix-vg   2   2   0 wz--n- 29.32g 20.03g

查看lv逻辑卷
root@zabbix:~# lvs

  LV     VG        Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root   zabbix-vg -wi-ao---- 7.29g                                                    
  swap_1 zabbix-vg -wi-ao---- 2.00g
root@zabbix:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/zabbix-vg/root
  LV Name                root
  VG Name                zabbix-vg
  LV UUID                u0VBi0-Bxae-QKGS-EL6C-2jGU-AwC2-FlUpw0
  LV Write Access        read/write
  LV Creation host, time zabbix, 2017-11-09 21:46:01 +0800
  LV Status              available
  # open                 1
  LV Size                7.29 GiB
  Current LE             1865
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

  --- Logical volume ---
  LV Path                /dev/zabbix-vg/swap_1
  LV Name                swap_1
  VG Name                zabbix-vg
  LV UUID                yUenJh-9djJ-VYsn-Sjyj-T4O6-88zS-9xfnTS
  LV Write Access        read/write
  LV Creation host, time zabbix, 2017-11-09 21:46:02 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

扩展 /dev/zabbix-vg/root这个逻辑卷

root@zabbix:~# lvextend -L +20G /dev/zabbix-vg/root
  Size of logical volume zabbix-vg/root changed from 7.29 GiB (1865 extents) to 27.29 GiB (6985 extents).
  Logical volume root successfully resized.

拉伸文件系统,覆盖/dev/zabbix-vg/root整个卷
拉伸前:

root@zabbix:~#  df -h
Filesystem                   Size  Used Avail Use% Mounted on
udev                         980M     0  980M   0% /dev
tmpfs                        201M  5.7M  195M   3% /run
/dev/mapper/zabbix--vg-root  7.1G  6.5G  221M  97% /
tmpfs                       1001M     0 1001M   0% /dev/shm
tmpfs                        5.0M     0  5.0M   0% /run/lock
tmpfs                       1001M     0 1001M   0% /sys/fs/cgroup
/dev/sda1                    472M  210M  238M  47% /boot

拉伸–高危操作:

root@zabbix:~# resize2fs /dev/zabbix-vg/root
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/zabbix-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/zabbix-vg/root is now 7152640 (4k) blocks long.

拉伸后:

root@zabbix:~# df -h
Filesystem                   Size  Used Avail Use% Mounted on
udev                         980M     0  980M   0% /dev
tmpfs                        201M  5.7M  195M   3% /run
/dev/mapper/zabbix--vg-root   27G  6.5G   20G  26% /
tmpfs                       1001M     0 1001M   0% /dev/shm
tmpfs                        5.0M     0  5.0M   0% /run/lock
tmpfs                       1001M     0 1001M   0% /sys/fs/cgroup
/dev/sda1                    472M  210M  238M  47% /boot
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值