LINUX本地磁盘DISK空间扩容
vmware虚拟机本地磁盘空间不足,虚拟机层面扩容原有磁盘/dev/sda从50G到100G,系统层面fdisk划分磁盘分区,创建pv,添加到vg,扩展lv,xfs_growfs刷新文件系统空间。
1. 磁盘空间现状
df显示/总大小50G
[root@glodendb ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 45G 18G 27G 41% /
devtmpfs 24G 0 24G 0% /dev
tmpfs 24G 0 24G 0% /dev/shm
tmpfs 24G 8.9M 24G 1% /run
tmpfs 24G 0 24G 0% /sys/fs/cgroup
/dev/sda1 1014M 133M 882M 14% /boot
/dev/loop0 4.2G 4.2G 0 100% /mnt/redhat_iso
tmpfs 4.8G 0 4.8G 0% /run/user/0
lsblk显示sda已经扩容到100G
[root@glodendb ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 49G 0 part
├─rhel-root 253:0 0 44.1G 0 lvm /
└─rhel-swap 253:1 0 5G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
loop0 7:0 0 4.2G 0 loop /mnt/redhat_iso
fdisk显示剩余50G空间未创建磁盘分区
[root@glodendb ~]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000b5694
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 104857599 51379200 8e Linux LVM
Disk /dev/mapper/rhel-root: 47.3 GB, 47303360512 bytes, 92389376 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/rhel-swap: 5301 MB, 5301600256 bytes, 10354688 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/loop0: 4497 MB, 4497342464 bytes, 8783872 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: 0x277a1f7d
Device Boot Start End Blocks Id System
/dev/loop0p1 * 0 8783871 4391936 0 Empty
/dev/loop0p2 860440 877859 8710 ef EFI (FAT-12/16/32)
2. fdisk划分新磁盘分区
[root@glodendb ~]# 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): 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 (104857600-209715199, default 104857600):
Using default value 104857600
Last sector, +sectors or +size{K,M,G} (104857600-209715199, default 209715199):
Using default value 209715199
Partition 3 of type Linux and of size 50 GiB is set
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.
此时从lsblk不能看到新磁盘分区,需要partprobe刷新分区表
[root@glodendb ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 49G 0 part
├─rhel-root 253:0 0 44.1G 0 lvm /
└─rhel-swap 253:1 0 5G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
loop0 7:0 0 4.2G 0 loop /mnt/redhat_iso
[root@glodendb ~]# partprobe /dev/sda
[root@glodendb ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 49G 0 part
│ ├─rhel-root 253:0 0 44.1G 0 lvm /
│ └─rhel-swap 253:1 0 5G 0 lvm [SWAP]
└─sda3 8:3 0 50G 0 part
sr0 11:0 1 1024M 0 rom
loop0 7:0 0 4.2G 0 loop /mnt/redhat_iso
3. 新磁盘添加VG扩容LV
逻辑卷现状
[root@glodendb ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- <49.00g 4.00m
[root@glodendb ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz--n- <49.00g 4.00m
[root@glodendb ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 44.05g
swap rhel -wi-ao---- <4.94g
创建PV
[root@glodendb ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
[root@glodendb ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- <49.00g 4.00m
/dev/sda3 lvm2 --- 50.00g 50.00g
扩容VG
[root@glodendb ~]# vgextend rhel /dev/sda3
Volume group "rhel" successfully extended
[root@glodendb ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 2 2 0 wz--n- 98.99g 50.00g
扩容LV
[root@glodendb ~]# lvextend -L +50G /dev/rhel/root
Size of logical volume rhel/root changed from 44.05 GiB (11278 extents) to 94.05 GiB (24078 extents).
Logical volume rhel/root successfully resized.
[root@glodendb ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 94.05g
swap rhel -wi-ao---- <4.94g
此时DF还不能看到容量增加
[root@glodendb ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs 45G 18G 27G 41% /
devtmpfs devtmpfs 24G 0 24G 0% /dev
tmpfs tmpfs 24G 0 24G 0% /dev/shm
tmpfs tmpfs 24G 8.9M 24G 1% /run
tmpfs tmpfs 24G 0 24G 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 145M 869M 15% /boot
/dev/loop0 iso9660 4.2G 4.2G 0 100% /mnt/redhat_iso
tmpfs tmpfs 4.8G 0 4.8G 0% /run/user/0
xfs_growfs刷新文件系统空间
[root@glodendb ~]# xfs_growfs /dev/rhel/root
meta-data=/dev/mapper/rhel-root isize=512 agcount=4, agsize=2887168 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=11548672, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=5639, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 11548672 to 24655872
[root@glodendb ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 95G 18G 77G 19% /
devtmpfs 24G 0 24G 0% /dev
tmpfs 24G 0 24G 0% /dev/shm
tmpfs 24G 8.9M 24G 1% /run
tmpfs 24G 0 24G 0% /sys/fs/cgroup
/dev/sda1 1014M 145M 869M 15% /boot
/dev/loop0 4.2G 4.2G 0 100% /mnt/redhat_iso
tmpfs 4.8G 0 4.8G 0% /run/user/0
[root@glodendb ~]#