Environment CentOS 7 running on VMware one SATA hard disk Introduction One day, a CentOS told me its hard disk space is full, but I can’t add extra storage with expansion drives at the moment. After checking out the vm, I knew its storage was managed with LVM , the root /
and /home
were mounted separately in different logical volumes, the error report came from the root /
, but /home
still had enough space, so I can transfer the space of /home
to /
.
Operations Backup home
>> Unmount home
>> Remove home
>> Move the space of home
to /
>> Make a new home
>> Format home
>> Done
The commands which I used:
1 2 3 4 5 6 df -h # Check disk space lsblk # Check device block fdisk -l # Check partitions info lvremove\lvcreate # Add and remove logical volume lvdisplay\vgdisplay\pvdisplay # Display logical volume/volume group/physical volume xfs_growfs # load xfs_growfs
Backup and remove /home
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 [root@test33 ~] Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl-root 230G 230G 20K 100% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 9.2M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 239M 776M 24% /boot /dev/mapper/cl-home 66G 33M 66G 1% /home tmpfs 380M 12K 380M 1% /run/user/42 overlay 230G 230G 20K 100% /var/lib/docker/overlay2/e439b425de8d1312a33938d8bfc4fbeb445759e36ea1bda36de7d9a0ba9562df/merged overlay 230G 230G 20K 100% /var/lib/docker/overlay2/2bbaf357045ec30e9e8f729f6c82784a41353e43209ec9484e40e03a7fe36647/merged overlay 230G 230G 20K 100% /var/lib/docker/overlay2/b78940a1c074d763256e2279599c5ad43066f16121af11b9af502c7adedc2e65/merged overlay 230G 230G 20K 100% /var/lib/docker/overlay2/afe2f63c026b30d1fe5da5d481eefa40acc2c0308b5ebd32705df197477911e5/merged shm 64M 0 64M 0% /var/lib/docker/containers/9dd9255c8c8bb5e3260a45d5c89e575cdaca90e8649f4e14c69e405382dc3c83/mounts/shm shm 64M 0 64M 0% /var/lib/docker/containers/b6d7a17c93493bf150fa417b63ded2ec5db1a62c436a689fb7557f9270e61b23/mounts/shm shm 64M 0 64M 0% /var/lib/docker/containers/f54bb5d50c4a055ef34cf55cb98425fca073a1f46a13042e7567219d6e015e31/mounts/shm shm 64M 0 64M 0% /var/lib/docker/containers/edc22af86393c9b0d8fcb59f60144e2f309a0e45fda676997e13eb2d6680dd5b/mounts/shm tmpfs 380M 0 380M 0% /run/user/0 [root@test33 ~] NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8:0 0 500G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 119G 0 part │ ├─cl-root 253:0 0 230G 0 lvm / │ ├─cl-swap 253:1 0 3.9G 0 lvm [SWAP] │ └─cl-home 253:2 0 65.1G 0 lvm /home ├─sda3 8:3 0 80G 0 part │ └─cl-root 253:0 0 230G 0 lvm / └─sda4 8:4 0 100G 0 part └─cl-root 253:0 0 230G 0 lvm / sr0 11:0 1 1024M 0 rom [root@test33 ~] [root@test33 ~] [root@test33 ~] [root@test33 ~] Do you really want to remove active logical volume cl/home? [y/n]: y Logical volume "home" successfully removed [root@test33 ~] NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8:0 0 500G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 119G 0 part │ ├─cl-root 253:0 0 230G 0 lvm / │ └─cl-swap 253:1 0 3.9G 0 lvm [SWAP] ├─sda3 8:3 0 80G 0 part │ └─cl-root 253:0 0 230G 0 lvm / └─sda4 8:4 0 100G 0 part └─cl-root 253:0 0 230G 0 lvm / sr0 11:0 1 1024M 0 rom
Scenario One: free all the /home
, then don’t remount /home
again 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [root@test33 ~] Size of logical volume cl/root changed from 295.00 GiB (75520 extents) to 295.11 GiB (75549 extents). Logical volume cl/root successfully resized. [root@test33 ~] meta-data=/dev/mapper/cl-root isize=512 agcount=24, agsize=3276800 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=77332480, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=6400, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 77332480 to 77362176 [root@test33 ~] // comment out the mounting of /home [root@test33 ~]
Scenario Two: only free part of the /home
, then remount /home
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 [root@test33 ~] Size of logical volume cl/root changed from <230.00 GiB (58879 extents) to 295.00 GiB (75520 extents). Logical volume cl/root successfully resized. [root@test33 ~] meta-data=/dev/mapper/cl-root isize=512 agcount=19, agsize=3276800 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=60292096, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=6400, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 60292096 to 77332480 [root@test33 ~] root swap [root@test33 ~] Logical volume "home" created. [root@test33 ~] home root swap [root@test33 ~] meta-data=/dev/cl/home isize=512 agcount=4, agsize=7424 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=29696, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=855, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@test33 ~] cl-home cl-root cl-swap control [root@test33 ~] [root@test33 ~] NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8:0 0 500G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 119G 0 part │ ├─cl-root 253:0 0 295G 0 lvm / │ ├─cl-swap 253:1 0 3.9G 0 lvm [SWAP] │ └─cl-home 253:2 0 116M 0 lvm /home ├─sda3 8:3 0 80G 0 part │ └─cl-root 253:0 0 295G 0 lvm / └─sda4 8:4 0 100G 0 part └─cl-root 253:0 0 295G 0 lvm / sr0 11:0 1 1024M 0 rom [root@test33 ~] Disk /dev/sda:536.9 GB, 536870912000 bytes,1048576000 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 Disklabel type : dos Disk identifier: 0x000b5a9c Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 251658239 124779520 8e Linux LVM /dev/sda3 251658240 419430399 83886080 83 Linux /dev/sda4 419430400 629145599 104857600 83 Linux Disk /dev/mapper/cl-root:316.8 GB, 316753838080 bytes,618659840 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/cl-swap:4160 MB, 4160749568 bytes,8126464 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/cl-home:121 MB, 121634816 bytes,237568 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 [root@test33 ~] Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl-root 295G 225G 71G 77% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 18M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 239M 776M 24% /boot tmpfs 380M 12K 380M 1% /run/user/42 overlay 295G 225G 71G 77% /var/lib/docker/overlay2/b78940a1c074d763256e2279599c5ad43066f16121af11b9af502c7adedc2e65/merged shm 64M 0 64M 0% /var/lib/docker/containers/9dd9255c8c8bb5e3260a45d5c89e575cdaca90e8649f4e14c69e405382dc3c83/mounts/shm tmpfs 380M 0 380M 0% /run/user/0 overlay 295G 225G 71G 77% /var/lib/docker/overlay2/57f869e119cb2f7fdd412f015eefee639b997e1638c456129ed4e21c47cf397c/merged shm 64M 0 64M 0% /var/lib/docker/containers/09a9262208972446b9f3bb2e97838ebf22c2f1e66090618593e8cafd8b86a000/mounts/shm overlay 295G 225G 71G 77% /var/lib/docker/overlay2/ae47756e9851081ad120a06dbfea8cba4275d9297c44863b4f9410bd000de412/merged overlay 295G 225G 71G 77% /var/lib/docker/overlay2/2420c90bd4403953c535b70aa3d06891c58092398681c9fc5be202b5ad67bb2e/merged overlay 295G 225G 71G 77% /var/lib/docker/overlay2/c612edf73c386189365a6583f41090802f6b2a4cd5e88cb3ca22e3a526d7d612/merged shm 64M 0 64M 0% /var/lib/docker/containers/c06950567393ef037c649b9ce2f0e19052e0e3c418acdc7eeed9b5330c166b1c/mounts/shm shm 64M 0 64M 0% /var/lib/docker/containers/ccf645e71a455df8802e8b83884b96bc81857852031593e7fd5ddef1c89d903e/mounts/shm shm 64M 0 64M 0% /var/lib/docker/containers/2ffab189252844eb7f444b75191e6988fe622adc88e0f87a8c16b7b61f254a99/mounts/shm overlay 295G 225G 71G 77% /var/lib/docker/overlay2/06d76af657c7c0f7a2b11759af09e62b31f5d4ba62b923692a61677f6ad87b21/merged shm 64M 0 64M 0% /var/lib/docker/containers/bf10d736de9b8c209c11c9f25a3d30bb415701c9c2b750aa95a4e31994524405/mounts/shm overlay 295G 225G 71G 77% /var/lib/docker/overlay2/a01fa0fba6e4b5cfa2972da7878af59852aa75a10808fa20f06e285a57ca92a1/merged overlay 295G 225G 71G 77% /var/lib/docker/overlay2/35a81c327fd00e51bceed151fb35967c35d24338ec5dd3ed9086fc384c7f7803/merged shm 64M 0 64M 0% /var/lib/docker/containers/89f265fbf738ce64e4ab923d3e8d27cdad599106c6dcc1de55802d2c72ff70c9/mounts/shm shm 64M 0 64M 0% /var/lib/docker/containers/16026f7e55b6b5338478caff0613564f56b56e0a41495377d9b298091e1a57f3/mounts/shm /dev/mapper/cl-home 113M 6.1M 107M 6% /home
Recovery /home
1 2 [root@test33 ~] [root@test33 ~]
Reference https://www.cnblogs.com/-abm/p/11349240.html