Home > General > Linux backup/restore and grub2 reinstall

Linux backup/restore and grub2 reinstall

Not exactly related to MythTV, but very useful because MythTV often breaks when upgrading, so you want to be able to easily restore an old version.

In order to backup linux, I use dump and restore.

You can backup your system drive by booting into rescue mode and running the following:

/sbin/dump -0 -v -a -y -f- -L “Linux root partition” /dev/sda1 1>filename.dump 2>filename.log

To restore, use the rescue mode of the installation DVD and mount the drive you want to restore to. Then go to the root directory of that drive and type:

/sbin/restore -r -f /location-of-dump-file/filename.dump

I’ve used this approach successfully for a long time. Now with the switch to grub2, I had to figure out how to reinstall grub2 on the disk after doing the restore.

After a lot of googling, I finally figured it out and wrote the following script:

#!/bin/bash
read -p “Press ENTER to restore grub2…”

echo
echo Mounting /dev/sda1 to /mnt/sda1 – these may already be mounted
mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1

echo
echo Mounting bindings
mount –bind /dev /mnt/sda1/dev
mount –bind /proc /mnt/sda1/proc
mount –bind /sys /mnt/sda1/sys

echo
read -p “Press ENTER to install grub”;
echo Installing grub and configuring it for local drive
chroot /mnt/sda1/ /bin/sh -c “/sbin/grub2-install /dev/sda; /sbin/grub2-mkconfig -o /boot/grub2/grub.cfg”

WARNING 1: You will want to change your drives/partitions listed in these scripts.

WARNING 2: Always do regular test runs of backup and restore – you want to be 100% sure they work when you need them! This is easy if you get an extra harddrive that you can test with.

WARNING 3: I’m not responsible for your data or the correctness of the scripts above. Use the above scripts/commands at your own risk!

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s