如果要减小lv的容量做好能用图形化界面来做,如果不能使用图形化界面的话,需要严格的按照如下步骤进行,否则可能会损坏文件系统,图形化的LVM软件包为:system-config-lvm
步骤(必须严格执行):
A.对要减小容量的文件系统卸载。根文件系统是无法卸载的。
B.使用e2fsck –f检查lv的文件系统
C.使用resize2fs减小文件系统的大小。
resize2fs /dev/vg-name/lv-name <减小之后的大小>
D.减小LV的大小。lvreduce或lvresize这一步最好用PE的数量。
示例:
步骤1:先卸载文件系统
[root@Server3 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 9.9G 7.8G 1.6G 83% / tmpfs 245M 0 245M 0% /dev/shm /dev/sda1 194M 28M 156M 16% /boot /dev/mapper/DATA_01-lv--01 496M 6.9M 464M 2% /backup
[root@Server3 ~]# umount /backup/ [root@Server3 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 9.9G 7.8G 1.6G 83% / tmpfs 245M 0 245M 0% /dev/shm /dev/sda1 194M 28M 156M 16% /boot [root@Server3 ~]#
步骤2:检查文件系统
[root@Server3 ~]# e2fsck -f /dev/DATA_01/lv-01 e2fsck 1.41.12 (17-May-2010) 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/DATA_01/lv-01: 12/131072 files (0.0% non-contiguous), 23571/524288 blocks [root@Server3 ~]#
步骤3:使用resize2fs减小文件系统的大小
说明:这里减小到50M
[root@Server3 ~]# resize2fs /dev/DATA_01/lv-01 50M resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/DATA_01/lv-01 to 51200 (1k) blocks. The filesystem on /dev/DATA_01/lv-01 is now 51200 blocks long. [root@Server3 ~]#
步骤4:减小LV的大小
说明:LV原先的大小是512M,现在减小到50M,减小了512-50=462M。
root@Server3 ~]# lvresize -L -462M /dev/DATA_01/lv-01 Rounding size to boundary between physical extents: 448.00 MiB WARNING: Reducing active logical volume to 64.00 MiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv-01? [y/n]: y Reducing logical volume lv-01 to 64.00 MiB Logical volume lv-01 successfully resized [root@Server3 ~]# lvs LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert lv-01 DATA_01 -wi-a--- 64.00m [root@Server3 ~]#
步骤5:挂载测试数据是否还在
[root@Server3 ~]# mount /dev/DATA_01/lv-01 /backup/ [root@Server3 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 9.9G 7.8G 1.6G 83% / tmpfs 245M 0 245M 0% /dev/shm /dev/sda1 194M 28M 156M 16% /boot /dev/mapper/DATA_01-lv--01 49M 5.7M 41M 13% /backup
[root@Server3 ~]# ll /backup/ total 638 drwx------ 2 root root 12288 Jul 17 02:10 lost+found -rw-r--r-- 1 root root 641020 Jul 17 02:11 services [root@Server3 ~]#