Thursday, March 29, 2018

How To Backup And Restore Partitions From Multi-boot UEFI Linux PC

Now that the author has a multi-boot UEFI Linux PC (see here), it is only logical that backup/restore of the various partitions on the PC needs to be found and installed.

After searching the Internet for a suitable candidate, the author finally found one - 'partclone' (here and here) - which supports almost all file systems, especially those file system used by the author's multi-boot Linux PC. For your information, the file system supported are ext2, ext3, ext4, hfs+, reiserfs, xfs, jfs, ntfs, fat(12/16/32), exfat, etc (the author is NOT sure whether 'partclone' support APFS - Apple File System, a new type of file system based on HFS+). If you have a hankering for exotic file systems on your PC, then you should consider 'partclone' as part of your arsenal of tools.

The Web site on 'partclone' mentioned above, contains all the relevant information on using it - however, most detail DOES NOT apply in the case of our multi-boot Linux PC. This 'how-to' was written to address that issue - just follow the steps given below.
  1. Boot up the multi-boot Linux PC using a suitable Live Linux distribution using a USB disk by inserting the USB boot disk into a working USB port of the PC and power it on.


    NOTE: Any Live Linux distribution with 'sudo' access will do, but avoid the ones with non-live distribution and use one that can install 'partclone' software - try to avoid using any flavors of Ubuntu or Debian - they simply would NOT work without having to download the 'tar.gz' file using a Web browser. The author used a Linux Mint 18 MATE USB disk to boot up the PC and used 'apt' to install the 'partclone' utility.


    Press the Boot Menu key (F12 for Gigabyte motherboard, F8 for ASUS motherboard, etc.) after you hear the POST beep and the boot menu should appear. Position the cursor or highlight to the USB disk with the 'UEFI' at the beginning of its name. Then press the 'Enter' key and the PC will boot up from the USB disk.

    After a while, the Linux Mint GRUB menu will appear. Make sure that the highlighted cursor is on the 'Start Linux Mint 18.3 MATE 64-bit' - move it using the keyboard if not. Then press the 'Enter' key and wait for the MATE desktop to appear.

  2. Open a terminal (there is an icon in the panel that you can use) on the PC, and install 'partclone' on the PC by executing:

      sudo apt install partclone

    Press the 'Enter' key when prompted and wait for the installation to finish. The screen will look something like the figure below.


  3. Then execute:

      sudo lsblk

    A possible layout may look like the one as shown in the figure below.


    The command will list all the disks on your multi-boot Linux PC - note the names of the disks ('dev/sdXN' where X is the name of the disk and N is the name of the partition). I will assume that you have followed the author's 'how-to' and the files on the PC are as per the 'how-to'. Should you deviate from the 'how-to', then its up to you to identify the name of the disks on the PC.

    From the figure, please note that the disk '/dev/sdd' present in the list, is the device (in this case a USB disk) is used by the author to boot up the PC - ignore this disk. Also, ignore the 'loop0' entry.

    The disks for the backup/restore process is listed in the figure as '/dev/sda' (Linux Mint MATE), '/dev/sdb' (Debian Linux Cinnamon), and '/dev/sdc' (Manjaro Gnome).

  4. Now on your PC, connect the disk (via USB, TH, etc) that you will use as the source or target of your backup files. Dismiss the file manager window, if one appears. Then execute:

      sudo lsblk

    This will allow you to identify the disk you have just inserted - make a note of the device and the device number. Note that the PC will mount the disk under the '/media/mint/<name-of-disk>'. This is, of course, assuming the disk is 'LINUX-DATA' (see figure below).



    NOTE: If you are using a new backup disk (whether a mechanical HDD or a solid-state SSD), then I suggest using the ext4 journaling file system and a directory system in the form of '/backup/<pc-name>' (replace '<pc-name>' with the name of the actual PC to make things easier to identify in future (my PC's name is 'merlin'). However, you are free to choose a file system and a directory naming system.


  5. If you are performing a backup of the ESP partition (fat32 file system) then execute:

      sudo partclone.fat32 -c -s /dev/sda1 -o /media/mint/LINUX-DATA/backup/merlin/esp.pcl

    Note that the whole command is on one line. Also note that the command given above is 'complete' and can be used as is - this is, of course, assuming that you have followed the 'how-to' faithfully. If not, replace the disk '/dev/sda1' with the ESP partition and the name of the ESP backup file with the file name that you wish to use.

    If you are performing a backup of any of the Linux file system (ext4 file system) then execute:

      sudo partclone.ext4 -c -s /dev/sdXN -o /media/mint/LINUX-DATA/backup/merlin/<backup-file-name>.pcl

    Again note that the whole command is on one line.

    Replace 'sdXN' with the actual device and number as noted in (2) above, 'merlin' with the actual name of your PC (assuming that you have followed the naming conventions that I suggest), and '<backup-file-name>' with the actual name of the Linux distribution (e.g. 'debian' for the Debian Linux distribution).

    An explanation of the various command options: First the software uses 'partclone' with the extension related to the filesystem we are interested in, ext4 and fat32. Then we provided the -c option which let us specify that the action we want to do is to create a backup. The -s option let us specify the source we want to backup (in this case, 'dev/sda1' or 'dev/sdXN'). Finally the -o option, short for --output, tells 'partclone' where we want to store the backup file. Notice that the .pcl extension here is completely arbitrary - use it for convenience.

    The process of backup of the PC is as shown in the figures below.


  6. If you are performing a restore of the ESP partition (fat32 file system) then execute:

      sudo partclone.fat32 -r -s /media/mint/LINUX-DATA/backup/merlin/esp.pcl -o /dev/sda1

    If you are performing a restore of any of the Linux file system (ext4 file system) then execute:

      sudo partclone.ext4 -r -s /media/mint/LINUX-DATA/backup/merlin/<backup-file-name>.pcl -o /dev/sdXN

    Replace 'sdXN' with the actual device and number as noted in (2) above, 'merlin' with the actual name of your PC (assuming that you have followed the naming conventions that I suggest), and '<backup-file-name>' with the actual name of the Linux distribution (e.g. 'debian' for the Debian Linux distribution).

    An explanation of the various command options: This time we use the -r option (short for --restore), and inverted the arguments we used before. The argument earlier used for the -o option, this time represent our source, therefore we used it as the argument for the -s option. What before was the source of the backup, our partition, this time represents our destination, since we want to restore the backup.

  7. Wait for the backup/restore process to finish. That's it - the process of backup/restore is completed and you can now perform a verify using the file manager (see below).


    If you want to use the Linux Mint for something else, go ahead, but first unmount the backup disk (unless you plan to use that disk for other purpose). When finished, you can now shut down the PC, and store the backup disk in a safe place.
Note that you have NOT mounted any disk on your PC, as per a requirement of 'partclone' - however, you have mounted your backup/restore disk. Also note that if you want to overwrite an existing backup file, you MUST specify the -O <backup-file-name> (or --overwrite <backup-file-name>) as an option to the commands above. For information on other options that you can specify, see the 'man' page on 'partclone'.

Enjoy!

No comments:

Post a Comment