Ubuntu Live Rescue
Overview
How I Managed to return to booting from an old partition when I had changed the active boot partition using 'testdisk' and got myself into trouble.
Create/Fix Grub 2 boot
Boot from Ubuntu Live USB
Choose 'try ubuntu'. Boot Normal mode Without persistence Open a terminal window.
Detect Partition to install GRUB
sudo fdisk -l
output:
Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disklabel type: dos Disk identifier: 0x5f540829 Device Boot Start End Sectors Size Id Type /dev/sda1 2048 156205055 156203008 74.5G 83 Linux /dev/sda2 * 156205056 968665087 812460032 387.4G 83 Linux /dev/sda3 968665088 976771071 8105984 3.9G 82 Linux swap / Solaris
Note:
/dev/sda1 is the one that we can still boot from. /dev/sda2 is the one I made active (causing the problem)
- Mount Partition(s)
sudo mount /dev/sda1 /mnt
Now point /dev and a few others to locations on the partition so grub uses those.
for i in /dev /dev/pts /proc /sys; do sudo mount -B ${i} /mnt${i} ; done`
- Maskerade as though ''/mnt' were now ''/''
sudo chroot /mnt
# You can get back to the main root with <ctrl>d
- install grub
grub-install --recheck /dev/sda
# The recheck checks/rebuilds the partition map grub uses.
- update grub
update-grub
exit
- unmount partitions
for i in /sys /proc /dev/pts /dev ; do sudo umount /mnt${i}; done
sudo umount /mnt
reboot computer
The steps above corrected my problem, but I still had to choose a grub recovery option to boot properly.
This is because the active partition is still set to the one that does not work. We need to switch the active partition.
To do that, I booted up using grub recovery option.
I Then logged into the Ubuntu 16.04 partition and used the GUI app called disks . I edited the (wrong) active partition to turn off "bootable", then edited the correct partition to turn it on.
After that reboot brought up the working partition hands free.
Note1
This Note is all but copied from the link where I learned how to do this stuff:
How To install/repair GRUB with Ubuntu Live CD/Flash
Note2
testdisk is a popular tool to recover data from faulty partitions.
But Since our partitions were pretty well intact, we did not need it in this case.