缩小PV空间到120G,即PV上的vg00已将缩小到120G pvresize --setphysicalvolumesize 120g /dev/sda2
机器上有一块900G本地的本地磁盘,安装系统时将900G的空间所有扩到了一个VG卷组中,即vg00,并建立了多个LV逻辑卷,LV逻辑卷占用了vg00卷组120G的空间,即卷组vg00还剩770G左右的空闲空间;此种文件系统格式不符合应用的规范标准,标准的文件系统规范为建立一个120G的卷组Vg00,使用Vg00卷组建立系统必要的LV逻辑卷,而剩下的770G空间新建卷组Vg01。为了知足应用需求,现将900G盘上的vg00空间缩小为120G,而后新建vg01使用剩下的770G空间。在不影响系统正常的状况下实现PV/VG的缩小。因为LV占用了120G的VG,即将VG空间缩小到120G方可最大化利用vg00卷组,为了达到缩小Vg00的需求,经过缩小PV来强制缩小Vg空间。
现有文件系统linux
[root@sishb00302 ~]# vgs VG #PV #LV #SN Attr VSize VFree vg00 1 6 0 wz--n- 837.84g 721.84g [root@sishb00302 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert crashvol vg00 -wi-ao---- 32.00g homevol vg00 -wi-ao---- 2.00g rootvol vg00 -wi-ao---- 20.00g swapvol vg00 -wi-ao---- 32.00g tmpvol vg00 -wi-ao---- 10.00g varvol vg00 -wi-ao---- 20.00g [root@sishb00302 ~]# 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: 900.2 GB, 900151926784 bytes, 1758109232 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 262144 bytes / 262144 bytes Disk label type: dos Disk identifier: 0x000cd03d Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 1758107647 878540800 8e Linux LVM
减少PVapp
[root@sishb00302 ~]# pvresize --setphysicalvolumesize 120g /dev/sda2 Physical volume "/dev/sda2" changed 1 physical volume(s) resized / 0 physical volume(s) not resized [root@sishb00302 ~]# vgs VG #PV #LV #SN Attr VSize VFree vg00 1 6 0 wz--n- 120.00g 4.00g [root@sishb00302 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 vg00 lvm2 a-- 120.00g 4.00g
删除原有的900G的/dev/sda2分区,新建/dev/sda2分区为120G,剩余空间为/dev/sda3分区ide
[root@sishb00302 ~]# 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: 900.2 GB, 900151926784 bytes, 1758109232 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 262144 bytes / 262144 bytes Disk label type: dos Disk identifier: 0x000cd03d Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 1758107647 878540800 8e Linux LVM Command (m for help): d Partition number (1,2, default 2): Partition 2 is deleted Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (1026048-1758109231, default 1026048): Using default value 1026048 Last sector, +sectors or +size{K,M,G} (1026048-1758109231, default 1758109231): +120G Partition 2 of type Linux and of size 120 GiB is set Command (m for help): t Partition number (1,2, default 2): Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): Using default response p Partition number (3,4, default 3): First sector (252684288-1758109231, default 252684288): Using default value 252684288 Last sector, +sectors or +size{K,M,G} (252684288-1758109231, default 1758109231): Using default value 1758109231 Partition 3 of type Linux and of size 717.9 GiB is set Command (m for help): t Partition number (1-3, default 3): Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to '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.
移除/dev/vg00/crashvol文件系统ui
[root@sishb00302 ~]# umount /var/crash/ [root@sishb00302 ~]# lvremove /dev/vg00/crashvol Do you really want to remove active logical volume vg00/crashvol? [y/n]: y Logical volume "crashvol" successfully removed [root@sishb00302 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert homevol vg00 -wi-ao---- 2.00g rootvol vg00 -wi-ao---- 20.00g swapvol vg00 -wi-ao---- 32.00g tmpvol vg00 -wi-ao---- 10.00g varvol vg00 -wi-ao---- 20.00g [root@sishb00302 ~]# vgs VG #PV #LV #SN Attr VSize VFree vg00 1 5 0 wz--n- 120.00g 36.00g
/dev/vg00/varvol逻辑卷在线扩容3d
[root@sishb00302 ~]# lvextend -L +30g /dev/vg00/varvol -r Size of logical volume vg00/varvol changed from 20.00 GiB (5120 extents) to 50.00 GiB (12800 extents). Logical volume vg00/varvol successfully resized. resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/mapper/vg00-varvol is mounted on /var; on-line resizing required old_desc_blocks = 3, new_desc_blocks = 7 The filesystem on /dev/mapper/vg00-varvol is now 13107200 blocks long. [root@sishb00302 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert homevol vg00 -wi-ao---- 2.00g rootvol vg00 -wi-ao---- 20.00g swapvol vg00 -wi-ao---- 32.00g tmpvol vg00 -wi-ao---- 10.00g varvol vg00 -wi-ao---- 50.00g
修改fatab文件code
修改前 [root@sishb00302 ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Tue Mar 6 11:44:46 2018 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/vg00-rootvol / ext4 defaults 1 1 UUID=c04bb69b-1380-4c31-b4f4-9bfacb5d9063 /boot ext4 defaults 1 2 /dev/mapper/vg00-homevol /home ext4 defaults 1 2 /dev/mapper/vg00-tmpvol /tmp ext4 defaults 1 2 /dev/mapper/vg00-varvol /var ext4 defaults 1 2 /dev/mapper/vg00-crashvol /var/crash ext4 defaults 1 2 /dev/mapper/vg00-swapvol swap swap defaults 0 0 修改后 [root@sishb00302 ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Tue Mar 6 11:44:46 2018 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/vg00-rootvol / ext4 defaults 1 1 UUID=c04bb69b-1380-4c31-b4f4-9bfacb5d9063 /boot ext4 defaults 1 2 /dev/mapper/vg00-homevol /home ext4 defaults 1 2 /dev/mapper/vg00-tmpvol /tmp ext4 defaults 1 2 /dev/mapper/vg00-varvol /var ext4 defaults 1 2 /dev/mapper/vg00-swapvol swap swap defaults 0 0
关机重启系统,从而释放/Idev/sda3分区的空间ci
空间释放后,再次建立vg01卷组rem
[root@sishb00302 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert homevol vg00 -wi-ao---- 2.00g rootvol vg00 -wi-ao---- 20.00g swapvol vg00 -wi-ao---- 32.00g tmpvol vg00 -wi-ao---- 10.00g varvol vg00 -wi-ao---- 50.00g [root@sishb00302 ~]# vgcreate /dev/vg01 /dev/sda3 Physical volume "/dev/sda3" successfully created. Volume group "vg01" successfully created [root@sishb00302 ~]# vgs VG #PV #LV #SN Attr VSize VFree vg00 1 5 0 wz--n- 120.00g 6.00g vg01 1 0 0 wz--n- 717.84g 717.84g [root@sishb00302 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert homevol vg00 -wi-ao---- 2.00g rootvol vg00 -wi-ao---- 20.00g swapvol vg00 -wi-ao---- 32.00g tmpvol vg00 -wi-ao---- 10.00g varvol vg00 -wi-ao---- 50.00g
最终实现了vg00文件系统从900G减少到了120G,并新建了vg01卷组it