8

I want to resize an LVM partition (specifically, I want to increase the root / mount and decrease the /home), because I am running low on disk space on one virtual partition.  Now people say LVM has resizeable partitions… they claim, at least.  I did not see it so far…

How can I do so?

Blivet GUI

I tried to use blivet GUI from a Fedora Workstation installation disk. So I:

  1. boot that media
  2. start blivet-gui (after installing it, if needed)
  3. go to the LVM section and find the virtual partitions there.

However, when I right-click and go to "Edit", the menu entries are all greyed-out.

blivet GUI screenshots with an edit menu, where all entries are greyed out

Fedora 31

Other tries

Alternatively, is there any other GUI that can edit the size of the inner LVM partitions? I've tried gnome-disks, GParted and blivet.  GParted does only recognize the disks and GNOME disks does not help either.

I want to avoid using the command line for this.


Cross-posted at Ask Fedora.

rugk
  • 3,086

5 Answers5

6

KDE partitionmanager 3.0 is doing this just fine now.

We used to have system-config-lvm, a python2 wrapper around lvm commands, now deprecated after python2 & gtk2.0 support for glade are dropped.

Apparently gnome palimpsest also had this capability (plus some S.M.A.R.T. utilities and RAID) but gnome disk utility, that replaces it as a poor cousin does not.

Flint
  • 161
  • I have been unable to get KDE partitionmanager to shrink an LVM LUKS partiion, but here are the steps I used to install this tool on an Ubuntu 22.04 Live USB for anyone else who wants to try: sudo apt update sudo add-apt-repository universe sudo apt --fix-broken install sudo apt update sudo apt install partitionmanager – Gabriel Staples Dec 16 '22 at 23:08
5

See also my closely-related answer here, where I expand a LUKS-encrypted partition (which is easier) instead of shrinking it: How to clone your hard drive (SSD or HDD) and expand your LUKS-encrypted partition to fill the new full disk space.

How to shrink an encrypted LUKS partition

...by installing blivet-gui on an Ubuntu live USB and then using blivet-gui, Gnome Disks, and GParted (all 3 are required together).

Tested on:

  1. An Ubuntu 22.04 live USB which was used to run these 3 GUIs to unlock a LUKS-encrypted outer partition, shrink and edit an Ubuntu 20.04 LVM volume within it, and then shrink the outer LUKS partition.
  2. An Ubuntu 22.04 system where I shrunk a LUKS-encrypted partition on an external SSD drive.

1. Install blivet-gui

I was just now able to follow @rugk's instructions, except while running the Blivet GUI from an Ubuntu 22.04 live USB (created with Balena Etcher) instead of using a Fedora live USB.

To install blivet-gui into my Ubuntu 22.04 live USB, I tried to follow blivet-gui's own installation instructions here, which are these. Note: the instructions here worked on an actual Ubuntu system, but failed on my Ubuntu live USB installation disk. For the live USB, my customized instructions I posted farther below worked.

# Ubuntu 22.04
echo 'deb http://download.opensuse.org/repositories/home:/vtrefny/xUbuntu_22.04/ /' | sudo tee /etc/apt/sources.list.d/home:vtrefny.list
curl -fsSL https://download.opensuse.org/repositories/home:vtrefny/xUbuntu_22.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_vtrefny.gpg > /dev/null
sudo apt update
sudo apt install blivet-gui

Ubuntu 20.04

echo 'deb http://download.opensuse.org/repositories/home:/vtrefny/xUbuntu_20.04/ /' | sudo tee /etc/apt/sources.list.d/home:vtrefny.list curl -fsSL https://download.opensuse.org/repositories/home:vtrefny/xUbuntu_20.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_vtrefny.gpg > /dev/null sudo apt update sudo apt install blivet-gui

etc.

Although the 2nd set of instructions above work perfectly on my main Ubuntu 20.04 machine (I tested this too), they do not work equally well on the more-limited live USB environment.

So, what worked for me on the Ubuntu 22.04 live USB ended up looking more like this:

sudo apt update
sudo add-apt-repository universe
sudo apt --fix-broken install
sudo apt update

optional, if you want to try the other answer here recommending this tool too

sudo apt install partitionmanager

sudo apt install curl

Ubuntu 22.04

echo 'deb http://download.opensuse.org/repositories/home:/vtrefny/xUbuntu_22.04/ /' | sudo tee /etc/apt/sources.list.d/home:vtrefny.list curl -fsSL https://download.opensuse.org/repositories/home:vtrefny/xUbuntu_22.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_vtrefny.gpg > /dev/null sudo apt update sudo apt install blivet-gui

