How to resize Pure OS partitions to gain space for dual boot (Ubuntu)

I have a default installation of Pure OS with LUKS encryption on a 500 GB SSD.

How can and should I change my partitions to install Ubuntu as a second OS (dual boot)?

My partition scheme:

/dev/sda     ext4        rescue    2 GB
/dev/sda1    ext4                  1 GB     boot
/dev/sda3    extended            460 GB
   /dev/sda5 (Encrypted)         460 GB
unallocated                        1 GB

My problem is that the Ubuntu installer only offers to

  1. Erase disk and install Ubuntu
  2. Something else (“you can create or resize partitions yourself”)

but if I choose “2” gparted does not offer to resize /dev/sda5 (it is encrypted!) and the disk
has no more space to add another partition.

To resize (shrink) the encrypted /dev/sda5 partition I have tried these steps:

  1. Open a terminal in the live boot system

  2. Open the encrypted partition using your LUKS password:

    sudo cryptsetup luksOpen /dev/sda5 cryptdisk

  3. Then you’ll be prompted to enter the decryption key

  4. After successful decryption you have root access to your now decrypted partition

  5. Run gparted as root from the terminal and use the GUI to resize the partition

Step 5 does fail because “resize” of /dev/sda5 did not offer smaller partition sized.

Any ideas?

PS: I guess shrinking from within PureOS is not possible because the partition must be unmounted.

Update 1:

I have found step-by-step instructions how to shrink your LUKS/LVM partition:

It is so complicated and risky that I do understand now why Ubuntu recommends to backup and re-install :slight_smile:

If you still try to do so, I have some helpful commands for the first part (still incomplete):

# Load decryption kernel module
sudo modprobe dm-crypt

# Recognize and activate your LVM
sudo vgscan --mknodes
sudo vgchange -ay
# 2 logical volume(s) in volume group "crypt" now active

sudo lvscan
# Shows the two active devices within LVM (swap + root)
# /dev/crypt/swap
# /dev/crypt/root   # this device is what we need!

# You could mount the encrypted partition now but DON'T DO this since it prevents resizing!
# mkdir /media/sda5
# sudo mount /dev/crypt/root /media/sda5

# Check the file system for errors before resizing
sudo e2fsck -f /dev/crypt/root

# Resize: Shrink to 70 GB (or whatever you want by changing the number)
sudo resize2fs -p /dev/crypt/root 70G

# Check that the file system is still OK
sudo e2fsck -f /dev/crypt/root

The next parts are still missing

  • Reduce the size of your root (LVM) Logical Volume.
  • Resize your (LVM) Physical Volume.
1 Like

I’m trying the same thing. The default hard drive size is tiny, I’m having an annoying time trying to get an OS that allows some of the things I need to work on here

I have read about a Linux tool (with a GUI?) that can change LVM sizes (can’t remember ATM but perhaps you can find it easily)

I’ll look, but I lost all the data on my disk by doing this, so do not ever do this -

@tovadiratum Have you been able to get this working?

I’ve been trying the same thing. I’ve been working with a skilled Linux-guru friend and we were able to get a little farther than you had, using this article for reference but I’m missing what I hope is the final step. The current state is that I can select either OS from a boot menu and PureOS still works as it did before, but Ubuntu will only launch in recovery mode. If I try to launch a full version of Ubuntu, I get the login screen but my keyboard and trackpad are disabled. I’ve been scouring the internet to try to figure out what we’re missing.

In response to your question, this article has clear instructions about resizing your logical volume and LVM physical volume but it doesn’t deal with LUKS encryption. The second link has some really useful pointers for that, but obviously you can’t use it as a walkthrough unless you want to wipe your machine and start from scratch. One gotcha while resizing: my filesystem sizes were shown in GiB so remember to convert to GB and subtract from the total size in order to get the size you want. I made a mistake in my first attempt but was able to balance things out by reducing and then extending the volume to minimize wasted disk space.

After getting my encrypted partitions set up, there was an error when I ran the Ubuntu installer and it couldn’t create its bootloader, presumably because “grub can’t access the secondary bootloaders if they are sitting in an encrypted LUKS container” (from the LUKS encryption article above which I found after the fact).

I noticed in my /boot/grub/grub.cfg that the menu entry for the generic kernel was missing an initrd path, like this:

…so I generated one. First I made a backup copy of my boot/grub/grub.cfg so I could restore to my current working state if anything went wrong:

mkdir boot/old
cp boot/grub/grub.cfg boot/old/

Then I generated the initrd and updated grub like so:

update-initramfs -v -c -k vmlinuz-4.18.0-15-generic

That sort of worked, in that I can now see my initrd path in grub.cfg, but after rebooting and selecting Ubuntu 4.18 generic it drops me into a BusyBox prompt and I’m not sure what to do next.

