Simpsonian 🍁︎

Open Heart Partition Surgery

Sometimes in this life, you aren't sure that something will work, but you have to try it anyway.

The other day, I ran some experiments that I would describe—in my usual overdramatic way—as "open heart partition surgery."

A word to the wise: this post is really just a braindump for me to refer back to later, and is even less coherent than usual. It is certainly not a how-to guide… but if you are looking to mutilate your hard drive, welcome!

Backstory

A couple of months ago, I took advantage of some holiday sales and finally put together a desktop PC. I knew that I wanted to run Linux, but which distro? I've been using Ubuntu on my laptop for years, and while it's treated me well, I've been longing to explore new lands and gain a hands-on appreciation for the differences between distros. What better excuse to go distro-hopping than a fresh build?

I settled on testing two distros: Pop!_OS and Arch. Pop!_OS obviously felt familiar (it's based on Ubuntu), but with a souped-up desktop environment full of keyboard shortcuts and a tiling window manager option that appealed to me. Conversely, Arch's appeal lay in its challenge: it has a bit of a reputation for being a real "hacker's" distro—no picture book illustrations in my installer, thank-you-very-much; a shell (zsh, btw) is more than enough for me. This stereotype isn't quite true—the documentation on the Arch Wiki is usually very helpful and to-the-point—but it there is a hint of verity to it.

I won't belabour my comparison of the two here, but suffice it to say that it didn't take long before Arch + KDE Plasma won me over entirely. Two months later, I was ready to thank Pop!_OS and let it go. (Although I do miss some part of its desktop environment!)

However, I was now facing a problem. When setting up my PC, I installed Pop!_OS first. Being relatively inexperienced with this sort of thing, I used my best judgement with the partitioning strategy and created the following partitions (via the Pop!_OS installer): one for boot, one for Pop!_OS itself (followed by some empty space), then a separate partition to store games (so that I only needed to download games once, while still being able to play them on either distro—this worked great!) and finally a swap partition.

Model: Samsung SSD 980 PRO 1TB (nvme)
Disk /dev/nvme0n1: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system     Name   Flags
 1      1049kB  1075MB  1074MB  fat32                  boot, esp
 4      1075MB  250GB   249GB   ext4            popos
 5      250GB   446GB   196GB   ext4            arch
 2      446GB   983GB   537GB   ext4            games
 3      983GB   1000GB  17.2GB  linux-swap(v1)         swap

(Note: I was insufficiently diligent and didn't take complete notes as I worked through this; the above is me approximating what the actual parted output would've looked like at the time.)

This worked fine when I was just evaluating Pop!_OS and Arch, but now I find myself wanting some unpartitioned disk space to play around with Linux From Scratch. What I would really like to do is relocate the existing Arch partition to where the Pop!_OS partition currently resides and extend it a bit (while leaving a little space unallocated). Can we make that happen?

Thought process

Based on some previous knowledge and a bit of general research, I found myself ruminating on the following pile of thoughts:

Chapter 14 of Michael Kerrisk's The Linux Programming Interface was quite useful for confirming some of my uncertainties here.

The plan

Taken together, those thoughts suggest a plan: presumably, we should indeed be able to just reformat the Pop!_OS partition, copy over everything from the old Arch partition, then delete the old Arch partition, and extend the new Arch partition to use some of the old partition's space. In checklist form:

  1. Back up everything important on the old Arch partition! I give it at least a 30% chance I end up needing to do a fresh install, so let's not lose anything should that happen.
    • Come to think of it, I should've done the same for the Pop!_OS partition too… welp, it probably didn't have anything important anyways… 😬
  2. Delete the Pop!_OS partition
  3. Create a new partition in the place of the old Pop!_OS partition
  4. Create a new ext4 filesystem on the new partition
  5. Copy everything from the old Arch partition to the new partition
  6. Add boot entries for the new Arch partition
  7. Pause: reboot; confirm that we can still boot to both the new and old Arch partitions
  8. Delete the old Arch partition, and extend the new one to fill (some of) that space
  9. Resize the filesystem on the new partition to use the newly-expanded space; update boot entries

How did it go?

Surprisingly well! I'm writing this from my "relocated" Arch partition, and as best I can tell, the procedure was a complete success. As a general note, I used parted for all the partition-related tasks, and performed most of these commands from the Arch installation image (because I can't imagine messing with mounted partitions ends well). Below are my play-by-play notes from the operation; I haven't explicitly linked them to the checklist steps above, but I hope it's obvious enough from the context.

After all of that, I have a working system with the following partitions:

Model: Samsung SSD 980 PRO 1TB (nvme)
Disk /dev/nvme0n1: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system     Name   Flags
 1      1049kB  1075MB  1074MB  fat32                  boot, esp
 4      1075MB  350GB   349GB   ext4            arch
 2      446GB   983GB   537GB   ext4            games
 3      983GB   1000GB  17.2GB  linux-swap(v1)         swap

Huzzah!

Lessons Learned

Here's what I took away from going through this: