You are not logged in.

#1 2025-01-17 11:19:26

theo01
Member
Registered: 2025-01-17
Posts: 5

shrink and move luks encrypted root partition

Hello,

I have a root filesystem encrypted with luks1 and and I need to resize and move it to the right in order to grow my boot partition. How can I proceed ?

# lsblk -f
NAME                                          FSTYPE      FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
loop0                                         squashfs    4.0                                                    0   100% /var/lib/snapd/snap/core20/2379
loop1                                         squashfs    4.0                                                    0   100% /var/lib/snapd/snap/core20/2434
loop2                                         squashfs    4.0                                                    0   100% /var/lib/snapd/snap/snapd/23258
loop3                                         squashfs    4.0                                                    0   100% /var/lib/snapd/snap/snapd/23545
nvme0n1
├─nvme0n1p1                                   vfat        FAT32       AC41-B686                             133,4M    56% /boot
├─nvme0n1p2                                   crypto_LUKS 1           87550b66-7982-4503-9dec-c23d015351ce
│ └─luks-87550b66-7982-4503-9dec-c23d015351ce ext4        1.0         4604eb05-9aeb-453f-9cd2-6d6e6f30ee9f  663,2G    59% /
└─nvme0n1p3                                   crypto_LUKS 1           1676a75f-b260-453c-890d-75ccaec3292b
  └─luks-1676a75f-b260-453c-890d-75ccaec3292b swap        1     swap  d463e634-4e5a-4ca3-9de7-297df5e0ac08                [SWAP]
# cryptsetup status /dev/mapper/luks-87550b66-7982-4503-9dec-c23d015351ce
/dev/mapper/luks-87550b66-7982-4503-9dec-c23d015351ce is active and is in use.
  type:    LUKS1
  cipher:  aes-xts-plain64
  keysize: 512 bits
  key location: dm-crypt
  device:  /dev/nvme0n1p2
  sector size:  512
  offset:  4096 sectors
  size:    3928465583 sectors
  mode:    read/write
  flags:   discards

Offline

#2 2025-01-17 11:26:13

frostschutz
Member
Registered: 2013-11-15
Posts: 1,487

Re: shrink and move luks encrypted root partition

I would leave the partition where it is and instead relocate /boot to the end of disk. It's not necessary to shuffle around 600+GB of data, risking data loss in the process.

Otherwise do a full backup and then just set it up from scratch. Probably faster to copy files anyways (since that filesystem is 50% empty).

Offline

#3 2025-01-17 11:48:49

theo01
Member
Registered: 2025-01-17
Posts: 5

Re: shrink and move luks encrypted root partition

True, moving /boot to then end of disk sounds safer than moving data around. Yet I have no free space at the end of disk. What tool should I use ? resize2fs and cryptsetup resize ? I just don't know what's the sequence there.

Offline

#4 2025-01-17 19:53:58

gcb
Member
Registered: 2014-02-12
Posts: 183

Re: shrink and move luks encrypted root partition

another option is not needing a larger boot.

I use 1GB for boot and never care about that. but sometimes i get employer machines with those small /boot and have to set it up for 1) compress initramfs https://wiki.archlinux.org/title/Mkinitcpio#COMPRESSION and 2) remove fallback and other things https://bbs.archlinux.org/viewtopic.php … 5#p2154175

Offline

#5 2025-01-17 22:38:40

kermit63
Member
Registered: 2018-07-04
Posts: 288

Re: shrink and move luks encrypted root partition

How big is your swap partition?

If it is big enough, you may be able to skim off a few hundred MBs from it to create a /boot partition at the end of the disk, as frostschutz suggested. It is a lot easier resizing or even recreating the swap partition.

Another option is to totally do away with the swap partition, then create a swap file in your root partition to take its place. This should free up more than enough space at the end of the disk.


Never argue with an idiot, they will drag you down to their level and then beat you with experience.
It is better to light a candle than curse the darkness.
A journey of a thousand miles begins with a single step.

Offline

#6 2025-01-18 16:57:03

theo01
Member
Registered: 2025-01-17
Posts: 5

Re: shrink and move luks encrypted root partition

I workaround this by changing the initramfs compression to default: zstd, so I can now fit 2 initramfs in boot but this solution won't last long as there's now only 20Mb left on the boot partition. For now I am good.
My swap partition is 34Gb.
If I need more space I'll consider either removing the fallback images or moving my boot partition to end of disk after swap. Thanks for your help.

Offline

Board footer

Powered by FluxBB