LVM缩容
当前环境
root@jmk:~/shell# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
nvme0n1 259:0 0 953.9G 0 disk
|-nvme0n1p1 259:1 0 512M 0 part /boot/efi
|-nvme0n1p2 259:2 0 488M 0 part /boot
`-nvme0n1p3 259:3 0 952.9G 0 part
|-jmk--vg-root 254:0 0 27.9G 0 lvm /
|-jmk--vg-swap_1 254:1 0 976M 0 lvm [SWAP]
|-jmk--vg-home 254:2 0 100G 0 lvm /home
|-jmk--vg-wxy 254:3 0 700G 0 lvm /wxy
|-jmk--vg-docker 254:4 0 30G 0 lvm /var/lib/docker
`-jmk--vg-data 254:5 0 94G 0 lvm /data
需求
- 将
data
分区缩小到10G
,并将空出的空间给到wxy
开始操作
取消挂载
在进行容量操作的时候,需要先取消挂载
root@jmk:~/shell# umount /data
root@jmk:~/shell# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
nvme0n1 259:0 0 953.9G 0 disk
|-nvme0n1p1 259:1 0 512M 0 part /boot/efi
|-nvme0n1p2 259:2 0 488M 0 part /boot
`-nvme0n1p3 259:3 0 952.9G 0 part
|-jmk--vg-root 254:0 0 27.9G 0 lvm /
|-jmk--vg-swap_1 254:1 0 976M 0 lvm [SWAP]
|-jmk--vg-home 254:2 0 100G 0 lvm /home
|-jmk--vg-wxy 254:3 0 700G 0 lvm /wxy
|-jmk--vg-docker 254:4 0 30G 0 lvm /var/lib/docker
`-jmk--vg-data 254:5 0 94G 0 lvm
root@jmk:~/shell#
检查一致性
root@jmk:~# e2fsck -f /dev/jmk-vg/data
e2fsck 1.47.0 (5-Feb-2023)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/jmk-vg/data: 12/6160384 files (0.0% non-contiguous), 533162/24641536 blocks
root@jmk:~#
调整逻辑边界空间大小
root@jmk:~# resize2fs /dev/jmk-vg/data 10G
resize2fs 1.47.0 (5-Feb-2023)
Resizing the filesystem on /dev/jmk-vg/data to 2621440 (4k) blocks.
The filesystem on /dev/jmk-vg/data is now 2621440 (4k) blocks long.
root@jmk:~#
逻辑卷缩减
root@jmk:~# lvreduce -L 10G /dev/jmk-vg/data
WARNING: Reducing active logical volume to 10.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce jmk-vg/data? [y/n]: y
Size of logical volume jmk-vg/data changed from 94.00 GiB (24064 extents) to 10.00 GiB (2560 extents).
Logical volume jmk-vg/data successfully resized.
root@jmk:~#
检查
root@jmk:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
nvme0n1 259:0 0 953.9G 0 disk
|-nvme0n1p1 259:1 0 512M 0 part /boot/efi
|-nvme0n1p2 259:2 0 488M 0 part /boot
`-nvme0n1p3 259:3 0 952.9G 0 part
|-jmk--vg-root 254:0 0 27.9G 0 lvm /
|-jmk--vg-swap_1 254:1 0 976M 0 lvm [SWAP]
|-jmk--vg-home 254:2 0 100G 0 lvm /home
|-jmk--vg-wxy 254:3 0 700G 0 lvm /wxy
|-jmk--vg-docker 254:4 0 30G 0 lvm /var/lib/docker
`-jmk--vg-data 254:5 0 10G 0 lvm
root@jmk:~#
挂载
root@jmk:~# mount /dev/jmk-vg/data /data/
root@jmk:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.8G 0 3.8G 0% /dev
tmpfs 767M 3.2M 764M 1% /run
/dev/mapper/jmk--vg-root 28G 4.9G 22G 19% /
tmpfs 3.8G 84K 3.8G 1% /dev/shm
tmpfs 5.0M 12K 5.0M 1% /run/lock
/dev/nvme0n1p2 456M 68M 364M 16% /boot
/dev/mapper/jmk--vg-docker 30G 5.0G 23G 18% /var/lib/docker
/dev/mapper/jmk--vg-home 98G 6.5G 87G 7% /home
/dev/mapper/jmk--vg-wxy 688G 181G 473G 28% /wxy
/dev/nvme0n1p1 511M 5.9M 506M 2% /boot/efi
overlay 30G 5.0G 23G 18% /var/lib/docker/overlay2/f09763168435f4be6ce5adf352d0654ad28506aec40ba4c387a190a364906f9f/merged
overlay 30G 5.0G 23G 18% /var/lib/docker/overlay2/bab66014a7a556344e6483ba7e3ef7b97b915d669ec37dcef548e0925df51ff6/merged
overlay 30G 5.0G 23G 18% /var/lib/docker/overlay2/834e9bd560c81d329d3eae63e15305931abaf18d862ceeb3f6b16ac7b3139d47/merged
tmpfs 767M 4.0K 767M 1% /run/user/1000
/dev/mapper/jmk--vg-data 9.4G 32K 8.8G 1% /data
root@jmk:~# ls /data/
log.txt lost+found
root@jmk:~#
可以看到,此时容量已经调整,并且文件依旧存在