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
  • I find including one of the dd commands from the linked page without any explanation quite disappointing. Well, not enough, dangerous if it’s executed blindly! (That’s the reason why the name dd is sometimes explained as “destroy disk“.) Please provide full usage and explanation for this command or remove it from your answer. Moreover, your answer says about backing up MBR while OP wants to backup their OS… – Melebius Jun 04 '20 at 07:24
  • In this case I have to copy the whole page, because everything that is explained is an important step. Please don't downvote before giving me the chance to improve the post. There's a warning, "see the link for the complete explanation about how to do that), maybe I should make it bold? – Quidam Jun 04 '20 at 07:44
  • The whole paragraph about the dd command says: "Need to restore your MBR backup? Boot into your broken Linux PC’s system with one of these Grub tools here. Then, open up a terminal, connect your USB device that has the “master-boot-record.txt” file, place the file back into your home directory (~/), and run the following command.

    Note: like before, it’s critical that you change /home/username/ and /dev/sda to reflect your username and actual hard drive’s label." For more info, I have to paste the whole page.

    – Quidam Jun 04 '20 at 07:46
  • Downvotes can be retracted after the post is edited (by fixing the problem, altering the formatting is not enough). I agree that “everything that is explained is an important step”, you cannot just copy one (potentially dangerous!) command! Moreover, the article explains that before restoring MBR you have to backup it, so your single command is out of context. And what if OP used GPT instead of MBR? – Melebius Jun 04 '20 at 07:50
  • Restoring something is always after backing up as far as I understand English (not my language). You can suggest your edit and edit directly the post, as I don't see how to make the command non dangerous, unless including the paragraph above. It says "need to restore your MBR backup", so it's clear that it's a backup, but I will include the backup step that is missing. – Quidam Jun 04 '20 at 07:59
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).