Autres langues English ; français ; |
Résumé : Depuis que les clés USB sont devenues courantes, de nombreux outils sont apparus sur le marché. Cependant, ces outils imposent certains critères à la création de ces clés USB. Nombre de ces critères sont limités, contraignants ou inadaptés à de nombreuses situations. Cette page tentera d’expliquer comment créer une clé USB autonome Mageia pas à pas. |
Contents
Problèmes des outils existants
- La plupart du temps, ils prenent uniquement en compte des partitions FAT
- Aucune possibilité d'ajouter des systèmes supplémentaires
- Compatibilité seulement avec certaines distributions
- La plupart sont conçus pour les systèmes Windows
- Absence de dualité combinée UEFI/BIOS.
La trame
Cette page suppose ce qui suit :
- La clé USB est ≥ 32 Go (bien que vous puissiez choisir la capacité dont vous avez besoin)
- La clé USB doit permettre de démarrer plusieurs distributions Linux, PC-BSD, MS Windows et quelques autres SE (même si nous parlerons ici uniquement de Mageia).
- La clé USB doit démarrer à la fois sur les systèmes BIOS et UEFI.
- Vous avez déjà téléchargé les ISO que vous voulez mettre sur la clé USB.
Préparation de la clé USB
Nous essaierons d’adopter une approche détaillée, étape par étape, expliquant la raison d’être de chacune d’entre elles.
Partitionnement de la clé USB
TOUTES LES DONNÉES SUR LA CLÉ USB SERONT SUPPRIMÉES
Comme nous avons besoin de la clé USB pour démarrer sur les deux systèmes BIOS et UEFI, nous devons utiliser le schéma GPT pour le partitionnement.
- un outil de partitionnement que l'on trouve sur la plupart des distributions Linux. Les partitions que nous allons créer à cette fin sont les suivantes
- Créer un label GPT sur la clé USB
- Une partition formatée en NTFS de ~15 GiB pour notre usage quotidien sur différents systèmes et l'étiqueter MesDonnées.
- Une partition formatée en EXT4 de ~20 GiB pour contenir les fichiers de Mageia et l'étiqueter Linux.
- Une partition système EFI (ESP) formatée en FAT32 avec une capacité de 100 Mio, avec le drapeau "boot" et l'étiquette "ESP".
- Une partition de 1MiB UNFORMATED avec le drapeau bios_grub.
La création de la partition NTFS garantit d'abord que Microsoft Windows est capable de lire et d'écrire sur cette partition au cas où nous voudrions partager des fichiers ou installer Microsoft Windows hors de la clé USB.
Notez que la partition ESP ci-dessus DOIT être soit FAT16 soit FAT12 pour les dispositifs amovibles selon la norme
Copier Mageia sur la clé USB
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
Mise en place de 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 VirtualBox 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
Ecrire la configuration de démarrage sur 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
- Notes by Yves DEMUR (ydemur) 2020/05/17
- For rescue boot :
- the "install" directories ared copied from the installation iso
- the only needed files are isolinux/${arch}/{vmlinuz,all.rdz},install/stage2{VERSION,rescue.sqfs}
- while booting you may be prompted to choose the partition containing "rescue.sqfs" and type the path to the i586 or x86_64 directory (containing "install/stage2/...") or their parent
- For Mageia7.1Live (and maybe some previous ones) :
- (reference = /usr/lib/dracut/modules.d/90mgalive/mgalive-root.sh from the dracut package)
- change "livepath=/Mageia/X64/Live/loopback" to "mgalive.basedir=/Mageia/X64/Live"
- change "livepath=/Mageia/X32/Live/loopback" to "mgalive.basedir=/Mageia/X32/Live"
- The mgalive.basedir MUST be the path to the directory containing the "loopbacks" directory (which contains the "distrib.sqfs" file of Mageia Live Release) the default for mgalive.basedir is "" (void)
- While running the Live
- the partition containing "${mgalive.basedir}/loopbacks/distrib.sqfs" will not bee seen nor be mountable, because it is mounted on "/live/media" before the pivot_root
- "distrib.sqfs" is mounted ro on "/run/mgalive/ovlsize" unionfs with "/" rw
- For live boot the only needed files are boot/{vmlinuz,initrd.img},loopbacks/distrib.sqfs
- Notes by Yves DEMUR (ydemur) 2020/05/17
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
La clé USB est opérationnelle
With that our pen-drive is set up to boot different Mageia flavours on both BIOS and UEFI systems.
Remarques finales
Ce n'est probablement pas la meilleure méthode pour le faire, mais elle fonctionne pour moi. J'ai d'autres distributions sur la même partition, qui est bien sûr beaucoup plus grande, ainsi que d'autres configurations pour d'autres SE.
Installation à partir de l'USB
READ THIS ONLY IF YOU USED THE INSTALL MENU OF THE USB..IF YOU USED THE LIVE MENU ENTRY TO INSTALL 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:
- Unplug the USB from the computer
- Start the computer to get to the boot menu (GRUB2 in my case)
- Plug in the USB to the computer
- After you log in; start a root terminal
Use blkid to find out the UUID of your swap partition NOT THE ONE ON THE USB- umount all the partitions of your USB
Open /etc/default/grub as rootModify GRUB_CMDLINE_LINUX_DEFAULT so that resume=UUID=YOUR_LOCAL_DRIVE_SWAP_PARTITION_UUID_GOTTEN_FROM_BLKIDSave and close the fileOpen /boot/grub2/grub.cfg, again as rootReplace all occurences of the removable drive swap partition UUID with the correct one for your local driveSave and closeOnce again as root open /etc/dracut.conf.d/51-mageia-resume.confReplace the UUID with the right one for your local swap partitionSave and close- One last time; open /etc/fstab as root
- Remove all references to any partition on your USB
- Save and close
- 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.oldmv -v initrd.img initrd.img.oldln -s initrd-$(uname -r)-rev.img initrd-desktop.imgln -s initrd-$(uname -r)-rev.img initrd.img
Now you can unplug your USB and reboot your system :)
Pourquoi modifier les initrams et sont-ils fiables ?
Tout d’abord, les initrams modifiés sont fidèles et ont été conçus uniquement pour surmonter certaines limitations des initrams par défaut. Ils ajoutent l’option de ligne de commande du noyau livepath afin de démarrer Mageia à partir d’un dossier spécifié, ainsi nous n’avons pas besoin d’une partition différente pour chaque version. L’autre ajout crucial est de démarrer Mageia à partir d’une partition EXT4. D’autres modifications sont en cours et seront présentées lorsque elles sont correctement mises en œuvre.
Mise en garde
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.