1-877-24-PRONTO     Live Sales Chat    Get Support    Login
ServerPronto HowTo
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:

mkdir /path_to_storage_device/backups

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
/dev/sda1 1 63 514048+ 83 Linux
/dev/sda2 64 8223 65537167+ 82 Linux swap / Solaris
/dev/sda3 8224 10773 1865909587+ 83 Linux

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:

  1. The partition that will contain the boot loader files needs to have the boot flag set, this is usually /dev/sda1.
  2. The swap partition is type 82, the default type for fdisk is 83, which is fine for the other partitions.
  3. If you use parted vs. fdisk you will need to create a disk label, using msdos is a better option for boot drives as many servers cannot boot gpt drives.

For the remainder of this article we are going to use the above partition scheme for the commands being issued.

Create the partitions:

/sbin/fdisk /dev/sda
n for new partition
p for primary partition
1 for the first partition
1 for the start of the partition
63 for the end of the partition
a to toggle the boot flag

Repeat the process for the second partition
n for new partition
p for primary partition
2 for the second partition
64 for the start of the partition
8223 for the end of the partition
t to change the partition type
82 to specify the swap partition type

Repeat the process for the third partition
n for new partition
p for primary partition
3 for the third partition
8224 for the start of the partition
Default enter for the end of the partition

Review the scheme with p to print the table parameters to the screen.
If you’re satisfied, write your changes with w.

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.

/sbin/mkswap /dev/sda2
/sbin/mke2fs –j /dev/sda1
/sbin/mke2fs –j /dev/sda3

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.

mkdir /mnt/sysimage
mount –t ext3 /dev/sda3 /mnt/sysimage/

Then create the directories that are not in the backup file.
mkdir /mnt/sysimage/boot
mkdir /mnt/sysimage/proc
mkdir /mnt/sysimage/backups
mkdir /mnt/sysimage/dev
mkdir /mnt/sysimage/sys

Mount the partition that will be the /boot partition.
mount –t ext3 /dev/sda1 /mnt/sysimage/boot

Mount the device that contains the backup file.
mount –t fs_type path_to_device /mnt/sysimage/backup

Change the working directory to what will be the / filesystem.
cd /mnt/sysimage

Initiate the restore process
tar xvpfz backup/backup.tgz -C /mnt/sysimage

***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.
chroot /mnt/sysimage

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.
grub-install --root-directory=/ /dev/sda

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.

Bare Metal, Cloud, and Custom Dedicated Servers

Affordable Hosting Done Right

ServerPronto’s Dedicated Servers are the economical choice for providing an exclusive set of resources solely devoted to your IT needs. With our bare metal servers, you will benefit from:.

  • Transparent Pricing, Free Setup Assistance
  • 24/7 Customer Support and Hardware Replacement
  • 100% Uptime SLA, 7-day Money Back Guarantee
  • Full Root Access, Personalised Solutions
Build Your Server Contact an Advisor
about img

42,712

Provisioned Servers