I just tried it again, and that worked. If that isn't sufficient for your case, however, throw in a couple more scattered sudo apt --fix-broken install and sudo apt update commands, then try sudo apt install blivet-gui again too. You can also try following the comment by @mixalbl4 below this answer.

2. Unlock and shrink the LUKS partition

Unlock a LUKS-encrypted outer partition, shrink and edit the LVM volume(s) within it, and then shrink the outer LUKS partition using a combination of 3 GUIs: Gnome "Disks", "blivet-gui", and "GParted".

Usages:

  1. You must use Gnome "Disks" to unlock the outer LUKS-encrypted partition. Although both blivet-gui and GParted also have features to unlock LUKS-encrypted partitions, they won't work properly to allow blivet-gui to then edit and shrink the inner LVM volumes. Only unlocking via Gnome "Disks" will work for that. So, follow my instructions below.
  2. You must use blivet-gui to shrink the inner LVM volume(s) and edit or delete any other inner volumes inside the outer LUKS-encrypted partition. blivet-gui is the only one of these 3 GUIs that can edit the inner volumes once the outer LUKS-encrypted partition is unlocked via "Disks".
  3. To shrink the outer LUKS-encrypted partition afterwards, you must use GParted. It's the only one of the 3 that can do that.
    1. Also, only GParted can fully close and re-lock the outer LUKS-encrypted partition. For me to write this tutorial and test my instructions repeatedly, I had to use only GParted to close and re-lock the outer LUKS-encrypted partition (via right-click menus on it). Although I unlocked it with Disks, only GParted could properly re-lock and re-close the outer LUKS-encrypted partition. Weird, but that's what I saw, repeatedly.

Instructions:

  1. Use Disks to unlock the outer LUKS-encrypted partition: press the Windows key and type in "disks" to open up the gnome-disks GUI tool. Click on your drive of interest containing the LUKS-encrypted partition, then find the locked LUKS-encrypted partition. This is what I'm calling the "outer partition", since it contains protected inner LVM volumes. Click the unlock icon (it looks like an unlocked padlock) and enter your encryption password to unlock the partition. It will take several seconds to complete unlocking. You'll see the unlocked inner "LVM2 PV" volumes now show up in the Disks GUI underneath that outer "LUKS" partition. Reminder: only the Disks tool can properly unlock the partition to work with the next step. Don't unlock it with blivet-gui nor GParted, or else blivet-gui will throw an error in the next step.

  2. Use blivet-gui to shrink and edit the inner LVM volume(s) within the outer LUKS-encrypted partition: press the Windows key and type in "blivet" to open the blivet-gui tool. Note: the blivet-gui should NOT already be open! You must do the unlock step above in "Disks" before opening blivet-gui. Under the bold "LVM" label, I have a 951.94 GiB partition which is my protected LVM volume (inside the outer LUKS-encrypted partition) which I want to shrink. Under the "Logical View" tab, right-click the volume you want then go to --> Edit --> Resize --> drag the slider to the left to resize to your desired size. Here's what that looks like for an LVM volume of 80 GiB being resized to 57.3 GiB:

    enter image description here

    Note: in my original case, I shrunk a 951.94 GiB LVM volume down to 80 GiB.

    Click "Resize" when done.

    Do any other editing of inner LVM volumes via blivet-gui at this time. You may add, delete, resize, etc, LVM volumes as you see fit.

    Disks is still open at this time. You can leave blivet-gui open too.

  3. Use GParted to shrink the outer LUKS-encrypted partition: press the Windows key and type in "gparted" to open up the GParted partition editor GUI tool. It looks like this. You can see that my outer 951.94 GiB LUKS-encrypted partition is unlocked (previously by the Disks tool) because its label shows "lvm2 pv", and because it shows the usage (the yellow portion near the left of the graphical view of it shows "space used"--which is actually just the 80 GiB inner LVM volume in this case--even if not all of that space is truly "used", and the white portion to the right is empty space freed from where I just shrunk the inner LVM volume above).

    enter image description here

    Next, in GParted, right-click it and go to --> Resize/Move --> drag the right side of the bar all the way to the left, as shown here. This shrinks the outer LUKS-encrypted partition down to the size of the inner LVM volume. My inner LVM volume is actually exactly 80 x 1024 = 81920 MiB, but for whatever reason, I could only shrink the LUKS container down to 81940 MiB:

    enter image description here

    Click "Resize" when done, then click the green check-mark at the top of GParted to apply the change on-disk. A few minutes later, and "boom, done!" Here's the final, most-beautiful result! You can see that the LUKS-encrypted outer partition containing the currently-unlocked LVM2 PV inner volume is now 80.02 GiB, with 871.92 GiB to the right of that totally free!:

    enter image description here

    To close and re-lock the partition, inside GParted, right-click the encrypted partition and go to --> Deactivate, then right-click it again and go to --> Close Encryption. It now looks like this, showing just the label "[Encrypted]", rather than also indicating that it contains an "lvm2 pv system" volume inside of it:

    enter image description here

    You can now close GParted, blivet-gui, and Disks. As you can see, all 3 of those GUIs were required to unlock an outer LUKS-encrypted partition, shrink and edit its inner LVM volumes, and then shrink the outer LUKS-encrypted partition, in that order.

    That new space can now be used for installing a new LUKS-encrypted Linux operating system, for instance, while keeping the old LUKS-encrypted Linux operating still intact, for a dual-boot system with two Linux operating systems

