Miskatonic University Press

How I recovered a lost partition

unix

Last week I was setting up a bunch of drives for a new backup system (which I'll post about soon) and while partitioning and formatting I accidentally removed the single partition from my main laptop. That was not good. I knew it would keep on working as long as it stayed on, but when it rebooted, I'd be in trouble. I had backups, and if it came to the worst, I could reinstall Ubuntu and copy my files back, but that would take an evening, after all the various programs and packages I use had downloaded and installed.

With a bit of luck, though, it only took about twenty minutes.

  1. I booted up into Ubuntu on a USB stick.
  2. I installed TestDisk and used this step-by-step guide to recover my lost partition.
  3. I rebooted. The partition was there, but the computer didn't know how to boot.
  4. So I reinstalled GRUB. I can't find the actual page I used with the commands, but my drive was /dev/sda, the partition I'd recovered was /dev/sda1, and I did this:
    • sudo mount /mnt /dev/sda1
    • sudo grub-install --mount-directory /mnt /dev/sda (note /dev/sda here, even though I mounted /dev/sda1)
    • sudo umount /mnt
  5. I rebooted, and it came up fine, but with a warning about a missing disk. I'd lost my swap space.
  6. I used gparted to allocate swap space out of some empty disk space that probably was swap space before but got lost along the way. I had to edit /etc/fstab to say that /dev/sda2 was swap space now.
  7. Rebooted and all was well.

Phew! TestDisk is extremely helpful.