Ok, I got it! We had all the info we needed from the three articles linked in my previous comment, we just did a few things out of order in our first attempt.

We decided to move forward with the idea that sharing one partition for dual boot won’t work with LUKS because Grub needs access to encrypted parts of the disk in order to build the secondary OS during boot.

Steps are:

  1. Boot into live media
  2. Decrypt LUKS in Terminal
  3. Resize the Boot partition (sda2*) to 500MB (minimum size of ~123,000 4kb blocks)
  4. Initialize the new boot partition ext4
  5. Install Ubuntu with the “something else” option on sda5*

*sda2 and sda5 assumes you and I have the same starting point, which is a Purism laptop running the original installation of PureOS. Your system may be different.

This got dual boot working, however we still needed to do some housekeeping. The wifi antenna was not recognized in Ubuntu so we had to copy the resolv.conf from PureOS into the new boot partition. We also removed the lines we had added to the /etc/grub.d/40_custom because there were two entries for PureOS. After a reboot, I was able to connect to the internet. I did an apt update from the Terminal in Ubuntu and now I can boot into PureOS or Ubuntu from the main menu. Both partitions are fully LUKS encrypted so they share the same original password, but I am using different passwords to log in as a user on either system.

So it turns out it was not a great idea to do step 3 above, “Resize the Boot partition to 500MB”

Although PureOS continued to operate well with the minimum boot partition size, the 500MB boot partition was not big enough for Ubuntu, which keeps several versions of the kernel around by default. In order to update the kernel, I had to remove older kernel versions. Though not a huge problem, it was also not ideal. The warning said I only had 5MB to spare.


So I decided to go back in and do the following:

  1. reduce the size of the logical volume containing my secondary OS (ubuntu)
  2. create a new partition at the end of the disk, and
  3. copy ubuntu’s boot partition into that new partition
  4. inform the boot loader about the move
  5. update grub
  6. resize the boot partition so PureOS could use that space comfortably

I decided to document the commands I used, in case it is helpful to anyone reading this thread:

# Insert the live media and boot using the option "Try Ubuntu"
# mount the file system containing ubuntu. I named it /ubuntu
# yours may be /root if you used one of the tutorials linked in an earlier message in this thread
mount /dev/crypt/ubuntu /mnt

# check things out
df -h
e2fsck -f /dev/crypt/ubuntu

# I have a 500GB encrypted disk. Ubuntu is in a partition with 353GB
# I decided to reduce the size of the logical volume containing ubuntu by 16GB (which I realized later was way more than I needed.) based on the total size LESS the size of my end partition.
# NOTE: use two dashes in the command below. Markdown converts it to a comment
lvreduce --size 337G /dev/crypt/ubuntu 

# then I needed to reduce the size of the physical volume which holds both ubuntu and PureOS. that one showed 453GB so the math was easy
pvresize /dev/mapper/cryptroot --setphysicalvolumesize 437G

# decided to check things out again
cryptsetup status

# resize the encrypted partition. Here I am attempting to reduce to 481GB
# number of blocks / 1024^2 = number of GB
cryptsetup resize /dev/mapper/cryptroot -b 504365056

# Note:  this gave me a warning that I actually had more than 481GB of space. In fact I had 484GB so I tried parted instead
parted resizepart 484GB

# that seemed to work so I wrote the change
parted write

# now I needed to make a new file system for the space I freed above
mkfs ext4 /dev/sda6

# use the editor of your choice to open /etc/fstab. I commented out the previous reference to the boot partition I'm about to get rid of and made a new reference to the new filesystem
/dev/sda6    /boot    ext4    0    2

# we need a directory to mount
mkdir /mnt/boot

# then we mount it
mount /dev/sda6 /mnt/boot

# copy the old boot into the newly mounted boot directory
rsync -rsv /boot/ /mnt/boot/

# un-mount both
umount /mnt/boot
umount /boot/

# remount boot
mount /boot

# check things out one more time
df -h

# then if everything looks good...

# now we need the root directory to know how to boot with the new copy of boot at the end of the disk
grub install --root-directory / /dev/sda6

# open gparted

# something funny happened because I intended to increase the size of sda4, which was the original boot partition of PureOS, but it seems like gparted was smart enough to know I didn't want any empty space in the boot partition and it did so for me without any action on my part. Not sure whether this is a bug or a feature...

# and finally in case any of my math was wrong, I want to give any additional disk space to PureOS
resize2fs /dev/sda2

That did the trick!

As mentioned, I made the Ubuntu boot partition WAY bigger than it needs to be (16GB) but after digging in and doing some extensive re-partitioning of a Luks encrypted disk 3 times now, I feel pretty comfortable going back in to resize it to 1GB or so.