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!

Tuesday, March 20, 2018

Multi-Booting Several UEFI Linux Distributions On Different Disks

This 'how-to' is all about setting up a modern UEFI PC for installing Mint Linux, Debian Linux, and Manjaro Linux (according to Distrowatch, three of the most downloaded Linux distributions) on different hard disks, be it a mechanical disk (HDD), or a new Solid-State (SDD) disk. Just be aware that this 'how-to' was also designed specifically for Linux OS and Unified Extensible Firmware Interface (UEFI). Why? you may ask; as a guide for Linux experimenters! the author will answer.

This is a very long 'how-to', so be forewarned that it may take time to read through, and an even longer time to implement the multi-booting of the Linux distributions mentioned. Read through the 'how-to' FIRST, then go implement it.


NOTE: This 'how-to' was prepared sometimes in 2017 and as such Distrowatch listed Linux Mint, Debian Linux and Ubuntu Linux as the three downloaded Linux distributions. Manjaro Linux was NOT even in the list for the top three. However this 'how-to' will install Manjaro Linux along with Linux Mint and Debian Linux - keep reading and just follow the steps in this 'how-to'.


According to Wikipedia, multi-booting is the act of installing multiple operating systems on a computer, and being able to choose which one to boot. On the other hand, the term dual-booting refers to the common configuration of specifically two operating systems, normally a Windows OS and a Linux OS. This seems to be the most popular UEFI PC system, mainly because it involves the most popular OS in the world - the Windows OS.

This 'how-to' was tested on the following hardware and found to be working:
  • Gigabyte GA-Z79-HD3 Motherboard
  • Intel Core i5-4590 CPU (3.3 GHz)
  • Kingston 16 Gb DDR3 HyperX RAM
  • Nvidia GTX 750 Ti PCI-E Graphics Card

A Word About UEFI

One more thing before we proceed to the 'how-to' and this concerns the firmware (the software used to control low-level tasks) on most modern motherboards.

Basically there are two types of firmware: one is the old-style type BIOS (Basic Input/Output System) and the other is the new EFI or UEFI ((Unified) Extensible Firmware Interface). In this 'how-to', the terms EFI and UEFI are used interchangeably - both means (and refer to) the same thing.

While most of us old fogeys are familiar with the BIOS-type firmware, the computer industry, as a whole, is heading towards the UEFI-type firmware. So it very important for computer enthusiast like me, to fully understand UEFI. Allow me to emphasize that UEFI is relatively new, as compared to the older BIOS, and has several quirks, which in time will be worked out.

There are a lot of documents and articles on UEFI found on the web - but they seems to have one goal in mind: confuse the hell out of the computer enthusiast - and they all have succeeded beautifully. However, I recommend that any computer enthusiast worth his/her salt, do some research and get to understand UEFI. Anyway, the method outlined in this 'how-to' is based on a UEFI PC (which is a PC with a new UEFI firmware), which the reader must possess beforehand.


NOTE: Most of the information on UEFI and EFI comes from the manufacturers themselves - the rest came from reading the Roderick W. Smith's web site at here.


Make sure that the Linux distribution you want installed is UEFI compatible. This is very important as installing a non-UEFI Linux will result in having a system with both UEFI and BIOS based Linux - something that I would recommend to avoid at all cost, as this would result in boot problems later on. Check with the manufacturer's Web site if you are unsure about the Linux's UEFI capabilities.


NOTE: The firmware of the PC used here was set for UEFI operation only. If there is Compatibility Support Module (CSM) features in the firmware, disable it. We are NOT using CSM in this 'how-to' - so if you do have legacy BIOS compatibility, solve them before proceeding with the rest of this 'how-to'.


DO NOT MULTI-BOOT THE LINUX DISTRIBUTIONS WHICH CONFLICTS WITH EACH OTHER. This warning is especially for multi-booting Linux Mint (except Linux Mint Debian Edition 2) and any flavors of Ubuntu - it's a bad idea to do so since these two has not solved the problem of using the 'ubuntu' name as the EFI boot directory name - i.e, both of them uses the same name - as a result, the files in this directory will be overwritten without any warning during installation. So be forewarned. Consult the Web for any articles and issues on the Linux distributions that you want to multi-boot.

Assumptions

