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.
- I booted up into Ubuntu on a USB stick.
- I installed TestDisk and used this step-by-step guide to recover my lost partition.
- I rebooted. The partition was there, but the computer didn't know how to boot.
- 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/sdahere, even though I mounted
sudo umount /mnt
- I rebooted, and it came up fine, but with a warning about a missing disk. I'd lost my swap space.
- 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/fstabto say that
/dev/sda2was swap space now.
- Rebooted and all was well.
Phew! TestDisk is extremely helpful.