Fedora – How to reduce LVM for root partition

fedoralvmlvreduceroot-filesystem

I am trying to reduce the space dedicated to root LVM since I don't really need it and I am having a few doubts. Below is the output for lvdisplay:

# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/pc_rperez_lvm/root
  LV Name                root
  VG Name                pc_rperez_lvm
  LV UUID                m7XejM-82cZ-hODn-nT8H-y2BM-3B4s-lq2xgn
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                72.37 GiB
  Current LE             18527
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/pc_rperez_lvm/home
  LV Name                home
  VG Name                pc_rperez_lvm
  LV UUID                Ehl9tF-XV30-uF4Y-T1Bc-WB8r-Pfim-ONQFn3
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                25.00 GiB
  Current LE             6400
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/pc_rperez_lvm/swap
  LV Name                swap
  VG Name                pc_rperez_lvm
  LV UUID                pJuBnV-fhD1-NgOe-xMUc-gck8-CfeM-YkQHAX
  LV Write Access        read/write
  LV Status              available
  # open                 2
  LV Size                8.00 GiB
  Current LE             2048
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

What I want to achieve is shrink root to 25gb and then add the free space to home. I have read a lot of posts but none of them mention how to achieve this on a root partition with the partition mounted. So having this information, it's possible to reduce the space with partition mounted? If so how? If not what would you recommend me? I am using Fedora 23

What I am missing?

EDIT: File system:

As requested this is the file system used:

# cat /etc/fsatb
/dev/mapper/pc_rperez_lvm-root /                       ext4
/dev/mapper/pc_rperez_lvm-home /home                   ext4
/dev/mapper/pc_rperez_lvm-swap swap                    swap

Note: I've read about some Live CD for manage LVM (like GParted) partition but so far I doesn't found any, if you know any add to your reply!!

Articles read: 1, 2, 3, 4 and many others

EDIT: Can't grow up the other LVM

I have run the command for shrink the pc_lvm_root and everything was fine as show below:

$ sudo ssm resize -s 50G /dev/mapper/pc_rperez_lvm-root 
fsck from util-linux 2.28
/dev/mapper/pc_rperez_lvm-root: 425214/4743168 files (0.2% non-contiguous), 9042371/18971648 blocks
resize2fs 1.42.13 (17-May-2015)
Resizing the filesystem on /dev/mapper/pc_rperez_lvm-root to 13107200 (4k) blocks.
The filesystem on /dev/mapper/pc_rperez_lvm-root is now 13107200 (4k) blocks long.

  Size of logical volume pc_rperez_lvm/root changed from 72.37 GiB (18527 extents) to 50.00 GiB (12800 extents).
  Logical volume root successfully resized.

Now I want to add those 50G to the pc_rperez_lvm-home but I can't, see output below:

$ sudo ssm resize -s+50G /dev/mapper/pc_rperez_lvm-home 
SSM Error (2005): There is not enough space in the pool 'pc_rperez_lvm' to grow volume '/dev/mapper/pc_rperez_lvm-home' to size 78538342.4 KB!

EDIT: still can't grow up the LVM

Sadly I can't grow up the home LVM yet, below is what I did following suggestions from the answer:

$ sudo ssm resize /dev/mapper/pc_rperez_lvm-home 
e2fsck 1.42.13 (17-May-2015)
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/pc_rperez_lvm-home: 34602/1638400 files (3.0% non-contiguous), 2213886/6553600 blocks
resize2fs 1.42.13 (17-May-2015)
Please run 'e2fsck -f /dev/mapper/pc_rperez_lvm-home' first.

SSM Error (2012): ERROR running command: "resize2fs /dev/mapper/pc_rperez_lvm-home"

$ df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             3.9G     0  3.9G   0% /dev
tmpfs                3.9G  260K  3.9G   1% /dev/shm
tmpfs                3.9G  1.4M  3.9G   1% /run
tmpfs                3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sdb1             15G  1.6G   13G  11% /run/initramfs/live
/dev/mapper/live-rw  6.3G  4.2G  2.2G  66% /
tmpfs                3.9G   20K  3.9G   1% /tmp
vartmp               3.9G   63M  3.9G   2% /var/tmp
tmpfs                798M   24K  798M   1% /run/user/1000