This 'how-to' also makes several assumptions:
  1. You have disabled Secure Boot (a Microsoft invention) in your firmware of the target PC as this 'how-to' is mainly for Linux.

  2. You have several large enough blank (unformatted) disks (HDD's or SDD's) to fit all the Linux OS'es you plan to install, and you have the disks to be used, installed on the target PC for partitioning and formatting.

  3. You have downloaded (using a working PC) the Linux distributions that you plan to use with the multi-boot system and either burn them to a CD/DVD or create a bootable USB/SD/MicroSD drive (henceforth called a USB drive), which you will use to install the distributions.


    NOTE: Consult the Linux distributions web site to determine the best way of creating the USB bootable USB drive. DO NOT USE ANY OTHER METHODS EXCEPT THAT RECOMMENDED BY THE LINUX DISTRIBUTION THEMSELVES.

  4. You plan to use either a USB boot disk or a CD/DVD drive to UEFI boot a suitable Linux Live distribution (such as Ubuntu) on the target PC. The Linux Live distribution has the 'gdisk' and 'mkfs' utilities installed on it. Use the command 'which gdisk' and 'which mkfs' in a terminal to check for presence or absence of these utilities - install them if they are not already installed.
By the way, the author used a Ubuntu Linux 17.10 USB boot disk to capture the screenshots and to partition the target disks. Therefore, this 'how-to' will be based (in the beginning) on using that Linux to boot, partition the disks, and then format the partitions. However, you are free to choose which Linux to use initially - just make sure that you use a Live Linux distribution.


STEP 1: Booting Up the Target PC Using the USB Boot Disk


NOTE: If you are using the Ubuntu CD/DVD to boot the PC, skip this step and go to STEP 2.

  1. Insert the Ubuntu Linux 17.10 USB boot disk into a working USB port of the target PC and power it on.

  2. 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.

  3. Position the cursor or highlight to the USB disk with the 'UEFI' as part of its name - usually at the beginning. Then press the 'Enter' key and the PC will boot up from the USB disk.

  4. The Ubuntu GRUB menu will appear. The first item 'Try Ubuntu without installing' is already selected, so just press the 'Enter' key and the PC will start loading the Ubuntu desktop. Then skip the following STEP 2 and got to STEP 3 directly.

STEP 2: Booting Up the Target PC Using the CD/DVD