Update 1:

I don't know how to make the dual-boot system work when both systems are LUKS-encrypted; after my new install, the old Ubuntu 20.04 OS I shrunk down to 80 GiB above is not in the grub menu, and I don't know why, nor how to fix it yet. Here are my follow-up questions on that:

  1. Unix & Linux: How to get a dual boot (2 Linux OSs) system working when both are LUKS-encrypted
  2. Ask Ubuntu: How to get old LUKS-encrypted Ubuntu version back into Grub menu after installing new Ubuntu version in new LUKS partition

I think maybe next time I should try shrinking only the LVM volume within the outer LUKS partition, but not shrink the outer LUKS partition itself. Then, instead of creating a new LUKS partition, try installing the new version of Linux Ubuntu next to the old version inside a new LVM volume within the same LUKS partition as the original version of Ubuntu. Maybe that would work???

Update 2:

I got it! I got the Grub boot menu updated to include my old LUKS-encrypted operating system, as well as the new one. See my answers at either of the two links just above, here and here.

Update 3:

Next time I install the new OS, try using the same /boot partition as the old OS, instead of making a new, separate /boot partition. I think using a single, shared /boot partition will avoid having to do the "dirty hack" I explain near the end of my answer here (search that answer for "dirty hack")!

See also

  1. [my answer] Use blivet-gui, instead of gparted or Gnome Disks, to see what is inside of LUKS-encrypted LVM volumes/partitions
  • 1
    Ubuntu 22.04.1 cmd install blivet-gui finishes with E: Sub-process /usr/bin/dpkg returned an error code (1) every time. Solution: https://askubuntu.com/a/380701 – mixalbl4 Feb 03 '23 at 13:48
  • 1
    Nice guide, thanks! I tried unlocking the container from blivet-gui and it didn't cause any issues. I have added an answer with code to install kvpm too. – user334639 Feb 22 '24 at 20:49
3

Actually, with a newer version in Fedora 32 it worked. For some reason.