$ sudo lvdisplay 
  --- Logical volume ---
  LV Path                /dev/pc_rperez_lvm/root
  LV Name                root
  VG Name                pc_rperez_lvm
  LV UUID                m7XejM-82cZ-hODn-nT8H-y2BM-3B4s-lq2xgn
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/pc_rperez_lvm/home
  LV Name                home
  VG Name                pc_rperez_lvm
  LV UUID                Ehl9tF-XV30-uF4Y-T1Bc-WB8r-Pfim-ONQFn3
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                25.00 GiB
  Current LE             6400
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/pc_rperez_lvm/swap
  LV Name                swap
  VG Name                pc_rperez_lvm
  LV UUID                pJuBnV-fhD1-NgOe-xMUc-gck8-CfeM-YkQHAX
  LV Write Access        read/write
  LV Status              available
  # open                 2
  LV Size                8.00 GiB
  Current LE             2048
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

$ sudo e2fsck -f /dev/mapper/pc_rperez_lvm-home
e2fsck 1.42.13 (17-May-2015)
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/pc_rperez_lvm-home: 34602/1638400 files (3.0% non-contiguous), 2213886/6553600 blocks

Ideas at this point?

EDIT: required information

$ sudo vgdisplay 
  --- Volume group ---
  VG Name               pc_rperez_lvm
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               105.38 GiB
  PE Size               4.00 MiB
  Total PE              26976
  Alloc PE / Size       21248 / 83.00 GiB
  Free  PE / Size       5728 / 22.38 GiB
  VG UUID               Gi0r0L-gRJe-Tzwz-QQE0-CLOY-ofb2-Hk5YCe

$ sudo dumpe2fs -h /dev/mapper/pc_rperez_lvm-home 
dumpe2fs 1.42.13 (17-May-2015)
Filesystem volume name:   <none>
Last mounted on:          /home
Filesystem UUID:          eb319b45-03f2-49d3-b849-6e1ff4b19046
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              1638400
Block count:              6553600
Reserved block count:     327680
Free blocks:              4358401
Free inodes:              1607559
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      1022
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Fri Mar 18 13:16:13 2016
Last mount time:          Thu Jul  7 08:06:05 2016
Last write time:          Thu Jul  7 13:21:17 2016
Mount count:              1
Maximum mount count:      -1
Last checked:             Thu Jul  7 07:56:48 2016
Check interval:           0 (<none>)
Lifetime writes:          714 GB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:           256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      a4d5967b-3ad8-4d22-833d-a6126de8ee41
Journal backup:           inode blocks
Journal features:         journal_incompat_revoke
Journal size:             128M
Journal length:           32768
Journal sequence:         0x002cb467
Journal start:            0

enter image description here

Best Answer

The resize2fs does not support shrinking of a mounted file system:

DESCRIPTION The resize2fs program will resize ext2, ext3, or ext4 file systems. It can be used to enlarge or shrink an unmounted file system located on device. If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel and the file system supports on-line resizing.

As you are using fedora distribution, it's much easier to use System Storage Manager to change the size of your file system as it takes care on underlying partition/logical volume size change in one shot. Though you would need to boot the system off the one of LiveCD spins, provided by Fedora community (I recommend XFCE or LXDE to reduce the download size a bit), so in the terminal window just issue:

sudo ssm resize -s -5G /dev/mapper/pc_rperez_lvm-root 

to decrease the root fs by 5 gigabytes, or

sudo ssm resize -s 15G /dev/mapper/pc_rperez_lvm-root 

To set the fs size to 15 gigabytes.

If the ssm is not available in the live CD you would download, then do

sudo yum install system-storage-manager

prior to re-sizing.

to extend a volume to the maximum available space just omit the -s option:

sudo ssm resize /dev/mapper/pc_rperez_lvm-home
Related Question