Default LVM partitioning in Linux may not be optimal for some tasks. For example, root partition can be too small and filled up after some time while home partition is large and almost unused. In this case one obviously would want to transfer some amount of space from /home
to /
partitions.
Consider the following example:
1 2 3 4 5 6 7 8 9 10 11 |
$ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 50G 21G 30G 41% / devtmpfs 5.8G 0 5.8G 0% /dev tmpfs 5.8G 0 5.8G 0% /dev/shm tmpfs 5.8G 8.5M 5.8G 1% /run tmpfs 5.8G 0 5.8G 0% /sys/fs/cgroup /dev/mapper/centos-home 224G 13G 212G 6% /home /dev/sda1 497M 145M 352M 30% /boot tmpfs 1.2G 0 1.2G 0% /run/user/1000 |
Running fdisk -l
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
$ sudo fdisk -l [sudo] password for admin: Disk /dev/sda: 300.6 GB, 300647710720 bytes, 587202560 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0006c283 Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 587202559 293088256 8e Linux LVM Disk /dev/mapper/centos-swap: 6316 MB, 6316621824 bytes, 12337152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/centos-home: 240.1 GB, 240115515392 bytes, 468975616 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes |
And:
1 2 3 4 5 6 7 8 9 10 11 |
$ sudo lsblk -io NAME,TYPE,SIZE,MOUNTPOINT,FSTYPE,MODEL NAME TYPE SIZE MOUNTPOINT FSTYPE MODEL fd0 disk 4K sda disk 280G Virtual disk |-sda1 part 500M /boot xfs `-sda2 part 279.5G LVM2_member |-centos-swap lvm 5.9G [SWAP] swap |-centos-root lvm 50G / xfs `-centos-home lvm 223.6G /home xfs sr0 rom 1024M VMware IDE CDR10 |
How to move the disk space used for /dev/mapper/centos-home
to /dev/mapper/centos-root
?
Here is how.
First of all unmount the /home
partition with:
1 |
# umount -fl /dev/mapper/centos-home |
Reduce the logical volume:
1 |
# lvreduce -L 200G /dev/mapper/centos-home |
Mount back your home partition as you’re done with it:
1 |
# mount /dev/mapper/centos-home /home |
Then extend your root volume:
1 |
# lvextend -t -r -l+100%FREE /dev/mapper/centos-root |
-t
is a test mode. remove -t
if results are ok.