Extend/resize a LUKS partition on a dual boot setup

Hi!

I’m currently running F41 on a dual boot with Windows, and I have voluntarily left some space for a 3rd partition where I initially intended to put files meant to be shared with both OS with a VeraCrypt encryption.

As of now, I’m quite happy with Fedora and spend 95% of my time on it. So I’m rather thinking about extending my Fedora partition that is currently LUKS-encrypted.

I’ve read several threads here and there talking about LVM, cryptsetup, etc., but haven’t found any 101 on the topic. (I’m not fluent yet in CLI and all, and those threads on StackExchange, Reddit or other Reddit have not given me full confidence in the process.)

So:

  1. Is it possible?
  2. Is there any GUI/easy way to do it?
  3. If not, are there any clear and pedagogical CLI steps somewhere?

Many thanks ahead for your help!

P.S.: If it is not possible whatsoever, how can I save properly my current setup (Fedora config. and files) so that I delete my current partition and create a new one without needing to reset my extensions, workspace, etc.?

It should be possible. I think this is what you are looking for: Add storage to your Fedora system with LVM - Fedora Magazine

You should still make a full backup of all your filesystems and subvolumes. Assuming your filesystem is Btrfs, you can use the btrfs send ... command to send snapshots of your filesystems to an external device so you’ll have a backup in case something goes wrong. See the " Storing snapshots on a different Btrfs filesystem" section of this article: Working with Btrfs - Snapshots - Fedora Magazine

Hi @glb!
Thanks for your answer, and sorry for my late reply. I’ve left that topic aside for a while, but I’m back on track.

I’m actually having an ext4 setup, so the btrfs method does not work for me.
As for the link you provided, I don’t see any mention of LUKS setup. I have read on different threads that it can get tricky when encryption is on.

And I don’t feel savvy enough in CLI to do everything on my own without a GUI. I’ll see if I can find some help from a Linux-savvy person around. Unless there’s another way to do it!

https://www.reddit.com/r/Fedora/comments/1e83g5u/extending_encrypted_btrfs_partition_to_use_full/

https://www.reddit.com/r/archlinux/comments/y835f1/how_do_i_resize_a_btrfs_partition_inside_luks/

Yes, LVM is quite complicated. I would definitely recommend having a good backup before you attempt to extend your LUKS volume.

Ext4 backups can be done with the dump command: 5.4. Backing up ext2, ext3, or ext4 File Systems | Red Hat Product Documentation

You might even want to clone your entire HD to a secondary drive if you can.

Good luck.

P.S. These are exactly the reasons Fedora Linux switched to Btrfs by default – easier backups and easier space management (you can set quotas in Btrfs rather than having to deal with resizing partitions or volumes).

I would like to reinforce this suggestion.

I regularly clone my dual-boot’ing system simply because I don’t want any grief from having both bitlocker-encrypted Windows and LUKS-encrypted Fedora partitions on my SSD. To do that, I attach the secondary drive, boot the latest Fedora Workstation live system, install ddrescue, and then use that to clone the drive to the external drive. If you do that, you’ll be bulletproof should you make a mistake in your process.

Also, you don’t say whether you’re using LVM on your system, so I can see how the Stack Exchange LVM-related link would have parts that make the process seem more complicated if you don’t currently have and LVM set up.

The one from Fedora Magazine was targeting adding a separate, new physical device to your LVM storage, so that one is irrelevant, I think.

Good luck!

1 Like

I recently had no problem resizing a LUKS encrypted Btrfs partition with GParted, and I’m sure it has no problem with ext4, but I don’t know if LVM makes things more complicated.

Great info, thanks!

OP: If you’re planning on using gparted from a live Fedora system, please note that, like ddrescue, you’ll need to install it from that system; it’s not included in the live distro: sudo dnf install gparted.

Good luck!

Hi everyone!
Thanks for your replies and support!

@katflap @jrredho I’m not sure whether I’m using LVM or not. How can I figure this out? (Sorry, I’m quite new to Linux.)

As for the backup, I’ve backed up my files with DéjàDup. But from what I understand, ddrescue goes deeper and allows to restore the whole system configuration, right?

I’m a bit struggling with a how to save my entire system easily (file systems and configuration + user files), being used to TimeMachine. So if ddrescue does it all, I might give it a try, although there is no GUI.

There might be a last option to scratch my existing Fedora setup and start anew, using btrfs if it’s meant to ease backups. What do you think?

You can use ddrescue to clone entire disks or a selection of individual disk partitions. You can restore any of these via ddrescue. It is also possible to figure out how to mount any of the partitions and restore selected system files, although you will have to figure out how to, say, use cryptsetup subcommands to decrypt these partitions and make filesystem(s) on them available.

As for how to see if your system is currently using LVM, you can use any LVM-related command, such as pvdisplay, pvs, or pvscan. If they return results, then you’re system is setup with LVM. Oh, these probably require sudo to run properly, but I’m not sure.

Good luck!

Hi again!
Thanks for your reply and for the details regarding ddrescue.

:person_gesturing_no: No LVM apparently

I’ve tried the CLI to check wether I’m LVM-based or not, I either get no results or No matching physical volumes found for the pvscan one.
So I guess I’m not using LVM.

:information_source: Instructions to proceed

I have tried to figure out how to use gparted properly, reading many articles. I must admit it’s quite confusing for me. From what I understand, since Feb. 2017, gparted can handle LUKS resizing. So there’s no need to follow complicated step-by-step instructions like these. However, it looks like some add additional steps.

