Score:0

Make the OS use all the space from 2 logical volumes on the same VG

cn flag

When I installed Ubuntu 20.04 LTE headless, I used a NVME and for the OS I created a LV with only 20G, and the rest of the space was assigned to another LV that is mounted as /home... (because I am new to Linux). Now I'm running out of space on root (LV mounted on /) and I'm looking for a way to either remove the second LV and add the space to the root or any other solution that would avoid OS erase and reinstall...

Tried to lvresize but I can't unmount /home even logged in as root.

root@server:~# umount /home
umount: /home: target is busy.
root@server:~# lvresize -r -L -100G /dev/mapper/ubuntu--vg-storage--lv
  /dev/sdc: open failed: No medium found
  /dev/sdc: open failed: No medium found
Do you want to unmount "/home" ? [Y|n] y
umount: /home: target is busy.
fsadm: Cannot proceed with mounted filesystem "/home".
  /sbin/fsadm failed: 1
  Filesystem resize failed.

Here are the outputs for lsblk and df -h:

├─nvme0n1p1                259:1    0   512M  0 part /boot/efi
├─nvme0n1p2                259:2    0     1G  0 part /boot
└─nvme0n1p3                259:3    0 475.4G  0 part
  ├─ubuntu--vg-ubuntu--lv  253:0    0    20G  0 lvm  /
  └─ubuntu--vg-storage--lv 253:1    0 455.4G  0 lvm  /home
udev                                3.8G     0  3.8G   0% /dev
tmpfs                               784M  3.5M  780M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv    20G   18G  769M  96% /
tmpfs                               3.9G     0  3.9G   0% /dev/shm
tmpfs                               5.0M  4.0K  5.0M   1% /run/lock
tmpfs                               3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/nvme0n1p2                      976M  204M  706M  23% /boot
/dev/mapper/ubuntu--vg-storage--lv  448G  8.4G  417G   2% /home
/dev/nvme0n1p1                      511M  7.9M  504M   2% /boot/efi

Thanks for your advice.

Score:0
cn flag

Since the file system is on both logical volumes, you need to use a LIVE CD. For Ubuntu 20.04 desktop or server, you need to create a mountable USB OS with RUFUS and the DESKTOP VERSION OF UBUNTU (as it has the option to TRY UBUNTU; ubuntu-20.04.2.0-desktop-amd64.iso). Then I found an answer posted somewhere (sorry, I can't find the link) about what to do next:

BEFORE YOU CHANGE ANYTHING MAKE SURE YOU HAVE A CURRENT BACKUP. This all worked for me, but it might not work for you. If it blows up for some reason, you don’t want to lose anything that you can’t recover. Continuing on… It is not possible (to my knowledge) to shrink a filesystem while it is mounted, so we need to do the actual resizing from a Live CD. All the following instructions assume you have booted off of the 20.04 Desktop Install CD.

After the Live CD boots up to the desktop, open up the Terminal. The LVM tool are not built-in to the Live CD, so first we must install them: sudo apt-get install lvm2

Find the name of the Volume Group (henceforth “ubuntu--vg”) that contains the root Logical Volume: sudo lvs

(If it’s not showing up, try running sudo lvmdiskscan and sudo pvscan then try again.) If you run ls /dev/mapper/ you may see that the Logical Volumes is not showing up. If it’s not there, you need to run the following command to make the kernel aware of the logical volumes: sudo vgchange --available y ubuntu--vg

Since we haven’t mounted the root filesystem, it should be safe to resize. Proceed to perform the actual resizing of the Logical Volume. Note that this command (--size -50G) shrinks the volume by 50GB — read the lvreduce(8) man page to learn how to specify a different size. sudo lvreduce --resizefs --size -50G /dev/ubuntu--vg/storage--lv

This command will first shrink the filesystem, then shrink the Logical Volume that contains it, which is the only safe way to do it.

Now if you want to extend with un-allocated (free space) you use:

lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu--lv to extend the logical volume and resize2fs /dev/ubuntu-vg/ubuntu--lv to extend the file system.

You can now restart the system and boot into your now-resized root filesystem.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.