CentOS无损调整home,root磁盘的大小
调整硬盘分区大小
想增加root空间,减少home空间。
需要说明的是整个操作需要使用root用户。
1.查看硬盘使用情况。
[root@Slave1 /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_slave6-lv_root 50G 22G 26G 46% / tmpfs 7.8G 160K 7.8G 1% /dev/shm /dev/sda1 485M 40M 420M 9% /boot /dev/mapper/vg_slave6-lv_home 860G 25G 792G 4% /home
可以看到home的大小是860G,而root的大小只有50G。
我的目标是将home的大小缩小为200G,其余的加到root中
接下来好戏上演了:
2.卸载/home
[root@Slave1 /]# umount /home umount: /home: device is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1))
出现这种情况表示有应用程序正在占用home,强制清除掉就可以,使用下边的命令
[root@Slave1 /]# fuser -km /home
强制清除后在进行卸载
[root@Slave1 /]# umount /home
3、调整分区大小
[root@Slave1 /]# e2fsck -f /dev/mapper/vg_slave6-lv_home 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/mapper/vg_slave6-lv_home: 255/57229312 files (1.2% non-contiguous), 10040281/228912128 blocks
设置home的大小为200G
[root@Slave1 /]# resize2fs -p /dev/mapper/vg_slave6-lv_home 200G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/mapper/vg_slave6-lv_home to 52428800 (4k) blocks. Begin pass 2 (max = 32992) Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 3 (max = 6986) Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 4 (max = 123) Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX The filesystem on /dev/mapper/vg_slave6-lv_home is now 52428800 blocks long.
挂载home
[root@Slave1 /]# mount /home [root@Slave1 /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_slave6-lv_root 50G 22G 26G 46% / tmpfs 7.8G 232K 7.8G 1% /dev/shm /dev/sda1 485M 40M 420M 9% /boot /dev/mapper/vg_slave6-lv_home 197G 25G 163G 14% /home
可以看到home的磁盘大小已经减小到了197G,剩余3G的空间应该是被用掉了
4.释放空间
[root@Slave1 /]# lvreduce -L 200G /dev/mapper/vg_slave6-lv_home WARNING: Reducing active and open logical volume to 200.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv_home? [y/n]: y Reducing logical volume lv_home to 200.00 GiB Logical volume lv_home successfully resized
[root@Slave1 /]# vgdisplay --- Volume group --- VG Name vg_slave6 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 3 Max PV 0 Cur PV 1 Act PV 1 VG Size 931.02 GiB PE Size 4.00 MiB Total PE 238341 Alloc PE / Size 65994 / 257.79 GiB Free PE / Size 172347 / 673.23 GiB VG UUID g1cRWV-O788-QKCc-lQG0-JaEp-s2BB-xNHxF3
会看到有637.23G的剩余空间,接下来要做的就是把这些空间加载到root中
5.增加空余空间到root
[root@Slave1 /]# lvextend -L +673.23G /dev/mapper/vg_slave6-lv_root Rounding size to boundary between physical extents: 673.23 GiB Extending logical volume lv_root to 723.23 GiB Logical volume lv_root successfully resized
接下来这个操作可能需要时间长点,加载的空间越大时间越长。
root@Slave1 /]# lvextend -L +673.23G /dev/mapper/vg_slave6-lv_root Rounding size to boundary between physical extents: 673.23 GiB Extending logical volume lv_root to 723.23 GiB Logical volume lv_root successfully resized [root@Slave1 /]# resize2fs -p /dev/mapper/vg_slave6-lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/vg_slave6-lv_root is mounted on /; on-line resizing required old desc_blocks = 4, new_desc_blocks = 46 Performing an on-line resize of /dev/mapper/vg_slave6-lv_root to 189590528 (4k) blocks. The filesystem on /dev/mapper/vg_slave6-lv_root is now 189590528 blocks long.
查看一下
[root@Slave1 /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_slave6-lv_root 712G 22G 655G 4% / tmpfs 7.8G 232K 7.8G 1% /dev/shm /dev/sda1 485M 40M 420M 9% /boot /dev/mapper/vg_slave6-lv_home 197G 25G 163G 14% /home
大功告成,home,root中的内容没有丢失