To boot up a CD or DVD (in the PC's optical drive) in a UEFI mode, you need to perform some steps as follows:
  1. Power up the target PC and then press the Boot Menu key (F12 for Gigabyte motherboard, F8 for ASUS motherboard, etc) after hearing the POST beep.

  2. Open the tray for the optical drive and insert the CD or DVD into the optical drive and close the tray - wait until the optical drive LED has stopped flashing.

  3. Press the PC's reset key (or do a Ctrl-Alt-Del on the PC). Then press the Boot Menu key again after hearing the POST beep.

  4. Position the cursor or highlight to the USB disk with the 'UEFI' as part of its name - usually at the beginning. Then press the 'Enter' key and the PC will boot up from the optical disk.

  5. The Ubuntu GRUB menu will appear, with the first item 'Try Ubuntu without installing' is already selected. So just press the 'Enter' key and the PC will start loading the Ubuntu desktop.

STEP 3: Prepare the Partitions on the Disk

When the Ubuntu desktop appears, open a terminal to execute a command for verifying you really have booted in UEFI mode. Note that you MUST perform this task before you can use the instructions in this 'how-to'. The command is:

  [ -d /sys/firmware/efi ] && echo UEFI || echo BIOS

On an UEFI-based PC the output will be 'UEFI' (see the screenshot below). The result on a BIOS-based PC, though, should be 'BIOS'. If you have booted up in BIOS mode, then I suggest you check the firmware settings before you proceed any further.

Note that the command shown above, checks for the presence of the '/sys/firmware/efi' directory - which is ALWAYS present if the PC was booted up in UEFI mode.

To get more details on the EFI firmware used, you can execute:

  sudo dmesg | grep EFI

The output to the commands above is as shown in the figure below (your PC may display a different output, depending on the Linux OS and hardware installed on the PC).


Then perform the following steps:
  1. In the terminal, execute the following command:

      sudo lsblk

    This would list all the disk on your PC (see figure below). From this list, you will be able to determine the proper device name. If you are using the target PC, the proper device name is most likely '/dev/sda'. Note that the disk for the Linux distribution is '/dev/sdb', and '/dev/sdc'. Please also note that the disks '/dev/sdd' present in the list below, is the device (in this case a USB disk) is used by the author to boot up the PC. Also, ignore the loop0 entry.


    Note that the listing was taken using the author's target PC with a unformatted Samsung 850 EVO 500GB SDD which will be used to store all the EFI System Partition (ESP) and the swap partitions for the Linux distributions that you plan to be installed, plus the first Linux distribution (Mint Linux). It was evident from the listing that the correct device name for this SDD is '/dev/sda'.

  2. Then execute the following command:

      sudo gdisk /dev/sda

    The 'gdisk' utility will start and you will see a screen similar to the one shown in the figure below. Note the message in the prompt '(? for help)' - so if you are lost, you can press the '?' key for help anytime. Notice the 'q' command in the 'help' list - this allows you to quit 'gdisk' at any time before anything is committed to the disk. It could be a lifesaver for you if you make a mistake during the process of creating partitions on the disk - you can quit 'gdisk' and start all over.



    NOTE: If you see a warning message like the one shown in the figure below, it is most likely that you are using a disk with an existing MBR partition table.


    You can now choose between 2 alternative actions:

    • If you are unsure that the disk is NOT completely blank and may contain data that you want to be saved, then exit disk by typing 'q' (the disk will remain unchanged in this case), and then check the disk for any contents and save it if so desired. Then restart 'gdisk' once more and follow the instructions below.

    • If you are SURE that the disk is completely blank and the warning message was shown because an MBR type partition exists for a prior installation (i.e, the disk was used previously), then press the 'w' (write) key, followed by the 'Enter' key. Then press the 'Y', followed by the 'Enter' key to confirm, and 'gdisk' will convert the MBR partition table to a GPT partition table and exit as shown in the figure below.


    Restart 'gdisk' once more and you will not get the warning message anymore.

    Please DO NOT USE Microsoft's 'diskpart' utility program to partition the disk - if you must use this program, then use this only to 'clean' the disk, and 'convert to MBR' format and let 'gdisk' to convert it to GPT as outlined above. Note that Microsoft insists on converting any GPT disk to their own format of EFI partition.

  3. The disk does not contain any partitions at the moment, and to confirm this, type 'p', followed by the 'Enter' key. The screen will change as shown below - notice the information displayed on the disk, plus the fact that it does not have any partitions configured yet.


  4. The disk for UEFI system requires an EFI System Partition (ESP) formatted as FAT32. The size of this special partition is between 100 to 500 MiB (Mega-Binary-Bytes - Google it for more information). This partition must also have it's 'boot flag' set and the 'gdisk' utility internal code set to 0xEF00 (hexadecimal). Note that the 'boot flag' will be set during the installation of a Linux distribution.

    Follow the steps given below to create the ESP partition:

    a) Type the command 'n' (new) and 'Enter'.

    b) You will be prompted to enter the new partition number - note that the default is 1, so just press the 'Enter' key.

    c) Next, you will be prompted to enter the first sector number - note that the default is given, so just press the 'Enter' key.


    NOTE: The 'gdisk' (and the older 'fdisk' utility) uses sector numbers to define the start and end of partitions - why this is so can be summed up in one word: compatibility - older systems used it so why not newer system? Apart for the confusion that this raise, my thoughts on this issue is that we ought to get rid of this sector numbering once and for all and move to a system where newer, large-sized disks dictate what ought to be used.

    d) Next, you will be prompted to enter the last sector number for the partition - the default is the last sector on the disk - which is what you DON'T want. You NEED a partition size of between 100 to 500 MiB - we will use 400 MiB as an example. Referring to the 'man' (manual) pages of 'gdisk', you will find it is possible to specify this sector relative to the end of the last sector specified by preceding the number by a '+' - in effect the 'size' of the wanted sector. For this 'how-to', the ESP's size is around 400 MiB - so we typed '+400M' and the 'Enter' key.

    e) Next, you will see the default type of partition you just created - a 'Linux filesystem' - which is NOT the type wanted. You want to create an EFI System Partition (ESP) and the correct code for it is 0xEF00. You need to type 'L', 'Enter' to list all the valid type codes. At the prompt for the hex code, enter 'ef00' followed by the 'Enter' key. The display will then confirm that you have changed the type of partition to 'EFI System'. You will now be back at the main prompt. Then type 'p', 'Enter' to check what you have done so far. The final screen will look something like this:


    Note that:

      * you have created partition 1
      * the size of the partition is 400 MiB
      * the code of the partition is hex EF00
      * the partition name (type name) is 'EFI System'

    This confirms exactly what you wanted.

  5. The next partition that will be created is the Linux swap partition. Follow the steps given below to create this (only the main command is given from now on - it is understood that each command will be followed by the 'Enter' key):

    a) Type 'n' for a new partition.

    b) Type 'Enter' to accept the default partition number 2.

    c) Type 'Enter' to accept the default second sector number.

    d) Type the required size of the swap partition - this should be equal to the target PC's RAM size - we will use 16 GiB in this 'how-to'; so we will type '+16G'.

    e) Type '8200' for the hex code of the swap partition.

    f) Type 'p' to display what you have done so far (see figure below).


  6. Next, you will create the actual first Linux partition; i.e, the partitions on which the Linux system (in this case the Mint Linux) will reside. Follow the steps given below:

    a) Type 'n' for a new partition.

    b) Type 'Enter' to accept the default partition number.

    c) Type 'Enter' to accept the default third sector number.

    d) Type the required size of the Linux partition. If the whole disk is to be used for the Linux system, the just press 'Enter' to accept the default last sector number.

    e) Type 'Enter' to accept the default partition type - which happened to be the correct 'Linux file system'.

    f) Type 'p' to display what you have done so far (see figure below).


  7. Should you make a mistake (e.g, specifying a wrong size for the swap partition), you can easily correct this by first deleting the partition (by using the d command and specifying which partition to delete) and start over to create a new partition. Note that the disk will remain unaffected - nothing will be written to the disk until you specifically execute the 'w' (write) command.

  8. Now that we have created all the ESP, swap and Linux file system partitions, all that remained to be done is to write these partition information to the disk. Type 'w', 'Enter', 'Y', 'Enter' again to confirm and you are done. The utility gdisk's work is done and it will automatically close (see below).


  9. To create more Linux partitions on your other disks, execute 'sudo gdisk /dev/sdN' again (where 'sdN' is the name of the disk for the Linux system). Then repeat steps 6(a) to (f) and (7) above for this disk. Note that the first disk (sda) will contain the ESP and swap partitions and the Linux file system occupies the rest of the disk. YOU NEED NOT CREATE ANOTHER ESP AND SWAP for the PC. If you wish, you can make the Linux file system occupy the whole disk for the rest of the other disks. A possible configuration is as shown in the figure below.


