Resizing Partitions

Tags: disk usage linux partition arch

The Background

On my recent Arch install, I decided to create separate partitions for my root and home directories. Unfortunately, I'm a dummy and only allocated 20 GB for the root partition. As it turns out, that's not enough for a proper workstation setup so now I have to fix my mistake.

The Fix

My particular install involves two usb drives, one with the Arch boot partition and the other with a cryptographic key to unlock the hard drive in my laptop. So to get started, I remove the usb drive with the boot partition and replace it with another usb that holds the Arch live environment I originally used for the installation. This way, I can boot into the live environment, unlock my drive, and resize the partitions while they're not in use.

Decrypting the Drive

I used dm-crypt plain mode to encrypt the drive so the first step is to unlock it so I can see the partitions. That looks like this:

cryptsetup --cipher=aes-xts-plain64 --offset=0 --key-file=/dev/sdc --key-size=512 open --type plain /dev/sda cryptlvm

In the above code snippet, /dev/sdc is the usb drive containing nothing but my cryptographic key and /dev/sda is the drive I'm decrypting.

At this point, I can see my logical volume group which look something like this:

sda                   8:0      0   400G  0 disk
  └─cryptlvm          254:0    0   400G  0 crypt
    ├─MyVolGroup-swap 254:1    0     8G  0 lvm   [SWAP]
    ├─MyVolGroup-root 254:2    0    20G  0 lvm   /mnt
    └─MyVolGroup-home 254:3    0   372G  0 lvm   /mnt/home

At this point, I can hopefully use lvresize to reduce the size of my home partition and add that extra space to my root partition. So let's give that a go:

lvresize -L -20G --resizefs MyVolGroup/home
lvresize -l +100%FREE --resizefs MyVolGroup/root

It worked!

Surprisingly painless. And now my root partition is twice the size it used to be so I can install more packages without fear of running out of space.