From Mageia wiki
Jump to: navigation, search


Introduction

Since live USBs have become common many tools showed up out there. These tools, however, force certain criteria upon creating those USBs. Many of these criteria are limited, limiting or unsuitable for so many considerations. This page will try to explain how to create a Mageia Live USB by hand.

Problems of existing tools

  • Mostly sticking to FAT partitions
  • No flexible way to add more than one system
  • Compatibility with certain distros only
  • Majority are designed for M$ Windows
  • Lack of combined UEFI/BIOS duality

The Scenario

This page assumes the following:

  • The USB is >= 32GB (even though you may choose the capacity you need)
  • The USB is to boot several Linux distros, PC-BSD, MS Windows and a few other OS's (even though we will only talk about Mageia Linux here)
  • The USB is to boot on both BIOS and UEFI systems
  • You have already downloaded the ISOs you want to put on the pen-drive

Preparing your pen-drive

We will try to take a detailed step-by-step approach explaining the rationale for each so;

Partitioning the pen-drive

ALL DATA ON THE PEN-DRIVE WILL BE GONE Since we need the pendrive to boot on both BIOS and UEFI systems, we need to use the GPT scheme for partitioning. So we use parted; a partitioning tool found on most Linux distros. The partitions we are going to create for this purpose are as follows:

  1. Create a GPT Label on the pen-drive
  2. An NTFS formatted partition of ~15GiB for our daily use on different systems and label it MyData
  3. An EXT4 formatted partition of ~20GiB to hold the files of Mageia and label it Linux
  4. EFI System Partition (ESP) formated as FAT32 with 100MiB capacity with the flag set to boot and label it ESP
  5. A 1MiB UNFORMATED Partition with the flag set to bios_grub

Creating the NTFS partition first guarantees that M$ Windows is able to read and write to that partition in case we want to share files or install M$ Windows off the USB.

Note that the ESP partition above MUST BE either FAT16 or FAT12 for removable devices according to the standard

Copying Mageia onto the pen-drive

Now that we have our pen-drive partitioned, we are going to copy the Mageia file onto the USB. So AS root;

1. Mount the EXT4 Linux partition on your system, in my case;
# mount /dev/sdb2 /media/Linux -t ext4 -o rw
2. Create the folders needed for the Mageia Media you intend to use from the USB, in my case;
# mkdir -pv /media/Linux/Mageia/{X32,X64}/{Install,Live,Net}
3. Mount the "Mageia 4.1 Live DVD ISO" on /mnt
# mount  /PATH/TO/YOUR/ISO/Mageia-4.1-LiveDVD-KDE4-x86_64-DVD.iso /mnt
4. Copy the contents of the ISO onto the corresponding folder on the pen-drive
# cp -Rv /mnt/* /media/Linux/Mageia/X64/Live/
5. Unmount the ISO you have just copied
# umount /mnt
6. Repeat steps 3-5 for all the ISOs you intend to boot off the pen-drive each in the corresponding folder
7. Create soft links for the installation folders of the installation version;
# cd /media/Linux
# ln -s Mageia/X64/Install/x86_64
# ln -s Mageia/X32/Install/i586

Setting up GRUB2

Now we have all the Mageia Files under the Mageia folder on the pen-drive. All we need is to make the pen-drive bootable by setting up GRUB2 onto it. You might want to have Mageia installed in Virtual Box to do this trick. Otherwise; try to find two Mageia installations, one on a BIOS system and the other on UEFI. We need thes installation so that we can install both versions of GRUB2, UEFI and BIOS, onto the pen-drive. One last thing is to download modified versions of Mageia Live DVD's initrams so that we can boot the correct version of Live Mageia in the corresponding folder.

The modified initram files can be downloaded from: http://mtailounie.net/progs/mageialive.html.

Having downloaded the required files we procede as follows (STILL AS root):