STEP 4: Format the Partitions on the disks

Remember that, although we have partitioned the disks properly, it is NOT formatted with the proper file system yet. To do this we need to invoke the 'mkfs' (make file system) utility as follows:
  1. For the first ESP file system, we require to format that partition as FAT32. To do this, execute the following command from the terminal:

  2.   sudo mkfs.vfat -F32 /dev/sda1

  3. For the second swap partition, we will use the 'mkswap' utility and execute:

  4.   sudo mkswap /dev/sda2

  5. For the Linux file system partitions, we can use the 'mkfs' utility to carry out this process. We assume that the ext4 file system is to be used in this 'how-to' - should you decide otherwise and use other types of file systems, consult the Web for the proper formatting commands to use. To format the partitions, we execute (one by one) the following command:

      sudo mkfs.ext4 /dev/sda3
      sudo mkfs.ext4 /dev/sdN1
      sudo mkfs.ext4 /dev/sdN1


    Note that 'sda3', 'sdN1', and 'sdN1' are the name of the partitions for the Linux system to be installed. Take care that you enter the partitions correctly - the partitions on the first drive (sda) already contain the ESP and the swap partition - hence it was specified as the third partition (sda3).

    The final screen will look like the figure shown below:


    Close the terminal when done.


  6. NOTE: The reason why we chose the partition layout as described above can be summed up as follows:

    a) The EFI System Partition (ESP) size, type, and position makes it easy to identify.

    b) The swap partition can be used by the various Linux distributions (i.e, it is common to all Linux distributions) since each Linux will only be used one at a time. We have the added benefit, using this scheme, of avoiding having to create one swap partition for each Linux distribution.

    c) If you leave some free (or unallocated) space at the END of the disk, you can easily accommodate other OS at a later stage.

    A lot of my professional colleagues and friends often ask me why I want to create the partitions first on the disk before installing the various Linux distributions. Why not let the installer for the various Linux distributions handle the creation of those partitions? Well, the answer is simple and can be summed up in one word - control.

    Creating the partitions first on the disk before installing the various Linux distributions allows me to:

    • control the size and location of the ESP

    • control the size and location of the swap partition. Note most Linux installers just create a partition based on the size of the RAM (which is acceptable) but put the location as the third partition - which makes it difficult (but not impossible) to resize the main root partition at a later date.

    • control the size, file system type and location of the main root partition

    With the size, file system type and location of each partition within my control, I would be able to make changes to each of them easily at a later date without having to worry about affecting the others.


