linux disk transfer space method

  • 2020-06-19 12:30:29
  • OfStack

How do you transfer space from one disk to another disk, because this happens a lot, in the /home directory the disk is large but /root is small, how do you transfer space from /home to /root? Here's how to fight.

fedora24 under actual combat

Use the following command to view disk usage


df -lh

 The file system           capacity   Has been used   available   Has been used %  The mount point 
devtmpfs         3.9G   0 3.9G  0% /dev
tmpfs          3.9G   0 3.9G  0% /dev/shm
tmpfs          3.9G 2.9M 3.9G  1% /run
tmpfs          3.9G   0 3.9G  0% /sys/fs/cgroup
/dev/mapper/fedora-root  60G  46G  12G  81% /
tmpfs          3.9G 400K 3.9G  1% /tmp
/dev/sda1        477M 141M 307M  32% /boot
tmpfs          787M   0 787M  0% /run/user/0
/dev/mapper/fedora-home 141G  60M 134G  1% /home

The mount directory corresponding to /dev/mapper/ fedora-ES18en is /home

The mount directory corresponding to /dev/mapper/ fedora-ES26en is /

As can be seen from the above list, ES29en-ES30en is very large, but ES31en-ES32en is very small. We practice transferring 1G.

Unmount the /home directory


umount -v /home 

Check the disk to be transferred


e2fsck -ff /dev/mapper/fedora-home
# This command operates on the result of 5 All steps must be passed 

The results are shown as follows


e2fsck 1.42.13 (17-May-2015)
 The first 1 step :  check inode, block , The size and 
 The first 2 step :  Check the directory structure 
 The first 3 step :  Check directory connectivity 
Pass 4: Checking reference counts
 The first 5 step :  Check the cluster profile information 
/dev/mapper/fedora-home: 130190/10838016 files (0.1% non-contiguous), 8077341/43338752 blocks

Change the disk size of /dev/mapper/ ES49en-ES50en

Calculation method: 141G - transfer 1g = 140G


resize2fs /dev/mapper/fedora-home 140G

Cut disk space


lvreduce -L -1G /dev/mapper/fedora-home

Remount /home


mount -v /home

Move to/root


lvextend -L+1G /dev/mapper/fedora-root

Effect the /root space


resize2fs /dev/mapper/fedora-root

At this point, execute the ES74en-ES75en command


 The file system           capacity   Has been used   available   Has been used %  The mount point 
devtmpfs         3.9G   0 3.9G  0% /dev
tmpfs          3.9G   0 3.9G  0% /dev/shm
tmpfs          3.9G 2.9M 3.9G  1% /run
tmpfs          3.9G   0 3.9G  0% /sys/fs/cgroup
/dev/mapper/fedora-root  60G  46G  12G  81% /
tmpfs          3.9G 400K 3.9G  1% /tmp
/dev/sda1        477M 141M 307M  32% /boot
tmpfs          787M   0 787M  0% /run/user/0
/dev/mapper/fedora-home 141G  60M 134G  1% /home
0

Related articles: