Clef USB de maintenance
Cette documentation est basée sur les articles suivants :
- https://wiki.debian-fr.xyz/Installation_Debian_Stretch_avec_Debootstrap_et_chroot
- https://blog.sleeplessbeastie.eu/2015/12/07/how-to-create-bootable-usb-flash-drive/
- https://askubuntu.com/questions/95392/how-to-create-a-bootable-system-with-a-squashfs-root
- https://l3net.wordpress.com/2013/09/21/how-to-build-a-debian-livecd/
- https://forum.manjaro.org/t/this-live-system-image-failed-to-boot/39967/3
- https://wiki.archlinux.org/title/Multiboot_USB_drive
Procédure validée sur Xubuntu 24.04 et Debian 13.
Présentation du projet
Nous souhaitons créer une clef USB de maintenance permettant d'installer un système Debian et Xubuntu. Nous préparerons un installeur automatisé Debian, ainsi qu'un système de maintenance live contenant des utilitaires usuels.
Cette clef USB de maintenance sera capable de démarrer à la fois sur un BIOS ou un UEFI.
Nous allons utiliser une clef USB 3 de 32 Go. Nous considérerons qu'elle est connectée sur une machine Debian sur le disque /dev/sda.
Partitionnement
La clef USB doit comporter une table de partitions GPT. Nous allons partitionner notre clef USB comme suit avec GParted puis cfdisk pour définir les systèmes de fichiers de /dev/sda1 et /dev/sda2 :
| Volume | Sys. de fichiers | Taille (en Mo) | Usage |
|---|---|---|---|
| sda1 | Amorcage BIOS | 1 | Partition d'installation de GRUB |
| sda2 | FAT32 EFI | 1 024 | Partition EFI |
| sda3 | ext2 | 8 192 | Système de maintenance |
| sda4 | ext2 | 4 096 | Fichiers pour l'installeur Debian automatisé |
| sda5 | NTFS | 16 253 | Stockage de données |
Installation du système d'amorçage hybride
Exécuter les commandes suivantes sur gdisk pour activer le démarrage hybride :
> gdisk /dev/sda Command (? for help): r Recovery/transformation command (? for help): h WARNING! Hybrid MBRs are flaky and dangerous! If you decide not to use one, just hit the Enter key at the below prompt and your MBR partition table will be untouched. Type from one to three GPT partition numbers, separated by spaces, to be added to the hybrid MBR, in sequence: 1 2 3 Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N): N Creating entry for GPT partition #1 (MBR partition #1) Enter an MBR hex code (default EF): Set the bootable flag? (Y/N): N Creating entry for GPT partition #2 (MBR partition #2) Enter an MBR hex code (default EF): Set the bootable flag? (Y/N): N Creating entry for GPT partition #3 (MBR partition #3) Enter an MBR hex code (default 83): Set the bootable flag? (Y/N): Y Recovery/transformation command (? for help): x Expert command (? for help): h Expert command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): Y OK; writing new GUID partition table (GPT) to /dev/sda. The operation has completed successfully.
Monter la partition sda3 sur /mnt et la partition sda2 sur /mnt/boot/EFI :
mount /dev/sda3 /mnt mkdir -p /mnt/boot/EFI mount /dev/sda2 /mnt/boot/EFI
Installer GRUB version BIOS :
grub-install --target=i386-pc --recheck --boot-directory=/mnt/boot /dev/sda grub-install --target=i386-pc --recheck --force --boot-directory=/mnt/boot /dev/sda3
Installer GRUB version UEFI :
apt install grub-efi-amd64 grub-install --target=x86_64-efi --recheck --removable --efi-directory=/mnt/boot/EFI --boot-directory=/mnt/boot
Télécharger Memtest86+ :
apt -y install unzip wget -O /tmp/memtest.zip https://memtest.org/download/v7.20/mt86plus_7.20.binaries.zip unzip /tmp/memtest.zip -d /mnt/boot
Créer le fichier /mnt/boot/grub/grub.cfg :
insmod efi_gop
insmod efi_uga
menuentry "Systeme de maintenance" {
linux /live64/vmlinuz boot=live live-media-path=/live64 nomodeset
initrd /live64/initrd.img
}
menuentry "Installeur Debian bureautique" {
linux /iso/debian-xfce/linux quiet vga=788
initrd /iso/debian-xfce/initrd.gz
}
menuentry "Installeur Debian" {
linux /iso/debian-64/linux quiet vga=788
initrd /iso/debian-64/initrd.gz
}
menuentry "Depannage Debian" {
linux /iso/debian-64/linux quiet vga=788 rescue/enable=true
initrd /iso/debian-64/initrd.gz
}
menuentry "Live Xubuntu" {
set isofile="/iso/xubuntu-64.iso"
loopback loop $isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile locale=fr_FR bootkbd=fr console-setup/layoutcode=fr noprompt fsck.mode=skip quiet splash
initrd (loop)/casper/initrd
}
menuentry "Installeur Xubuntu" {
set isofile="/iso/xubuntu-64.iso"
loopback loop $isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile locale=fr_FR bootkbd=fr console-setup/layoutcode=fr noprompt fsck.mode=skip only-ubiquity quiet splash
initrd (loop)/casper/initrd
}
menuentry "Installeur Xubuntu OEM" {
set isofile="/iso/xubuntu-64.iso"
loopback loop $isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile locale=fr_FR bootkbd=fr console-setup/layoutcode=fr noprompt fsck.mode=skip only-ubiquity oem-config/enable=true quiet splash
initrd (loop)/casper/initrd
}
grub_platform
if [ "$grub_platform" = "efi" ]
then
menuentry "Configuration UEFI" {
fwsetup
}
menuentry "Memtest86+ 64 bits" {
linux16 /boot/memtest64.efi
}
else
menuentry "Memtest86+ 64 bits" {
linux16 /boot/memtest64.bin
}
fi
Création du système de maintenance
Reportez-vous à l'article sur la création d'images système live pour la création du système client.Avant l'empaquetage des images systèmes, ajouter un point de montage pour la partition de stockage dans /etc/fstab :
UUID=<UUID de sda5> /media/donnees ntfs defaults 0 2
Placer les fichiers du système live (initrd.img, vmlinuz et filesystem.squashfs) dans le répertoire /mnt/live64.
Installation de l'ISO Xubuntu
Télécharger la dernière version LTS de l'ISO Xubuntu 64 bits minimale depuis un miroir Xubuntu :
mkdir -p /mnt/iso/ wget -O /mnt/iso/xubuntu-64.iso http://ftp.free.fr/mirrors/ftp.xubuntu.com/releases/24.04/release/xubuntu-24.04.3-minimal-amd64.iso
Installation des installeurs Debian
Télécharger la derniere version de l'installeur Debian netinstall :
mkdir -p /mnt/iso/debian-64 wget -O /mnt/iso/debian-64/linux http://ftp.fr.debian.org/debian/dists/stable/main/installer-amd64/current/images/netboot/debian-installer/amd64/linux wget -O /mnt/iso/debian-64/initrd.gz http://ftp.fr.debian.org/debian/dists/stable/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz
Création d'un installeur Debian automatisé
Vous pouvez créer un installeur automatisé de Debian permettant le déploiement d'un environnement de bureau Xfce avec les utilitaires usuels. Personnalisez la configuration et les fichiers chargés à votre guise pour l'adapter à vos besoins. Notre répertoire de travail sera /tmp
Nous allons fournir à l'installeur Debian un fichier preseed qui décrit les paramètres de l'installeur Debian. Créer le fichier /tmp/preseed.cfg :
d-i debian-installer/locale string fr_FR.UTF-8
d-i keyboard-configuration/xkb-keymap select fr(latin9)
d-i netcfg/choose_interface select auto
d-i netcfg/get_domain string unassigned-domain
d-i hw-detect/load_firmware boolean true
d-i mirror/http/proxy string
d-i mirror/country string FR
d-i mirror/http/hostname string deb.debian.org
d-i mirror/https/hostname string deb.debian.org
d-i mirror/http/mirror select deb.debian.org
d-i mirror/https/mirror select deb.debian.org
choose-mirror-bin mirror/http/hostname string deb.debian.org
choose-mirror-bin mirror/http/mirror select deb.debian.org
d-i mirror/http/directory string /debian
d-i clock-setup/utc boolean true
d-i time/zone string Europe/Paris
d-i apt-setup/cdrom/set-first boolean false
d-i apt-setup/use_mirror boolean true
d-i apt-setup/non-free boolean true
d-i apt-setup/contrib boolean true
popularity-contest popularity-contest/participate boolean false
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i passwd/root-login boolean false
d-i partman-auto/method string regular
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
tasksel tasksel/first multiselect standard
d-i pkgsel/include string openssh-server xfce4 lightdm terminator dmz-cursor-theme numix-gtk-theme papirus-icon-theme xfce4-whiskermenu-plugin qt5ct adwaita-qt qt5-gtk-platformtheme xdg-desktop-portal-gtk webp-pixbuf-loader gnome-software system-config-printer blueman xfce4-screenshooter xfce4-power-manager xfce4-power-manager-plugins network-manager-gnome firmware-linux-nonfree gnome-package-updater xfce4-mailwatch-plugin gvfs gvfs-fuse gvfs-backends firefox-esr firefox-esr-l10n-fr thunderbird thunderbird-l10n-fr libreoffice libreoffice-l10n-fr libreoffice-gtk3 sound-juicer brasero rhythmbox vlc kdenlive cheese mc krusader kate gimp shotwell cups printer-driver-all ttf-mscorefonts-installer libdvd-pkg keepassxc grsync hplip mousepad mate-calc catfish engrampa kdiff3 krename atril simple-scan ristretto wesnoth pokerth kblocks kbreakout kdiamond kmahjongg kmines kpat kshisen gnome-sudoku 0ad
#d-i finish-install/reboot_in_progress note
d-i preseed/late_command string \
user=$(grep 1000 /target/etc/passwd | cut -d: -f1); \
wget -O /target/tmp/tw.deb https://download.teamviewer.com/download/linux/teamviewer_amd64.deb; \
in-target apt -y install /tmp/tw.deb; \
mkdir /install; \
mount /dev/disk/by-uuid/<UUID de sda4> /install; \
cp -RT /install/target /target; \
cp -RT /target/etc/skel /target/home/${user}; \
in-target chown -R 1000:1000 /home/${user}; \
in-target update-alternatives --set x-cursor-theme /usr/share/icons/DMZ-White/cursor.theme; \
sed -ie "s/^GRUB_TIMEOUT=.*/GRUB_TIMEOUT=0/g" /target/etc/default/grub; \
sed -ie "s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"quiet splash\"/g" /target/etc/default/grub; \
sed -ie "s/^#*autologin-user=.*/autologin-user=${user}/g" /target/etc/lightdm/lightdm.conf; \
echo "QT_QPA_PLATFORMTHEME=qt5ct" > /etc/environment; \
in-target update-grub; \
in-target rm /etc/alternatives/desktop-background; \
in-target ln -s "/usr/share/images/desktop-base/Castilla Sky.jpg" /etc/alternatives/desktop-background; \
in-target apt -y remove light-locker;
Dans cet exemple, le fichier preseed effectuera les opérations suivantes à la fin de l'installation (champ preseed/late_command) :
- Installer Teamviewer
- Copier le contenu du dossier target situé dans la partition /dev/sda4 dans l'arborescence du système installé
- Copier le squelette de répertoire personnel dans le dossier utilisateur paramétré
- Effectuer quelques modifications cosmétiques (thème du curseur, écran de démarrage, suppression du menu de démarrage GRUB, définition du fond d'écran par défaut, définition du gestionnaire de thème Qt)
- Activer la connexion automatique de l'utilisateur
Un exemple de preseed avec des informations supplémentaires est disponible sur le site Debian : https://www.debian.org/releases/stable/example-preseed.txt
Un exemple d'arborescence à copier dans le dossier target situé dans la partition /dev/sda4 est disponible ici : https://antoinepernot.fr/data/debian-target.tgz
Télécharger le fichier initrd.gz dans votre répertoire de travail. Le décompresser et y intégrer le fichier pressed avant de le recompresser.
cd /tmp wget -O /tmp/initrd.gz http://ftp.fr.debian.org/debian/dists/stable/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz gunzip /tmp/initrd.gz echo preseed.cfg | cpio -H newc -o -A -F initrd gzip initrd
Copier le fichier initrd.gz dans le répertoire cible et télécharger le noyau.
mkdir -p /mnt/iso/debian-xfce cp /tmp/initrd.gz /mnt/iso/debian-xfce/initrd.gz wget -O /mnt/iso/debian-xfce/linux http://ftp.fr.debian.org/debian/dists/stable/main/installer-amd64/current/images/netboot/debian-installer/amd64/linux