These instructions are the easiest I’ve found, but they don’t mention using resize2fs after extending the partition. On the contrary, this thread mentions it, like many pre-2017 threads. I put my sources below.

:stethoscope: Sanity check

And I’m sharing my setup here just to check I’ve understood correctly.
My home data is in nvme0n1p6, and I want to extend it using the free space in nvme0n1p7.

  1. Can I simply resize my p6 partition with gparted by using the unallocated space (p7, currently a partition that is meant to be deleted) once it is decrypted?
  2. Should I leave 10% of unallocated to optimize my SDD performance? (I’ve read that on one thread, but that would mean leaving about 180 Go free, which seems a lot to me.)
  3. Do I need to do anything with my p5 partition (where my file system is stored)? Is this partition anyhow connected to resize2fs? Should I run that command? If so, when/where/how?
nvme0n1           259:0    0   1,8T  0                                        
├─nvme0n1p1       259:1    0   550M  0 vfat    /boot/efi                      
├─nvme0n1p2       259:2    0     1G  0 ext4    /boot                          
├─nvme0n1p3       259:3    0 244,1G  0 ntfs                               
├─nvme0n1p4       259:4    0    16M  0                                        
├─nvme0n1p5       259:5    0    70G  0 crypto_                           
│ └─luks-
│                 253:0    0    70G  0 ext4    /                              
├─nvme0n1p6       259:6    0   300G  0 crypto_                                
│ └─home          253:1    0   300G  0 ext4    /home                     
└─nvme0n1p7       259:7    0   1,2T  0 ntfs                                   

:books: Sources

After 2017, gparted now managing LUKS

Caution: some remind it is important to resize file systems too properly with the resize2fs CLI.

Before 2017, when gparted didn’t manage LUKS

Other sources

@jrredho @glb If you have some time, I’d be happy to have your insight on those questions before proceeding to the extension! (And if not, I’ll try to find some help with a local IT guy!)

I’ve never done it with LUKS, so I’m not sure what issues you might encounter there. FWIW, I have done this sort of thing before with non-LUKS partitions: BTRFS partition corrupted - #22 by glb

No. It doesn’t matter with regard to your partition boundaries. Just don’t completely fill all your partitions with files. It doesn’t even matter exactly where on your SSD the unallocated space is. The “unused” space could, for example, be in your ESP.

Again, I haven’t done this with LUKS, but yes, there are (at least) two things you need to resize – first your partition, then your file system. Some automated tools may perform both those operations with “one click”, but I don’t know. I haven’t used the newer (more automated?) tools.


P.S. To let your SSD know about the free blocks in your ESP, your ESP will need to be formatted with VFAT to support trim/discard and you will need to either manually run fstrim ... on your ESP once in a while or add discard as an option for the ESP mount in your /etc/fstab.

I don’t purport to be an expert on any of this, but I can tell you what worked for me when I replaced the NVMe SSD on my laptop from a 256GiB SSD to one that was 1TiB. (Steel yourself; this will be a bit painful to read, I’m sure…)

Note that the following occurred after I’d already installed f33, I believe, and that was after doing all of the necessary re-partitioning/resizing of my main, Bitlocker-encrypted, WindowsOS partition up front.

My LUKS-encrypted, btrfs filesystem, with / and /home subvolumes was the last partition on the native drive with no blank space at the end, iirc:

  1. I plugged in an external SSD controller with the 1TiB SSD installed in it via a USB C connection and booted the then current Fedora Workstation live iso;
  2. From the live iso, I installed gparted and ddrescue using dnf;
  3. Fired up gparted to find the device identifiers for the source and target drives so that I could clone my native SSD;
  4. Did the clone of the entire native drive to the target, 1TiB SSD using ddrescue with the previously identified source and target drives;
  5. Once that finished, back in gparted, I refreshed the device list, and, at refresh time, that application showed output that indicated that the still present target drive appeared to be smaller than its physical size; this warning queried whether I wanted to extend it to reflect its physical size. I responded by clicking the ‘Yes’ button.

So, my memory is that this last partition was already LUKS resized to the size of the entire partition.

After all of that, I did couple of syncs just to be safe and shut down the system, and I physically replaced the native SSD with the larger, now cloned and extended SSD. Everything worked exactly like I’d hoped: I could boot both Windows and Fedora, and all the filesystems were present, as before the swap, on each.

  • My last step was to boot into Fedora and resize the btrfs file system. The command to do that looked something like btrfs filesystem resize max /. Obviously, you’ll have to use a different command than that for your system.

Okay, if you’re with me this far, I guess the answer to your question is that, within the constraints of my old-guy memory, resizing a LUKS-encrypted partition using gparted will resize the LUKS container automagically. You should be able to boot your installed Fedora system and check that this is the case by using df and cryptsetup status and comparing the results.

Here’s how to do that last bit, from your now-booted, installed Fedora system, which I’ll show you with the example of how I do that on mine.

  • First, find the name of your LUKS device: ls -l /dev/mapper/.
  • Mine comes back as luks-d32f8c7c-a450-4d8e-884a-965066607f69, which is a symbolic link to a device in /dev.
  • Using that name, I can check the LUKS container size in one of the fields returned by sudo cryptsetup status luks-d32f8c7c-a450-4d8e-884a-965066607f69.

I can tell you that mine checks out consistently using various cross checking methods, such as gparted, df, etc.

Wow, that was a lot longer than I set out to make it! I hope it helps you get started. Good luck!

2 Likes

Alright! Many thanks @jrredho and @glb! I’ll do my best to follow your steps and will let you know how it went!

2 Likes