在Linux中克隆系统或者是修改磁盘空间的时候会用到mount命令,或者是lvm工具操作系统磁盘
逻辑卷的缩减,有风险,先缩减逻辑边界——在缩减物理边界
注意: 1、不能在线缩减,得先卸载;
2、确保缩减后的空间大小依然能存储原有的所有数据;
3、在缩减之前应该强行检查文件,确保文件系统处于一致性状态
2. 检查一下
e2fsck -f /dev/vg_db5/lv_home
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg_db5/lv_home: 29/32989184 files (0.0% non-contiguous), 2121120/131926016 blocks
3.开始缩小文件系统:
resize2fs /dev/vg_db5/lv_home 1024M
resize2fs 1.41.12 (17-May-2010)
resize2fs: New size smaller than minimum (307344)
显示1G太小了,最小是307344个块。得了,10个G吧
resize2fs /dev/vg_db5/lv_home 10G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg_db5/lv_home to 2621440 (4k) blocks.
The filesystem on /dev/vg_db5/lv_home is now 2621440 blocks long.
4.缩小lv大小:
lvreduce -L 10G /dev/vg_db5/lv_home
WARNING: Reducing active logical volume to 10.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
Size of logical volume vg_db5/lv_home changed from 503.26 GiB (128834 extents) to 10.00 GiB (2560 extents).
Logical volume lv_home successfully resized
vgdisplay 发现空间已经释放出来了
— Volume group —
VG Name vg_db5
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 557.26 GiB
PE Size 4.00 MiB
Total PE 142658
Alloc PE / Size 16384 / 64.00 GiB
Free PE / Size 126274 / 493.26 GiB
VG UUID Ji4TQc-IbhS-O6Cb-XH5Q-q4Uk-DIer-DvSMMD
5.增大LV:lv_root 的大小,增大到500G
lvextend -L 500G -f -r /dev/vg_db5/lv_root
Size of logical volume vg_db5/lv_root changed from 50.00 GiB (12800 extents) to 500.00 GiB (128000 extents).
Logical volume lv_root successfully resized
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_db5-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 32
Performing an on-line resize of /dev/mapper/vg_db5-lv_root to 131072000 (4k) blocks.
The filesystem on /dev/mapper/vg_db5-lv_root is now 131072000 blocks long.
想再增加操作系统大小,看来不用做了。
resize2fs /dev/vg_db5/lv_root 500G
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 131072000 blocks long. Nothing to do!
resize2fs -p /dev/vg_db5/lv_root
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 131072000 blocks long. Nothing to do!
重启之后:
df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_db5-lv_root 493G 6.2G 461G 2% /
tmpfs 160G 144K 160G 1% /dev/shm
/dev/sdq1 477M 37M 415M 9% /boot
/dev/mapper/vg_db5-lv_home 9.8G 37M 9.2G 1% /home
Linux中,进行系统克隆的时候,有些时候相应的硬盘存储容量不够,需要重新分配,这是就用到了lvm,在lvm中挂载的时候,遇到系统正在使用程序,导致分区占用,这时可以用fuser命令进行查看,例如当前lv券被占用,在/dev/mappper下,可以查看:
fuser -m -v /dev/mapper/无法umount的lv券
若是杀掉进程,可以用如下命令:
fuser -m -k /dev/mapper/无法umount的lv券 即可