2

I want to be able to boot into a backup version of my OS in case I accidentally change something so that i cant get past the grub menu. Is there a software for this? Is this possible with timeshift?

marbri
  • 95

2 Answers2

0

I have exactly the same question.

I've found that so far:

https://community.spiceworks.com/how_to/725-backup-and-restore-your-system-grub

https://ubuntuforums.org/showthread.php?t=2356742

This one seems easy and reliable: https://www.addictivetips.com/ubuntu-linux-tips/back-up-the-linux-bootloader-to-usb-for-emergencies/

It explains everything, but in short, the command for backup is:

dd if=/dev/sda  of=/home/username/master-boot-record.txt count=1 bs=512

And for restoring, it's the inverse:

 dd if=/home/username/master-boot-record.txt of=/dev/sda count=1 bs=512

(see the links for the complete explanation about how to do that. Be careful to change "username" and the sda to suit to your system, and to not mistype anything.)

Whole grub configuration backup, according to the same site:

mkdir -p ~/grub-backup

cp /etc/default/grub ~/grub-backup/    

sudo cp -R /etc/grub.d/ ~/grub-backup/

(All backup files have to be exported to another disk or an USB stick, for obvious reasons!) Be sure to read the full page to understand the whole process before doing anything https://www.addictivetips.com/ubuntu-linux-tips/back-up-the-linux-bootloader-to-usb-for-emergencies/

For the software, I know boot-repair (but don't run the repair if you just want to backup things), but the option is not always available. It also run the boot-info script (that you can install without boot-repair if you want), it provides very useful info about your boot system.

Personnally, I try to backup all the Grub files I can, because I had bad experiences with missing 10_linux and 30_os-proberfiles, not recovered by a reinstall from grub-common...

So, as I understand the Grub system, just follow the link I provided with the dd command, but you could add, as I try to do, a backup of the etc/grub.d folder content and other grub configuration files.

They are located in the etc/grub.d and in /etc/default/grub (and eventually a part in the MBR).
You may have some backup folders like /etc/grub.d.bak and /etc/grub.d/backup, you can export their contents to a USB stick or another disk.

In this link, there's an interesting addition, about the backup of the partition table:
How to repair GRUB: How can I repair grub? (How to get Ubuntu back after installing Windows?)

Backup partition table to text file & save to external device.

sudo sfdisk -d /dev/sda > PTsda.txt

This is only for MBR (msdos) systems. If your Ubuntu install is in GPT partition drive you can only install Windows in UEFI mode or convert drive back to MBR (msdos).

That's true that a sofware or a script automatizing all this backup would be really useful and cool!

Quidam
  • 141
  • 13
0

(I don't have the priveledge of commenting yet, pardon me for breaking protocol):

What is the format & location of your backup?

Editing the grub menu is done by editing the /etc/grub.d/40_custom script. This lets grub know about your boot options when generating the file grub.cfg. That file is automatically generated whenever the command update-grub is issued. All of these require administrator permissions granted by prefacing a command with the sudo command, then providing your password again (this is done to protect the OS stack from maliscious software).