Recover partition table with systemrescue and testdisk

Modified on Wed, 24 May 2023 at 02:40 PM

TABLE OF CONTENTS


Symptom(s)


Missing partitions in lsblk (or similar) output.


Solution


It is advisable to backup your system before attempting any partition repairs.


In the article below `sdX` is a placeholder, do not literally type sdX.
Make sure to substitute sdX with the correct disk drive.

Boot into systemrescue cd.


To analyse the device and recover lost partitions, run the following, pointing it to the drive with missing partitions. Run the command and follow the prompts:


testdisk /dev/sdX


A quick scan is usually sufficient.


On a successful discovery of the partition(s) you can 'write' them by 

navigating trough menu options, once done, select 'Quit'.


If it's a boot disk ...


If the disk that lost it's partitions was a boot disk, it will most likely have lost the grub installation too.

To start the recovery of grub, we need to mount the disk.
The process of mounting the partitions will depend on how the machine was set up.
Run `lsblk` again to see all the partitions
The most important partitions is root (/) and when present boot (/boot)

For example:

mount /dev/sdXn /mnt


mount /dev/sdXn /mnt/boot


Rebind the virtual file systems
This is required so that grub has system access to the machine instead of regular jail access:


for i in proc sys dev; do mount -o bind /$i /mnt/$i ; done


Change the root of the system to the OS being repaired:


chroot /mnt


Fix/Install bootloader 


grub-install /dev/sdX


OR


grub2-install /dev/sdX


AND


exit


If the above command fail consistently, it is also possible to repair grub outside of a chroot. If you are chroot'ed, exit out of it and run:


grub-install --root-directory=/mnt /dev/sdX


Be sure to replace the grub install root directory and the device with the ones applicable on your system.


And start the system normally.


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article