|Linux -> Backup and Restore -> Backing Up and Bare Metal Restore|
Backing Up and Bare Metal Restore
Backup Your Server's OS
Making a backup of your Linux Operating System is a very simple process that uses tools included in every linux installation, but this article if for a more advanced user with experience with storage mounts, disk partitioning, formatting and boot loaders.
The first step is to attach an external device to store the backup. This can be a USB device like thumb drive and an external hard drive, uit can even be special storage device like iSCSI and NFS mounted device to store the backup. Remember that whatever you attach and use will have to be attached and accessed by a rescue CD in the restore phase of this process. So if you can’t mount an iSCSI device in rescue mode, then don’t use an iSCSI device, the same goes for NFS attached storage. I recommend using a USB attached device or even an internal hard drive dedicated only to storing backup files.
Once you are logged into the server and at a command line, make the directory to store the backup in an organized way such as:
Now you need to create a compressed version of the Operating System in one single file (tarball) using the tar command.
tar cvpzf /path_to_stoage_device/backups/backup.tgz --exclude=/proc --exclude=/lost+found –exclude=/path_to_stoage_device --exclude=/dev --exclude=/sys /
Once the command completes the tarball named backup.tgz will be on your external storage device.
It is also recommended that you keep a printed copy of your partition scheme, the output of “fdisk –l” should be sufficient.
Performing a Bare Metal Restore
A Bare Metal Restore involves restoring the operating system of a server whose hard drive is blank or incapable of booting the installed operating system. In order to gain access to the hard drive of the server you must boot the server from alternate boot media. I recommend booting with the Operating System installation CD and choosing “Rescue Mode” in the initial choice menu. Once the boot process begins and you have chosen “rescue mode” pick through the choices to a point that you reach the command shell.
The first task is to lay out the partitioning scheme. You can lay it out exactly as the original hard drive or you can create partitions that are larger than the original hard drive. This options would allow moving the operating system from a smaller hard drive to a larger without cloning tools like ghost or clonezilla.
Here is an example of a partitioning scheme:
Device Boot Start End Blocks Id System
The only two partitions that are required are the / partition and swap, and even swap can be excluded but it is not recommended to not have a dedicated swap partition. The above shown partition scheme is setup for a small /boot partition, a swap partition that should be twice the size of the physical memory and the remainder is for the / partition.
This article is not really about creating partitions but some basics are:
For the remainder of this article we are going to use the above partition scheme for the commands being issued.
Create the partitions:
Repeat the process for the second partition
Review the scheme with p to print the table parameters to the screen.
Once the partitions have been created, the filesystems must be created. Use these commands to create an ext3 filesystems on the /boot and / partition and the swap filesystem on the swap partition.
Now you’re ready to start making the directory tree. Most of the required directories will be created by the restore process, but several need to be created manually.
Start by mounting what will be the / partition at a location that suites you, here we will use the RedHat standard of /mnt/sysimage.
Then create the directories that are not in the backup file.
Mount the partition that will be the /boot partition.
Mount the device that contains the backup file.
Change the working directory to what will be the / filesystem.
Initiate the restore process
***If your attached device and new boot drive were not labeled as the article provides examples for, you can modify the devices to represent what you have in your system. However if this is your circumstance you may need to reboot the server at this time and boot into rescue mode again and remount the proposed / and /boot partitions as you previously did. Just make sure you detach the external device when you reboot.
Now you need to launch your installation to install the boot loader using chroot. In this example /dev/sda3 must be mounted as /mnt/sysimage and if you have a separate /boot partition it must be mounted as /mnt/sysimage/boot before using chroot.
Install the boot loader with the installation command for your bootloader. The example I am providing is from a RedHat 6 or CentOS 6 installation, you may need to source the command for your linux flavor.
That’s it, your server should be ready to boot on its own. Issue the reboot command and after rebooting the server should be exactly as it was when you made the backup.