1. Create the folders /boot/EFI in the Linux partition of the pen-drive:
# mkdir -pv /media/linux/boot/EFI
2. Copy the downloaded initram mga41init32 into /boot under Mageia folder
# cp -v /PATH/TO/DOWNLOADED/INITRAM/mga41init32 /media/Linux/Mageia/X32/Live/boot
3. Copy the downloaded initram mga41init64 into /boot under Mageia folder
# cp -v /PATH/TO/DOWNLOADED/INITRAM/mga41init64 /media/Linux/Mageia/X64/Live/boot
4. mount the ESP, EFI System Partition, of the pen-drive under /boot
# mount /dev/sdb3 /media/Linux/boot/EFI -t vfat -o rw
5. On a BIOS installation; install GRUB2 as follows:
# grub2-install --root-directory=/media/Linux /dev/sdb
6. On a UEFI installation; install GRUB2 as follows:
# grub2-install --root-directory=/media/Linux --efi-directory=/media/Linux/boot/EFI --removable /dev/sdb
7. Now copy the /boot/grub2 folders of your installation onto the pen-drive
# cp -vfR /boot/grub* /media/Linux/boot
8. Create the grub.cfg on the pen-drive
# touch /media/Linux/boot/grub2/grub.cfg

Write boot configuration to grub.cfg

Now we should set up the GRUB2 menu that will show up when we boot the computer from the USB. Please refer to the GRUB2 manual for configuration as I will just give an example of menu configuration here.

Note that the livepath MUST be the path to the distrib-lzma.sqfs file of Mageia Live Release

Open grub.cfg in your favourite text editor as root: The following configuration here is very basic so feel free to add or modify:

insmod part_gpt 
insmod ext2
set root='hd0,gpt2'
set timeout=27

submenu "Mageia 4.1" {
  menuentry "Mageia 4.1 Live 64-Bit" {
               if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  UUID_OF_GPT2_OF_THE_USB
               else
                  search --no-floppy --fs-uuid --set=root UUID_OF_GPT2_OF_THE_USB
               fi
        	linux /Mageia/X64/Live/boot/vmlinuz BOOT_IMAGE=linux livepath=/Mageia/X64/Live/loopback root=mgalive:LABEL=Linux splash quiet rd.luks=0 rd.lvm=0 rd.md=0 rd.dm=0   vga=788 
   	        initrd	/Mageia/X64/Live/boot/mga41init64
  }
 
  menuentry "Mageia 4.1 Live 32-Bit" {
               if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  UUID_OF_GPT2_OF_THE_USB
               else
                  search --no-floppy --fs-uuid --set=root UUID_OF_GPT2_OF_THE_USB
               fi
       	linux /Mageia/X32/Live/boot/vmlinuz BOOT_IMAGE=linux livepath=/Mageia/X32/Live/loopback root=mgalive:LABEL=Linux splash quiet rd.luks=0 rd.lvm=0 rd.md=0 rd.dm=0   vga=788 
   	        initrd	/Mageia/X32/Live/boot/mga41init32
  }
 
  menuentry "Mageia 4 Install 64-Bit" {
               if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  UUID_OF_GPT2_OF_THE_USB
               else
                  search --no-floppy --fs-uuid --set=root UUID_OF_GPT2_OF_THE_USB
               fi
       	linux /Mageia/X64/Install/isolinux/x86_64/vmlinuz automatic=method:disk,disk:sdb,partition:sdb2,directory:/Mageia/X64/Install/x86_64 vga=788 splash quiet
   	        initrd	/Mageia/X64/Install/isolinux/x86_64/all.rdz
  }

  menuentry "Mageia 4 Install 32-Bit" {
               if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  UUID_OF_GPT2_OF_THE_USB
               else
                  search --no-floppy --fs-uuid --set=root UUID_OF_GPT2_OF_THE_USB
               fi
       	linux /Mageia/X32/Install/isolinux/i586/vmlinuz automatic=method:disk,disk:sdb,partition:sdb2,directory:/Mageia/X32/Install/i586 vga=788 splash quiet
   	        initrd	/Mageia/X32/Install/isolinux/i586/all.rdz
  }
  menuentry "Mageia 4 Rescue 64-Bit" {
               if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  UUID_OF_GPT2_OF_THE_USB
               else
                  search --no-floppy --fs-uuid --set=root UUID_OF_GPT2_OF_THE_USB
               fi
       	linux /Mageia/X64/Install/isolinux/x86_64/vmlinuz automatic=method:disk,disk:sdb,partition:sdb2,directory:/Mageia/X64/Install/x86_64 rescue
   	        initrd	/Mageia/X64/Install/isolinux/x86_64/all.rdz
  }

  menuentry "Mageia 4 Rescue 32-Bit" {
               if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  UUID_OF_GPT2_OF_THE_USB
               else
                  search --no-floppy --fs-uuid --set=root UUID_OF_GPT2_OF_THE_USB
               fi
       	linux /Mageia/X32/Install/isolinux/i586/vmlinuz automatic=method:disk,disk:sdb,partition:sdb2,directory:/Mageia/X32/Install/i586 rescue
   	        initrd	/Mageia/X32/Install/isolinux/i586/all.rdz
  }
}

