Extend Linux root directory size

Requirements: The Linux root directory is too small to meet the usage requirements, and the disk space under /home needs to be transferred to the root directory
Goal: transfer the 341G space under /home to 200G under the root directory
Steps:
Check the size of the disk space, the capacity of /home is 341G, use 8.8G, the capacity of / root directory is 50G, use 28G
[ root@244  ~]#  df -h
filesystem capacity used free used %% mount point
/dev/mapper/vg_244-lv_root        50G   28G   19G  60% /
tmpfs                 499M     0  499M   0% /dev/shm
/dev/sda1             485M  162M  298M  36% /boot
/dev/mapper/vg_244-lv_home      341G  8.8G  315G   3% /home
 unmount /home
[ root@244  /]#  umount /home
umount /home If you are prompted that it cannot be unmounted, there is a process occupying /home. Use the following command to terminate the occupying process:
[ root@244  /]#  fuser -m /home
Check that /home has been uninstalled
[ root@244  /]#  df -h
filesystem capacity used free used %% mount point
/dev/mapper/vg_244-lv_root      50G   28G   19G  60% /
tmpfs                 499M     0  499M   0% /dev/shm
/dev/sda1             485M  162M  298M  36% /boot
Resize the partition to 150G
The resize2fs command is used to increase or shrink the size of an unmounted "ext2/ext3" filesystem. If the file system is in the mount state, it can only be expanded, provided that the kernel supports online resize
[ root@244  /]#  resize2fs -p /dev/mapper/vg_244-lv_home 150G
resize2fs 1.42.2 (27-Mar-2012)
Please run 'e2fsck -f /dev/mapper/vg_244-lv_home' first.
According to the prompt, you need to execute e2fsck first
[ root@244  /]#  e2fsck -f /dev/mapper/vg_244-lv_home
e2fsck 1.42.2 (27-Mar-2012)
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_244-lv_home: 13478/22650880 files (0.2% non-contiguous), 2563008/90589184 blocks
After the execution is complete, execute resize2fs
[ root@244  /]#  resize2fs -p /dev/mapper/vg_244-lv_home 150G
resize2fs 1.42.2 (27-Mar-2012)
Resizing the filesystem on /dev/mapper/vg_244-lv_home to 39321600 (4k) blocks.
Begin pass 2 (max = 160645)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 2765)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 1419)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/vg_244-lv_home is now 39321600 blocks long.
Mount /home and view the disk
[ root@244  /]#  mount /home/
[ root@244  /]#  df -h
filesystem capacity used free used %% mount point
/dev/mapper/vg_244-lv_root           50G   28G   19G  60% /
tmpfs                 499M     0  499M   0% /dev/shm
/dev/sda1             485M  162M  298M  36% /boot
/dev/mapper/vg_244-lv_home         148G  4.4G  136G   4% /home
 
[ root@244  /]#  lvreduce -L 150G /dev/mapper/vg_244-lv_home 
  WARNING: Reducing active and open logical volume to 150.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 150.00 GiB
  Logical volume lv_home successfully resized
[ root@244  /]#  lvextend -L +200G /dev/mapper/vg_244-lv_root 
  Extending logical volume lv_root to 250.00 GiB
  Insufficient free space: 51200 extents needed, but only 50066 available
[ root@244  /]# lvextend -L +100G /dev/mapper/vg_244-lv_root    
  Extending logical volume lv_root to 150.00 GiB
  Logical volume lv_root successfully resized
[ root@244  /]#  resize2fs -p /dev/mapper/vg_244-lv_root 
resize2fs 1.42.2 (27-Mar-2012)
Filesystem at /dev/mapper/vg_244-lv_root is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 16
Performing an on-line resize of /dev/mapper/vg_244-lv_root to 64374784 (4k) blocks.
The filesystem on /dev/mapper/vg_244-lv_root is now 64374784 blocks long.
 
[ root@244  /]#  df -h
filesystem capacity used free used %% mount point
/dev/mapper/vg_244-lv_root
                      242G   28G  202G  13% /
tmpfs                 499M     0  499M   0% /dev/shm
/dev/sda1             485M  162M  298M  36% /boot
/dev/mapper/vg_244-lv_home
                      148G  4.4G  136G   4% /home
[ root@244  /]# 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326813537&siteId=291194637