So here is how to do it:

  1. Download an up-to-date live image, e.g. of Fedora 32.
  2. Create a bootable drive (USB or so)
  3. Boot into it.
  4. Use GNOME Software to install Blivet GUI
  5. If the main drives are encrypted use GNOME Disks to unlock it. (Note to unlock all drives.)
  6. Open Blivet GUI.
  7. You should see a section "LVM".
  8. There just right click on the partition you want to change/resize.
  9. At the end, you need to click the apply button at the top to apply all steps at once. Note this can take a while, and the loading indicator is quite bad. (I've created an issue for that.)
rugk
  • 3,086
  • decreasing a logical volume ? It is possible but well VERY dependent on the type of the file system - ie if the volume contains a JFS system but mount hasn't been done with resize as an option, the filesystem isn't expanded to use the space, but JFS doesn't supports – Stefan Skoglund May 02 '20 at 16:33
  • decreasing it's size. – Stefan Skoglund May 02 '20 at 16:54
  • It worked with a usual ext4 system volume. (Decreased size of one partition inside of the LVM and increased the size of another one.) – rugk May 04 '20 at 12:56
  • When I right-click on my LVM partition it says, "This device cannot be resized: Unformatted devices are not resizable." – Gabriel Staples Dec 16 '22 at 23:33
  • 1
    Fixed! I had unlocked the encrypted LVM LUKS partition with the GParted GUI tool. I needed to use the Disks GUI tool to unlock it, like you said, instead! Then, opening up the Blivet GUI afterwards worked as you stated. – Gabriel Staples Dec 16 '22 at 23:39
  • I added some of my notes, including installing blivet-gui on Ubuntu, in my new answer here. – Gabriel Staples Dec 17 '22 at 00:31
  • Upvoted. Thank you for pointing out this tool and these instructions! Although blivet-gui was able to shrink and edit my inner LVM volumes within a LUKS-encrypted partition, I could not get it to shrink the outer LUKS-encrypted partition itself. To do that, I then had to use GParted last. See my answer for full details and screenshots. Is it possible to make blivet-gui shrink the outer LUKS-encrypted partition too, or can it only shrink the inner LVM volumes within it? – Gabriel Staples Dec 17 '22 at 04:50
1

The resize menu option being unavailable was a bug and has been fixed in blivet-gui version 2.1.15.

You now also get more informative messages if an action is unavailable, eg. not being able to resize a mounted volume.

adatum
  • 1,141
1

The only tool I know that manages logical volumes, physical volumes and disk partitions is KDE Partition Manager.

Here is a summary of my brief experience with the main tools, and how to install them in an Ubuntu 22.04 pendrive live session.

partitionmanager 21.12.3

  • Can lock and unlock luks containers
  • Can deactivate lvm volume groups
  • Can expand and shrink physical partitions
  • Can expand and shrink lvm logical volumes
  • Can expand and shrink encrypted lvm physical volumes
  • Can mount and unmount lvm logical volumes (but not as easy as gnome-disk-utility)

Observed issues:

  • Failed to recognize that there was data in my current boot partition after I unmounted it, and offered to shrink it down to 8MB (?!). I told it to go ahead to see where this would go, and fortunately it threw an error message instead of destroying my boot partition.
  • Failed to create a physical volume on some 7GB free space at the end of a disk, insisting that it was mounted as /run (?!) when it was not.

blivet-gui 2.4.2

  • Can expand and shrink lvm logical volumes
  • Cannot lock and unlock luks containers
  • Cannot deactivate lvm volume groups
  • Cannot resize lvm physical volumes

Observed failures:

  • Threw python syntax errors during some perfectly legal operations

gnome-disk-utility 42.0

  • Can lock and unlock luks containers
  • Lists lvm volume groups
  • Can mount and unmount lvm logical volumes
  • Cannot create or resize lvm logical volumes

No failures

gparted 2.3.1

  • Can lock and unlock luks containers
  • Can expand and shrink encrypted lvm physical volumes
  • Can deactivate lvm volume groups
  • Cannot list lvm logical volumes and lvm volume groups

No failures

kvpm 0.9.10

  • Can resize lvm logical volumes
  • Can resize physical partitions
  • Offers to expand a luks container but does not expand the lvm physical volume inside it (?!)
  • Cannot lock and unlock luks containers
  • Cannot shrink lvm physical volumes
  • Cannot deactivate lvm volume groups
  • Cannot enlarge lvm physical volumes if the volume group is active

No failures besides the above

Installing them on an Ubuntu 22.04 pendrive session

As of February 2024:

sudo add-apt-repository universe
sudo apt update

sudo apt install partitionmanager

cd /tmp

wget http://download.opensuse.org/repositories/home:/vtrefny/xUbuntu_22.04/all/python3-pid_3.0.3-1_all.deb wget http://download.opensuse.org/repositories/home:/vtrefny/xUbuntu_22.04/all/python3-blivet_3.7.1-1_all.deb wget http://download.opensuse.org/repositories/home:/vtrefny/xUbuntu_22.04/all/blivet-gui_2.4.2-1_all.deb sudo apt install ./python3-pid_3.0.3-1_all.deb ./python3-blivet_3.7.1-1_all.deb ./blivet-gui_2.4.2-1_all.deb

wget http://archive.ubuntu.com/ubuntu/pool/main/l/lvm2/liblvm2app2.2_2.02.176-4.1ubuntu3.18.04.3_amd64.deb wget http://archive.ubuntu.com/ubuntu/pool/universe/k/kvpm/kvpm_0.9.10-1.1_amd64.deb sudo apt install ./liblvm2app2.2_2.02.176-4.1ubuntu3.18.04.3_amd64.deb ./kvpm_0.9.10-1.1_amd64.deb sudo -i kvpm