Please use blkid to get the UUID of your partition in order to set it up right in grub.cfg!

# blkid

Pen-drive ready

With that our pen-drive is set up to boot different Mageia flavours on both BIOS and UEFI systems.

Final comments

Probably this is not the best methos to do it but it works for me. I have other distros on the same partition, which is far bigger of course, as well as othe configurations for other OS's.

Installing from USB

READ THIS ONLY IF YOU USED THE INSTALL MENU OF THE USB..IF YOU USED THE LIVE MENU ENTRY TO INSTSALL THE SYSTEM YOU DO NOT NEED THIS! THIS METHOD CONTEMPLATES GRUB2 BOOT LOADER ONLY..YOU MIGHT NEED OTHER MODIFICATION IF YOU USED ANOTHER BOOT-LOADER

This USB includes a swap partition. That said; Mageia adds certain entries in various configuration files during the installation, which will lead to problems if booting with the USB disconnected from the computer. Follow these steps to fix this problem:

  1. Unplug the USB from the computer
  2. Start the computer to get to the boot menu (GRUB2 in my case)
  3. Plug in the USB to the computer
  4. After you log in; start a root terminal
  5. Use blkid to find out the UUID of your swap partition NOT THE ONE ON THE USB
  6. umount all the partitions of your USB
  7. Open /etc/default/grub as root
  8. Modify GRUB_CMDLINE_LINUX_DEFAULT so that resume=UUID=YOUR_LOCAL_DRIVE_SWAP_PARTITION_UUID_GOTTEN_FROM_BLKID
  9. Save and close the file
  10. Open /boot/grub2/grub.cfg, again as root
  11. Replace all occurences of the removable drive swap partition UUID with the correct one for your local drive
  12. Save and close
  13. Once again as root open /etc/dracut.conf.d/51-mageia-resume.conf
  14. Replace the UUID with the right one for your local swap partition
  15. Save and close
  16. One last time; open /etc/fstab as root
  17. Remove all references to any partition on your USB
  18. Save and close
  19. In the root terminal; issue the following commands:
  • cd /boot
  • swapoff -a
  • dracut -vH --xz --strip initrd-$(uname -r)-rev.img
  • mv -v initrd-$(uname -r).img initrd-$(uname -r).img.old
  • mv -v initrd-$(uname -r)-rev.img initrd-$(uname -r).img
  • mv -v initrd-desktop.img initrd-desktop.img.old
  • mv -v initrd.img initrd.img.old
  • ln -s initrd-$(uname -r)-rev.img initrd-desktop.img
  • ln -s initrd-$(uname -r)-rev.img initrd.img

Now you can unplug your USB and reboot your system :)

Why the modified initrams and are they trusty?

First of all the modified initrams are trusty and were only made to overcome some limitations of the default ones. They add the livepath kernel command-line option in order to boot Mageia from a specified folder, thus we do not need a different partition for each flavour. The other crucial addition is to boot Mageia from an EXT4 partition. Other modifications are underway and will be exposed as properly implemented.

Caveat

  • On some UEFI computers GRUB2 fails because of some alignment error. This is corrected by the if clause in grub.cfg above

I am investigating that on the Internet, but still all I could find was that it is a bug in GRUB. I suspect it has something to do with installing two versions of GRUB on the USB for BIOS and UEFI.

  • If you have some problem with GRUB set up, or you need secure boot, try installing it through other distro like Ubuntu.
  • The Mageia install boot options are giving me some trouble. But you can procede from GRUB2 shell just giving the same configuration through the shell.

Of course; you should know how to use the shell of GRUB2. Creating soft links on the root of the partition to x86_64 and i586 solved the problem *_*

  • Please make sure of the configuration you have as you follow this tutorial (device name, mount-points...etc.)
  • Make sure to mount the ESP partition under /boot/EFI before installing GRUB2 on UEFI systems.