Here’s a summarized version of the main commands and steps to recover from a deleted OS situation using a live USB environment, including troubleshooting for common issues like disk space:
Summary: Recovering GRUB and Restoring Deleted OS Data
Prerequisites:
- Bootable Ubuntu 24.04 live USB. ( although I has 23.10 USB while system installed was 24.04 but it worked)
1 Mount partitions
-
Boot into the live USB and open a terminal.
-
Identify the partitions:
sudo fdisk -lYou will see 2 partition, one is EFI ( sometimes it is not there ) and one is Linux FileSystem
Device Start End Sectors Size Type/dev/nvme0n1p1 2048 206847 204800 100M EFI System/dev/nvme0n1p2 206848 239615 32768 16M Microsoft reserved/dev/nvme0n1p3 239616 211358180 211118565 100.7G Microsoft basic data/dev/nvme0n1p4 211359744 294244351 82884608 39.5G Microsoft basic data/dev/nvme0n1p5 294246400 295315455 1069056 522M Windows recovery environment/dev/nvme0n1p6 295315456 500115455 204800000 97.7G Linux filesystem- Mount the root partition (replace /dev/nvme0n1p6 with your actual root partition):
sudo mount /dev/nvme0n1p6 /mnt- If there’s an EFI partition (typically small, like 100MB):
sudo mount /dev/nvme0n1p1 /mnt/boot/efi2 Copy data from os_deleted to root
actually the osuninstaller command moved files from root partition to os_deleted;
you can check whether /etc, /proc, /sys, /run directories are under root partition (i.e./dev/nvme0n1p1_ ) or not and if these directory are under os_deleted folder then we have to follow below step
- If your data was moved to os_deleted:
sudo rsync -av /mnt/os_deleted/ /mnt/This command copies the contents of os_deleted back to the root partition.
If “No space left on device” error occurs:
Remove large or unnecessary files:
sudo rm -rf /mnt/var/cache/apt/*sudo rm -rf /mnt/var/log/*Use find to locate large files:
sudo find /mnt -type f -size +100MThen remove any unnecessary large files:
sudo rm /mnt/path/to/large/filein my cae there are images and video files so removed those
3 chroot into the system
- Bind the required directories:
sudo mount --bind /dev /mnt/devsudo mount --bind /proc /mnt/procsudo mount --bind /sys /mnt/syssudo mount --bind /run /mnt/run- Enter the chroot environment:
sudo chroot /mntif above command gives error: failed to run command /bin/bash : No such file or directory means you do not have all required files in root directory
you can run sudo fsck /dev/nvme0n1p4 to check corrupted files
4 Reinstall GRUB
- Install GRUB for UEFI systems:
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu- Update the GRUB configuration:
update-grub
- If you encounter “unable to allocate pty”, run:
mount -t devpts none /dev/pts5 Exit chroot and unmount
- Exit chroot:
exit
- Unmount the bound directories:
sudo umount /mnt/devsudo umount /mnt/procsudo umount /mnt/syssudo umount /mnt/runsudo umount /mnt/boot/efi # If mountedsudo umount /mnt6 Reboot
- Reboot the system to check if GRUB is restored:
sudo rebootTroubleshooting tips:
If “target is busy” during unmount, use:
sudo umount -l /mntTo list processes using a mount point:
sudo lsof +D /mntsudo fuser -vm /mntsudo fuser -k /mnt # To kill processesUse rsync with —exclude to temporarily skip non-essential data if space is an issue:
sudo rsync -av --exclude='home/*' /mnt/os_deleted/ /mnt/
This should help for restoring the system and resolving common errors encountered during the process.
Hope it helps