kamals@poc02:~$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root vg_system -wi-ao---- 63.98g
scratch vg_system -wi-ao---- 465.66g
.
.
swap vg_system -wi-ao---- 16.00g
var vg_system -wi-ao---- 31.99g
kamals@poc02:~$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
vg_system 1 6 0 wz--n- 930.51g 296.88g
kamals@poc02:~$ df -h /scratch/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_system-scratch 459G 726M 435G 1% /scratch
kamals@poc02:~$ sudo umount /scratch
kamals@poc02:~$ sudo e2fsck -f /dev/mapper/vg_system-scratch
e2fsck 1.42.13 (17-May-2015)
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
scratch: 25/30523392 files (16.0% non-contiguous), 2134330/122070016 blocks
kamals@poc02:~$ sudo resize2fs /dev/mapper/vg_system-scratch 450G
resize2fs 1.42.13 (17-May-2015)
Resizing the filesystem on /dev/mapper/vg_system-scratch to 117964800 (4k) blocks.
The filesystem on /dev/mapper/vg_system-scratch is now 117964800 (4k) blocks long.
kamals@poc02:~$ sudo lvreduce -L -9G /dev/mapper/vg_system-scratch
WARNING: Reducing active logical volume to 456.66 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce scratch? [y/n]: y
Size of logical volume vg_system/scratch changed from 465.66 GiB (119209 extents) to 456.66 GiB (116905 extents).
Logical volume scratch successfully resized.
kamals@poc02:~$ sudo mount /dev/mapper/vg_system-scratch /scratch/
kamals@poc02:~$ lsblk | grep scratch
├─vg_system-scratch 252:4 0 456.7G 0 lvm /scratch
kamals@poc02:~$
kamals@poc02:~$ df -h /scratch/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_system-scratch 443G 727M 420G 1% /scratch
kamals@poc02:~$
SWAP Space extend:
===================
kamals@poc02:~$ lsblk | grep swap
├─vg_system-swap 252:1 0 16G 0 lvm [SWAP]
kamals@poc02:~$ sudo swapoff /dev/vg_system/swap
kamals@poc02:~$
kamals@poc02:~$ sudo lvresize -L+9G /dev/vg_system/swap
Size of logical volume vg_system/swap changed from 16.00 GiB (4095 extents) to 25.00 GiB (6399 extents).
Logical volume swap successfully resized.
kamals@poc02:~$ sudo mkswap /dev/vg_system/swap
mkswap: /dev/vg_system/swap: warning: wiping old swap signature.
Setting up swapspace version 1, size = 25 GiB (26839347200 bytes)
no label, UUID=5fbefbfc-b0fc-46d5-8d5e-b547c184ac14
kamals@poc02:~$ sudo swapon /dev/vg_system/swap
kamals@poc02:~$
kamals@poc02:~$ free -th | grep -i swap
Swap: 24G 0B 24G
kamals@poc02:~$
kamals@poc02:~$ lsblk | grep swap
├─vg_system-swap 252:1 0 25G 0 lvm [SWAP]
在这里,我尝试缩小/scratch
数据磁盘9G
并增加空间量SWAP
。
我在这里看到 LVM 的减少/scratch
正在按预期工作(465.66G-9G ~= 456.7G)
,但为什么 FS 大小只是通过减少而产生df -h
的。443G
459G
9G
我再次执行减少1G
,我看到 df 值减少到428G
。
kamals@poc02:~$ df -h /scratch/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_system-scratch 428G 727M 405G 1% /scratch
kamals@poc02:~$
我有几个问题,
我在这里做错了什么吗?
这些步骤是否正确?我可以通过停机来在生产服务器中实施它们吗?
这些步骤是否有可能导致数据丢失?
还有更好的解决办法吗?
太感谢了!
答案1
您使用 450G 作为文件系统大小:
$ sudo resize2fs /dev/mapper/vg_system-scratch 450G
但你的 LV 比这个大(456.66G):
$ sudo lvreduce -L -9G /dev/mapper/vg_system-scratch WARNING: Reducing active logical volume to 456.66 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.)
因此,您可以进一步减小 LV(至 450G),或者通过再次调用resize2fs
.否则 6.66G 将保持未使用状态。
实际上lvreduce
可以--resizefs
选择为您处理文件系统大小调整。
即使您手动执行此操作,也没有实际需要使文件系统小于 LV 大小。如果您将 450G 用于文件系统,则也可以将 450G 用于 LV。不过,使用整数而不是分数会有所帮助。如果您确实希望它为 456.66GiB,则最好用 MiB 来表示。
关于其他丢失的空间,请检查tune2fs -l
该文件系统是否有根保留(Reserved block count
!= 0),如果有,请使用 进行更改tune2fs -m
。如果您不需要/不想要此文件系统的根保留。
答案2
尝试了lvreduce
一下--resizefs
,恢复了17G。
kamals@poc02:~$ sudo lvs
scratch vg_system -wi-ao---- 454.66g
kamals@poc02:~$ df -h /scratch/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_system-scratch 428G 727M 405G 1% /scratch
kamals@poc02:~$ sudo e2fsck -f /dev/mapper/vg_system-scratch
.
.
scratch: 25/28442624 files (16.0% non-contiguous), 2003774/113770496 blocks
kamals@poc02:~$ sudo lvreduce --resizefs -L -3G /dev/mapper/vg_system-scratch
fsck from util-linux 2.27.1
scratch: clean, 25/28442624 files, 2003774/113770496 blocks
resize2fs 1.42.13 (17-May-2015)
Resizing the filesystem on /dev/mapper/vg_system-scratch to 118400000 (4k) blocks.
The filesystem on /dev/mapper/vg_system-scratch is now 118400000 (4k) blocks long.
Size of logical volume vg_system/scratch changed from 454.66 GiB (116393 extents) to 451.66 GiB (115625 extents).
Logical volume scratch successfully resized.
kamals@poc02:~$ sudo mount /dev/mapper/vg_system-scratch /scratch/
kamals@poc02:~$ df -h /scratch/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_system-scratch 445G 727M 422G 1% /scratch
kamals@poc02:~$
kamals@poc02:~$ sudo lvs
scratch vg_system -wi-ao---- 451.66g