How do I backup grub files / configuration on a new installation of Ubuntu 16.04?

I would like to know: How do I backup grub files / configuration on a new installation of Ubuntu 16.04?

I had a problem with a past install and due to lack of knowledge just re-installed Ubuntu OS.

I'd like to know how to backup and restore grub so that in the future I do not have to wipe my whole system in order to get it running correctly again.

I ran command :

    sudo parted --list        
Model: ATA Hitachi HDT72103 (scsi)          
Disk /dev/sda: 320GB        
Sector size (logical/physical): 512B/512B         
Partition Table: msdos        
Disk Flags:         

Number    Start     End     Size     Type      File system     Flags            
 1        1049kB    317GB  317GB     primary   ext4            boot            
 2        317GB     320GB  3181MB    extended            
 5        317GB     320GB  3181MB    logical   linux-swap(v1)            

Is there a command that gets more specific on MBR / GPT?

I show msdos on my external hard drive as well but it is NTFS specifically.I assume msdos is referring to MBR on my system hard drive but am wondering if there is a command that will specifically show MBR or GPT?

That is actually getting into a different question.

I've marked question as answered and thank them for the official docs as well for detailed information.


First, you can always chroot into your broken Ubuntu and reinstall the GRUB, read here.

! These commands are dangerous, be aware of what you are doing !

However here is what I do:

  1. Get a backup from MBR:

    sudo dd if=/dev/sda of=/home/user/mbr bs=512 count=1
    
  2. Get a backup from files within the /boot directory.
    • It's not really necessary, you can only get a copy of /boot/grub/grub.cfg it's the file containing the menu entries

Note that /dev/sda is my first hard disk where my grub has been installed on for you it might be /dev/sdb or something else.

When ever I broke my system's GRUB (Most of the times its a broken MBR), I can easily boot into a Live system and restore my MBR using:

sudo dd if=/home/usr/mbr of=/dev/sda

And my MBR with a working grub is back, you can also use your backup from /boot to restore anything else that might be corrupted.