STEP 5: Installing the First Linux Distribution – Linux Mint MATE 18.3

Power down (switch off) the PC and remove the Ubuntu 17.10 USB boot drive. Then follow the steps below.


NOTE: If you are using a CD/DVD to boot the PC, skip (1) and go to (2).

  1. If you are using a Linux Mint MATE 18.3 bootable USB drive, insert the install media into a USB port and power up the PC. Press the Boot Menu key (F12 for Gigabyte motherboard, F8 for ASUS motherboard, etc) after hearing the POST beep and the boot menu will appear on-screen.

    Move the highlight (using the mouse or keyboard) to the UEFI entry for the PC's USB drive and press the 'Enter' key. The PC will boot up and the GRUB menu for the Linux distribution will now appear. If you are using a bootable USB drive to boot up the PC, skip (2) below and proceed to (3).

  2. To boot up a Linux Mint MATE 18.3 CD or DVD (in the PC's optical drive) in a UEFI mode, you need to perform some steps. First power up the target PC and then press the Boot Menu key (F12 for Gigabyte motherboard, F8 for ASUS motherboard, etc) after hearing the POST beep.

    Then open the tray for the optical drive and insert the CD or DVD into the optical drive and close the tray - wait until the optical drive LED has stopped flashing.

    Press the PC's reset key (or do a Ctrl-Alt-Del on the PC), then press the Boot Menu key again after hearing the POST beep.

    Move the highlight (using the mouse or keyboard) to the UEFI entry for the PC's optical drive and press the 'Enter' key. The PC will now boot up and the GRUB menu for the Linux distribution will appear.

  3. The GRUB menu that you see on-screen differs for each Linux distribution. Some will allow you to try the distribution before committing it to the hard disk. Some will only allow you to install it to the disk without trying it first. Regardless of which Linux distribution it is, it has one purpose only - install it to the hard disk.
How you install the Linux distribution is highly subjective so it will not be covered in detail with this 'how-to', except to mention the disk partitioning part. Remember that we already have prepared each partition on the disk beforehand - so when you arrive at the point when you have to select the disk on which you want to install the Linux distribution, you have to select 'Something else'. DO NOT SELECT 'AUTOMATIC INSTALL' OR 'INSTALL ON FREE SPACE' OR 'INSTALL BESIDES...' OR 'ERASE DISK AND INSTALL...'.

The author will now use the steps below used in installing a Linux Mint as an example of installing the first Linux distribution on the disk. In this example, the author has also decided to use the 'ext4' file system.

Of course, this will differ if you decide to install a different flavor of Linux and file system; but the important thing is that you can use the steps shown below as a guide to install the Linux. The author have included lots of screenshots with the instructions that you can use as a guide.
  1. Consult the Internet for instructions to install Linux Mint MATE 18.3 Linux. If unsure, read the on-line manual here.

  2. When you arrive at partitioning the disk, move the highlight to the last item, 'Something else' (see figure below), and click the 'Continue' button.


  3. You will see a screen similar to that shown below. Notice that all the partitions that were created previously, are now listed. Three of these, the ESP, swap and the Linux file system, has been identified as shown. Further down on the screen, you will find the 'Device for boot loader installation' item. Do not change anything here.


  4. Click the mouse to the first partition (the ESP) as shown below. Then click on the 'Change...' button.


  5. You will see a screen similar to below. There is nothing more to be done here, so click on 'Cancel' to dismiss this window.


  6. Click on the next partition - the Linux swap partition, as shown in the figure below. Then click on the 'Change...' button.


  7. The next screen (shown below) indicates that everything has been set up properly - just click on 'Cancel' to dismiss the window.


  8. On the next screen, move the highlight to the next partition - the Linux file system - and click on the 'Change...' button. The next screen will appear (see below). Click on the 'Use as:' item, which, at the moment, is displaying 'do not use the partition'. Then click on the down arrow button to the right.


  9. On the drop-down screen, click on the 'Ext4 journaling file system'. This action will be confirmed on the next screen (see below) where the former 'do not use' has changed to 'Ext4 journaling file system'. A 'Mount point' window will now appear. Then click on the down arrow button to the right and select the root file system '/' for Linux Mint. This action will be confirmed on the next screen where the blank mount point has changed to '/'. Then click on the 'OK' button to dismiss the window.


  10. Remember that we have formatted the ESP, swap, and Linux file system partitions previously, so there is no need to format them again. However, there is no harm in formatting the ext4 file system partition - all you have to do is to place a tick mark in the proper place for the 'Format?' column (see below).


  11. Then click on the 'Install now' button. A window will appear as shown in the figure below. Then click on the 'Continue' button if you are sure.


  12. Continue from this point onwards to finish installing Linux Mint.
Once you have completed installing the first Linux distribution, re-start the PC while removing the USB boot drive. If everything proved to be successful, you will see the main Linux Mint MATE desktop login screen. You may have to wait a while for this login screen to appear - so be patient. Should you have problems, then seek help from the Internet.

You can now use the new Linux Mint MATE 18.3 to perform post-install stuff on it. Let me point out that this is a workable Linux system and it behaves like any other Linux system - despite it being part of a multi-boot system - which we describe next.


STEP 6: Installing the Second Linux Distribution – Debian Linux 9.3

You can use the same steps as given above to install the second of the Linux distributions. Usually, the Linux distribution will have a menu item or desktop icon where you can install it to a disk - use that for the installation. Should that fail, consult the Internet for instructions on how to install that Linux distribution to the disk.

Remember that we already have prepared the ESP and swap beforehand - so when you arrive at the point when you have to select the disk on which you want to install the Linux distribution, you have to select 'Manual'. DO NOT SELECT ANY ITEM THAT STARTS WITH 'GUIDED...'. Then follow the steps given below:
  1. When you arrive at 'Partition disks' screen, the highlighted cursor will be resting on the 'Guided - use the largest continuous free space'. Click on the last item, 'Manual', and click the 'Continue' button.


  2. The highlighted cursor will be resting on the 'Guided partitioning'. Click on the disk labeled as 'sdb' on the partition labeled as '#1' (MAKE SURE YOU SELECT THE CORRECT DISK!) on which you would the Linux OS to be installed. Then press the 'Enter' key. (Note that if you have NOT formatted the disk it will show the full size (in GB) and have a 'FREE SPACE' label on it.)


  3. The screen as shown in the figure below will appear. Click on the 'Use as:' and select 'Ext4 journaling file system' item from the drop-down list that appears next. This will be confirmed in the 'Use as:' item where the label will now change to 'Ext4 journaling file system'.




  4. Click on the 'Format the partition:' and this will be confirmed in the label will now change to 'yes, format it'.



  5. Click on the 'Mount point:' item, press the 'Enter' key, then select the '/' (root) from the drop-down list that appears next. This will be confirmed in the label will now change to '/'. Do not change any other items on the screen. Then click on the 'Done setting up the partition' item.




  6. The 'Partition disks' screen will re-appear. Note that the partition on which you want the Linux OS to be installed, will be formatted, as indicated by the 'F' on that line.


  7. Click on the 'Finish partitioning and write changes to disk'. Then, click on the 'Continue' button. Next a confirmation screen will appear - select 'Yes' if you are sure - then click on the 'Continue' button.



  8. Continue to finish installing Debian Linux 9.3, then restart the PC. You now have a dual-boot Linux PC!


STEP 7: Installing the Third Linux Distribution – Manjaro Linux Gnome 17.1.6

While this 'how-to' describes the installation of a third Linux distribution, you are free to decide whether you will employ the third disk as a data disk or another Linux distribution. The installation of a third Linux distribution is only for illustrative purpose - you can ignore it if you wish. If you wish to install a third Linux distribution, then follow the steps given below:
  1. We already have prepared the ESP and swap previously - so when you arrive at the point when you have to select the disk on which you want to install the Manjaro Linux distribution, you have to select 'Manual partitioning' for a manual install of the Linux distribution. Note that the left side of the screen is indicating 'Partitions' item (see below). DO NOT SELECT 'INSTALL ALONGSIDE' OR 'REPLACE A PARTITION' OR 'ERASE DISK'. Do not change anything else on the screen and click on the 'Next' button.


  2. You will see the screen as shown below. Click on the ESP partition (if not already there), and then click on the 'Edit' button.


  3. You will then see a screen similar to the one shown below. Select the 'Keep' button on the 'Content:' item. Click on the down arrow of the 'Mount Point:' and select the '/boot/efi' directory from the list. Make sure that the 'boot' and 'esp' is selected for the 'Flags:' item. Then click on the 'OK' button. The screen as shown below will reappear.


  4. From the 'Storage device:' item, click on the down arrow and select the disk for the Manjaro Linux - '/dev/sdc' in this case. The screen will change to the one shown below. Select the partition 'sdc1' (if it is not already selected), then click on the 'Edit' button.


  5. The screen will change to the one shown below. Select the 'Format' button of the 'Content:' item. Click on the down arrow of the 'Mount Point:' and select the '/' (root) directory from the list. Make sure that nothing is selected in the 'Flags:' item. Then click on the 'OK' button.


  6. The screen as shown below will reappear. Note that the disk on which you wish to install Manjaro Linux has the root sign ('/') in it. Then click the 'Next' button, and continue to finish installing Manjaro Linux, then restart the PC. You now have a multi-boot Linux PC!


Although only three Linux distributions were installed in this 'how-to', it illustrates the steps to set up a multi-boot Linux system. You can expand the same steps to include other Linux distributions, provided you do have enough disk space to spare. Even if you do run out of disk space on the disk, you can install the Linux distribution on another hard disk - just make sure that you have enough free space in your EFI System Partition (ESP) - 400 MiB should be enough, 500 MiB is even better.

After installing all the Linux distributions in this 'how-to', it was noticed that which Linux distribution's GRUB menu appears at boot-up depends on the LAST Linux that was installed. In our example above, the Mint GRUB menu appeared first because it was installed first and it was the only GRUB menu on the PC. However, when Debian Linux was installed, the GRUB menu that appeared after boot-up, was Debian's GRUB menu, with Mint Linux listed on it. Similarly, after Manjaro Linux was installed, the GRUB menu that appeared after boot-up contained Mint, Debian, and Manjaro.

At this stage, it was possible to select either Mint, or Debian, or Manjaro for booting, indicating that the Linux distributions has configured configured the GRUB menu correctly.


STEP 8: Using And Managing The UEFI Partition

On a Linux PC which was booted-up in UEFI mode (see STEP 3 at the beginning to determine how the PC was booted-up), there exists the 'efibootmgr' utility for managing the UEFI partition. Check if this utility is installed on the PC by starting a terminal and executing:

  which efibootmgr

If the 'efibootmgr' is currently installed, the output should show the path of the directory in which it was installed (see below - this is from the Debian Linux distribution). Else, use the terminal to install it by executing:

  sudo apt install efibootmgr

To check, execute the 'which efibootmgr' command again.


By the way, the 'efibootmgr' utility program can be used to manage UEFI and how it interacts with the PC. It can be used to set the boot order, delete an unwanted EFI entry, create a new EFI entry, and other EFI related stuff. For usage details, refer to the man page for 'efibootmgr'.

Now log in as the administrator (which the 'efibootmgr' requires) or if you are the administrator of the PC, preface every command shown with 'sudo', and execute:

  sudo efibootmgr -v

The output is as shown below - for the time being, ignore the Windows entry - this is solely for the author's PC and is used to boot the Windows 10 partition on a separate HDD. Note that if you execute 'sudo efibootmgr' without the '-v' option (which stands for verbose) you will get only the shortened display output - i.e., without the additional information such as the disk, disk type, UUID and the boot-loader file.


The three Linux distributions installed are listed as 'ubuntu' (which despite the ubuntu name, contains the boot files for Linux Mint 18.3 MATE), 'debian' and 'Manjaro' (BootOrder: 0002,0000,0001). In addition, a 'Windows Boot Manager' (which you can safely ignore) and an item labeled simply as 'UEFI OS' were also listed. The item labeled as 'UEFI OS' (BootOrder: 008A) illustrates the 'quirk' for the UEFI system, as explained later. The thing to note is the 'BootCurrent' item - it tells you which UEFI Linux's GRUB menu will be shown upon start-up - in this case the Manjaro GRUB menu (BootOrder: 0002).

Another thing to note from the output, is the disk from which the PC is booted. Notice that the list contains the first disk (1), the type of disk (GPT), plus the Universal Unique Identifier or UUID number of the disk, and the file from which the PC is booted from. Apart from the 'Windows Boot Manager' (BootOrder: 0088), the disk is the same - which is the ESP partition. However, the boot-loader files (listed at the end) are different. It does indicate which boot-loader files were used to boot-up the PC.

If you try to boot from the 'UEFI OS' (BootOrder: 008A) item (using the PC's Boot Menu), you will get the same GRUB menu as the other 'Manjaro' item. The reason for this is another 'quirk' of the UEFI system - the system will boot up with the file in /EFI/BOOT (BOOTX64.EFI), which is termed as the 'fallback' boot file, and use the boot order as stated.

Note that Linux Mint 18.3 MATE insists on using the 'ubuntu' directory name (because of the same ancestry?) for their distribution. All the EFI files for Linux Mint are placed in the same directory as Ubuntu Linux - crazy but true! This lead to the Linux Mint GRUB menu (NOT the Ubuntu GRUB menu) being displayed if selected using the PC's Boot Menu. However, the menu will allow you to select Linux Mint, Debian Linux or Manjaro Linux for use. This is the reason for the warning about not installing a Linux distribution that conflicts with each other! It makes things more difficult, especially when removing the Linux distribution.

The best way to verify this to mount the EFI directory and check the files and directories present there. Use the mount directory /mnt, although you are free to choose any name and position of that directory. Then mount the EFI partition as shown below. Then use the 'ls -la' command to display the contents of /mnt/tmp directory and the contents of the /mnt/tmp/EFI directory. Concentrate on the three directories, which are named 'ubuntu', 'debian' and 'Manjaro' (see below).


The structure of the EFI directory mandates that each Linux distribution have a separate directory in which the boot files are stored - obviously Linux Mint 18.3 MATE has NOT met this criteria - why this is so is anybody guess.

The files in each directory are listed in the figures below - do not remove or edit those files - the PC will be rendered unbootable if so. Remember to unmount the EFI partition when you have finished exploring (see the figure below).



STEP 9: Deleting and Adding a Linux Distribution

When I first started to write this 'how-to', I first installed an Ubuntu 16.04.3 Linux distribution in error. Later on, when I realized my error, I decided to delete the whole distribution from the PC, and replace it with a Linux Mint 18.3 MATE distribution. Here are the steps I took on a Debian Linux:
  1. Open a terminal and switch to the root account by executing:

      su -

  2. Mount the ESP partition using the command:

      mount /dev/sda1 /mnt

  3. Change to the EFI folder and list the contents of the EFI folder using the commands:

      cd /mnt/EFI
      ls -la


  4. From the listing, identify the Linux distribution to be deleted, then execute the command:

      rm -r <linux-distro>

    Replace <linux-distro> with the name of the actual Linux distribution to be deleted, and the all files for that Linux distribution will disappear from the ESP.

  5. Change back to the root home and unmount the /mnt directory using the commands:

      cd ~
      umount /mnt


  6. Now execute the command in the terminal:

      efibootmgr

    The output will display all the Linux distributions on your PC. Identify the one you have deleted and use the command:

      efibootmgr -b <linux-distro> -B

    Replace <linux-distro> with the name of the actual Linux distribution. This will delete the entry. Then exit the terminal.

  7. Then restart your PC and press the boot key and select the Linux you want to boot from. Note that the Linux distribution which you have just deleted will no longer be listed in the boot menu.

  8. The GRUB menu will appear for the Linux distribution you booted with the Linux which you have just deleted still being listed. Just leave it there for the time being - just remember that you can no longer boot from it as it has been deleted.

  9. Remember that, although you have deleted the Linux distribution from the ESP, the actual files for the Linux still exist on the disk. You can remove it by reformatting the whole disk (two tasks for the price of one!). Open a terminal and execute:

      su -
      mkfs.ext4 /dev/sdNN


    Replace sdNN with the actual partition number, and the Linux files will disappear. Just be careful to specify the correct partition number - use the command:

      lsblk

    if you are not sure about the partition number. Close the terminal when done.

  10. Now you can install the new Linux distribution to replace the old one - reboot at the end of the installation, and you will find that this distribution will be listed in the GRUB menu in place of the old one. However, if you don't want to replace the old Linux distribution, you have to execute: update-grub on both your existing Linux distributions. This will get rid of the old Linux distribution from being listed on either of the two existing GRUB menus. Close the terminal when done.

Closing Words

To reiterate, multi-booting is the act of installing multiple operating systems on a computer and being able to choose which one to boot. After going through the above process, you now have successfully installed a Linux Multi-Boot PC and you can now choose which Linux to boot at startup.

It has been a wild ride while this 'how-to' was being written and learning about the PC, and UEFI at the same time; but it was worth it; warts and all. I have learned about UEFI and how to avoid pitfalls when experimenting with it - especially booting up a new UEFI installation. I also have learned that UEFI, being a relatively 'new' concept, still has it's problems and people are still coming up with brand new and innovative solutions to these problems. As mentioned previously, there are many reference materials available on the Web and here I would like a express my appreciation to the authors of those materials - especially Roderick W. Smith - without whom this 'how-to' would not be possible.

Comments and feedback are most welcome. Enjoy!