vmware虛擬機擴容磁碟空間
- 2019 年 11 月 20 日
- 筆記
主要步驟:
- vmware宿主機編輯虛擬機配置擴容伺服器磁碟並啟動虛擬機
- fdisk新建分區
- pvcreate新建物理卷
- vgextend擴展卷組
- lvextend擴容邏輯卷
- xfs_growfs擴容文件系統
1.fdisk新建分區
[root@6_90 ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 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 label type: dos Disk identifier: 0x0007b2cf Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 419430399 209202176 8e Linux LVM Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p Partition number (3,4, default 3): First sector (419430400-838860799, default 419430400): Using default value 419430400 Last sector, +sectors or +size{K,M,G} (419430400-838860799, default 838860799): Using default value 838860799 Partition 3 of type Linux and of size 200 GiB is set Command (m for help): p Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 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 label type: dos Disk identifier: 0x0007b2cf Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 419430399 209202176 8e Linux LVM /dev/sda3 419430400 838860799 209715200 83 Linux Command (m for help): t Partition number (1-3, default 3): 3 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): p Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 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 label type: dos Disk identifier: 0x0007b2cf Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 419430399 209202176 8e Linux LVM /dev/sda3 419430400 838860799 209715200 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: 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) Syncing disks. 根據提示需要同步磁碟 [root@6_90 ~]# partprobe [root@6_90 ~]# fdisk -l Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 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 label type: dos Disk identifier: 0x0007b2cf Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 419430399 209202176 8e Linux LVM /dev/sda3 419430400 838860799 209715200 8e Linux LVM Disk /dev/mapper/centos-root: 193.2 GB, 193248362496 bytes, 377438208 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/centos-swap: 21.0 GB, 20971520000 bytes, 40960000 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 [root@6_90 ~]# pvscan PV /dev/sda2 VG centos lvm2 [199.51 GiB / 0 free] Total: 1 [199.51 GiB] / in use: 1 [199.51 GiB] / in no VG: 0 [0 ] [root@6_90 ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size 199.51 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 51074 Free PE 0 Allocated PE 51074 PV UUID U7l4WJ-kwxY-DgvQ-eZX3-F3YG-71GI-O54rin
2.pvcreate新建物理卷
[root@6_90 ~]# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created
3.vgextend擴展卷組
[root@6_90 ~]# vgscan Reading all physical volumes. This may take a while... Found volume group "centos" using metadata type lvm2 [root@6_90 ~]# vgextend centos /dev/sda3 Volume group "centos" successfully extended
4.lvextend擴容邏輯卷
[root@6_90 ~]# lvscan ACTIVE '/dev/centos/swap' [19.53 GiB] inherit ACTIVE '/dev/centos/root' [179.98 GiB] inherit [root@6_90 ~]# ls /dev/mapper/centos-root /dev/mapper/centos-root [root@6_90 ~]# lvextend -l +100%FREE /dev/mapper/centos-root Size of logical volume centos/root changed from 179.98 GiB (46074 extents) to 379.97 GiB (97273 extents). Logical volume root successfully resized.
5.xfs_growfs擴容文件系統
[root@6_90 ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 180G 3.7G 177G 3% / devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs tmpfs 3.9G 281M 3.6G 8% /run tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 xfs 497M 126M 371M 26% /boot tmpfs tmpfs 783M 0 783M 0% /run/user/1000 [root@6_90 ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=11794944 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=47179776, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=23037, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 47179776 to 99607552 [root@6_90 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 380G 3.7G 377G 1% / devtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 281M 3.6G 8% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 497M 126M 371M 26% /boot tmpfs 783M 0 783M 0% /run/user/1000

