1

I have bad balance between my root/home LVs. Please note that I'm extremely new to understanding disk management and Linux in general, so I'm probably going to say a few things incorrectly.

My goal is to move some storage space from /home into / (root). The disk is a 16GB flash card that has two partitions – a 250 MB boot volume and a ~14 GB LVM physical volume that contains both logical volumes.

I'd like to take some of the 9 GB of the home partition and add it to root.

Here's some output from my server (some drive details trimmed as there is a large collection of disks):

(nice-rack) stagl [~] > df -Th
Filesystem                      Type      Size  Used Avail Use% Mounted on
/dev/mapper/nice--rack--vg-root ext4      3.8G  3.6G     0 100% /
none                            tmpfs     4.0K     0  4.0K   0% /sys/fs/cgroup
udev                            devtmpfs  7.9G  8.0K  7.9G   1% /dev
tmpfs                           tmpfs     1.6G  6.5M  1.6G   1% /run
none                            tmpfs     5.0M     0  5.0M   0% /run/lock
none                            tmpfs     7.9G   12K  7.9G   1% /run/shm
none                            tmpfs     100M     0  100M   0% /run/user
/dev/sda1                       ext2      228M   71M  146M  33% /boot
/dev/mapper/nice--rack--vg-home ext4      9.6G  212M  8.9G   3% /home
/home/stagl/.Private            ecryptfs  9.6G  212M  8.9G   3% /home/stagl


(nice-rack) stagl [~] > sudo lvmdiskscan
  /dev/ram0                [      64.00 MiB]
  /dev/nice-rack-vg/root   [       3.90 GiB]
  /dev/ram1                [      64.00 MiB]
  /dev/sda1                [     243.00 MiB]
  /dev/nice-rack-vg/swap_1 [     512.00 MiB]
  /dev/ram2                [      64.00 MiB]
  /dev/nice-rack-vg/home   [       9.84 GiB]
  /dev/ram3                [      64.00 MiB]
  /dev/mapper/cryptswap1   [     512.00 MiB]
  /dev/ram4                [      64.00 MiB]
  /dev/ram5                [      64.00 MiB]
  /dev/sda5                [      14.26 GiB] LVM physical volume
  ...
  2 disks
  37 partitions
  0 LVM physical volume whole disks
  1 LVM physical volume


(nice-rack) stagl [~] > sudo pvscan
  PV /dev/sda5   VG nice-rack-vg   lvm2 [14.26 GiB / 16.00 MiB free]
  Total: 1 [14.26 GiB] / in use: 1 [14.26 GiB] / in no VG: 0 [0   ]


(nice-rack) stagl [~] > sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/nice-rack-vg/root
  LV Name                root
  VG Name                nice-rack-vg
  LV UUID                Ghsdz2-PxqH-03GM-3xgB-Ex4k-f4h5-hZ8xiB
  LV Write Access        read/write
  LV Creation host, time ,
  LV Status              available
  # open                 1
  LV Size                3.90 GiB
  Current LE             998
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

  --- Logical volume ---
  LV Path                /dev/nice-rack-vg/swap_1
  LV Name                swap_1
  VG Name                nice-rack-vg
  LV UUID                NxV2xj-0Crj-9DYQ-5h9z-zIdP-FxDH-MjxxJB
  LV Write Access        read/write
  LV Creation host, time ,
  LV Status              available
  # open                 1
  LV Size                512.00 MiB
  Current LE             128
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

  --- Logical volume ---
  LV Path                /dev/nice-rack-vg/home
  LV Name                home
  VG Name                nice-rack-vg
  LV UUID                Mxx3fp-PfxE-NFxi-Z5eC-B8oS-UXCZ-r7xjbq
  LV Write Access        read/write
  LV Creation host, time ,
  LV Status              available
  # open                 1
  LV Size                9.84 GiB
  Current LE             2520
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:2

Notice that I'm completely full in my root partition. This is causing all kinds of issues on the server. I can't even tab-complete at the prompt. :(

2

LVM is designed to allow easy resizing and redistributing space in exactly the situation you describe. However, Lambert's answer is incomplete as it fails to mention several things.

The outline process you need to follow is:

  1. Use resize2fs to reduce the size of the /home filesystem
  2. Use lvresize to reduce the size of the /dev/mapper/nice--rack--vg-home volume
  3. Use lvresize to increase the size of the /dev/nice-rack-vg/root volume
  4. Use resize2fs to increase the size of the root filesystem (/)

In general you can expand filesystems online but cannot shrink them while they are mounted - so you have to unmount everything on /home to shrink it, but can expand / (root) no problem.

The main caveat in your situation is your encrypted home. You'll need to unmount your encrypted home dir, then unmount the underlying /home filesystem, then proceed with the remaining steps. Depending on if ecryptfs uses a loop device (I don't think it does, but I'm not familiar with it) you may also need to unmount the device too - at which point it may be easier booting from a Live CD and doing the work there.

  • ecryptfs isn't related to partitioning, it's a stacked filesystem, so it's irrelevant here (you just need to unmount it before you can unmount /home). – Gilles Jun 22 '15 at 22:05
  • @Gilles: If you say so. But other "stacked filesystems" can sometimes leave file handles and loopback devices lying around after "unmounting" the encrypted filesystem in it, so I figured I'd mention it. – Circus Cat Jun 23 '15 at 3:54
1

Have a look at lvresize. Use man lvresize to read about the options.

The following commands should first reduce the size of the home logical volume by 3GB and then extend the root logical volume by 3GB:

lvresize -r -L -3G /dev/nice-rack-vg/home
lvresize -r -L +3G /dev/nice-rack-vg/root

It is necessary that the home logical volume is unmounted to be able to resize it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.