Introduction
Voici la présentation d’une installation automatisée par la méthode preseed et utilisant simple-cdd. Après plus de 300 tests, j’ai trouvé un moyen de le faire. J’ai été obligé de farfouiller dans le code de partman.
Il est nécessaire d’utiliser early_command et late_command pour pouvoir le faire (surtout late_command).
L’installateur Debian n’est aps très bon, voir mauvais pour faire une installation de ce type. IL y a aussi potentiellement desz bugs et/ou manquement dans partman.
Désolé pour tous les commentaires du fichier de preseed, c’est poru pouvoir facilement faire le lien avec les commandes debconf (tirées pour beaucoup de:
https://preseed.debian.net/debian-preseed/
Installation preseed RAID1
L’objectif est d’obtenir une machine avec LVM en RAID1 et /boot/efi
en RAID1, afin d’obtenir le partitionnement suivant:
$ lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1 linux_raid_member 0.90.0 2a9fb963-f1f3-ad17-00ba-7c8e7cfca707
│ └─md0 vfat FAT32 2109-648D 561,8M 1% /boot/efi
└─sda2 linux_raid_member 1.2 dsrvtest03:1 c1db43a1-9ab5-f1aa-140c-530dbd6d0cf8
└─md1 LVM2_member LVM2 001 cRmqNd-LGR3-wdR2-gfh2-nm4N-bl65-v1jl1m
├─vg01-swap swap 1 4e4ab8b2-9cbc-4a55-b969-6b70117f92a6 [SWAP]
├─vg01-boot ext4 1.0 BOOT 87b0c702-9a46-41c5-95d5-fd820722d476 144,6M 28% /boot
├─vg01-root ext4 1.0 ROOT a27d36a9-2aa7-484d-8462-d9d286585a06 9,5G 19% /
├─vg01-home ext4 1.0 HOME 18f4dfdb-2f20-4982-916f-55d1ad6f8295 4,7G 0% /home
├─vg01-var ext4 1.0 VAR 020017f9-521b-44d6-af05-16d4f2f1e54f 11,5G 3% /var
├─vg01-var_log ext4 1.0 LOG 998b472c-8f5a-4256-8a60-0150cad222f3 4,7G 1% /var/log
├─vg01-var_log_audit ext4 1.0 AUDIT 83e31036-f5e2-40f9-855a-c697d453ca3c 4,7G 0% /var/log/audit
├─vg01-var_tmp ext4 1.0 VARTMP 59f5110c-b78f-4061-9fb1-501d5e712625 2,3G 0% /var/tmp
└─vg01-tmp ext4 1.0 TMP f5a14152-ee7c-4cd8-b9c5-3c89d0f5e0ca 2,3G 0% /tmp
sdb
├─sdb1 linux_raid_member 0.90.0 2a9fb963-f1f3-ad17-00ba-7c8e7cfca707
│ └─md0 vfat FAT32 2109-648D 561,8M 1% /boot/efi
└─sdb2 linux_raid_member 1.2 dsrvtest03:1 c1db43a1-9ab5-f1aa-140c-530dbd6d0cf8
└─md1 LVM2_member LVM2 001 cRmqNd-LGR3-wdR2-gfh2-nm4N-bl65-v1jl1m
├─vg01-swap swap 1 4e4ab8b2-9cbc-4a55-b969-6b70117f92a6 [SWAP]
├─vg01-boot ext4 1.0 BOOT 87b0c702-9a46-41c5-95d5-fd820722d476 144,6M 28% /boot
├─vg01-root ext4 1.0 ROOT a27d36a9-2aa7-484d-8462-d9d286585a06 9,5G 19% /
├─vg01-home ext4 1.0 HOME 18f4dfdb-2f20-4982-916f-55d1ad6f8295 4,7G 0% /home
├─vg01-var ext4 1.0 VAR 020017f9-521b-44d6-af05-16d4f2f1e54f 11,5G 3% /var
├─vg01-var_log ext4 1.0 LOG 998b472c-8f5a-4256-8a60-0150cad222f3 4,7G 1% /var/log
├─vg01-var_log_audit ext4 1.0 AUDIT 83e31036-f5e2-40f9-855a-c697d453ca3c 4,7G 0% /var/log/audit
├─vg01-var_tmp ext4 1.0 VARTMP 59f5110c-b78f-4061-9fb1-501d5e712625 2,3G 0% /var/tmp
└─vg01-tmp ext4 1.0 TMP f5a14152-ee7c-4cd8-b9c5-3c89d0f5e0ca 2,3G 0% /tmp
C’est une installation sans GUI.
Partitionnement:
Pour le preseed, la partie la plus importante ici est le partitionnement, dont voici les éléments spécifiques au raid.
Préparation avec early_command
En premier lieu, préparer les disques avec la commande d-i partman/early_command
:
d-i partman/early_command string \
anna-install localechooser fdisk-udeb parted-udeb disk-detect cryptsetup-udeb hw-detect && logger "Preseed anna-install done"; \
interface=`ip -o link show | grep -Eio '2\:\s+.*\:\s+' | cut -d ' ' -f 2| cut -d ':' -f 1`; \
debconf-set netcfg/choose_interface select ${interface} && logger "Preseed interface selected done";
sfdisk --delete /dev/sda && logger "Preseed sfdisk /dev/sda delete done"; \
sfdisk --delete /dev/sdb && logger "Preseed sfdisk /dev/sdb delete done";
- Tout d’abord, installer les packages udeb nécessaires.
- Puis sélectionner l’interface réseau. ici l’objectif est de sélectionner systématiquement l’interface filaire, pour éviter la difficulté de configurer le Wifi, notamment du fait des firmwares.
- enfin; supprimer les partitions des deux disques utilisés pour le RAID1 avec sfdisk
Partitionnement
Dans la partie de partitionnement, on va dire à l’installateur de ne pas prendre en compte ni /boot
, ni EFI
. Ceux-ci seront traités spécifiquement plus tard avec la commande d-i partman/late_command.
De la même façon, on va dire à l’installateur qu’il ne doit pas installer le bootloader, présenté dans les chapitres suivants.
Supprimer tout ce qui est relatif à /boot et uefi:
Les deux commandes suivantes vont empêcher l’installateur de prendre en compte tout ce qui est relatif à /boot et uefi dna sle cadre du partitionnement:
### Description: Force UEFI installation?
# This machine's firmware has started the installer in UEFI mode but
# it looks like there may be existing operating systems already
# installed using "BIOS compatibility mode". If you
# continue to install Debian in UEFI mode, it mig/dev/nvme0n1p1ht be difficult to
# reboot the machine into any BIOS-mode operating systems later.
# .
# If you wish to install in UEFI mode and don't care about
# keeping the ability to boot one of the existing systems, you have the
# option to force that here. If you wish to keep the option to boot an
# existing operating system, you should choose NOT to force UEFI
# installation here.
d-i partman-efi/non_efi_system boolean false
### Description: Go back to the menu and resume partitioning?
# No EFI partition was found.
d-i partman-efi/no_efi boolean false
Indiquer les partitions RAID
Via partman-auto-raid, on indique les partition raid à créer:
### Description: for internal use; can be preseeded
# RAID recipe for automated install/boot/efi
d-i partman-auto-raid/recipe string \
1 2 0 vfat /boot/efi \
/dev/sda1#/dev/sdb1 \
# \
--metadata=0 \
. \
1 2 0 lvm - \
/dev/sda2#/dev/sdb2 \
.
Pour pouvoir utiliser une partition /boot/efi en RAID1 il faut impérativement que les metatada soient inférieur ou égal à la version 1.0.
malheureusement, partman ne prend pas en compte les version mineures. Donc soit l’option est 0 pour 0.90 soit c’est 1 pour 1.2.
De plus la structure d’une entrée est la suivante:
<raidtype> <devcount> <sparecount> <fstype> <mountpoint> <devices> <sparedevices> <args>
-
<raidtype>
: Niveau de RAID: 1 pour RAID1, c’est un champ numérique. Correspond à la valeur de l’option --level de mdadm -
<devcount>
: Nombre de devices: 2 pour RAID1, c’est un champ numérique correspond à la commande --raid-devices de mdadm -
<sparecount>
: Nombre de disques de spare: 0 pour RAID1, c’est un champ numérique, correspond à l’option --spare-devices de mdadm -
<fstype>
: Filesystem de la partition RAID: lvm pour la partition lvm, vfat pour la partition /boot/efi. -
<mountpoint>
: Point de montage de la partition RAID: /boot/efi pour /dev/md0, pas de point de montage pour la partition LVM bien évidement. -
<devices>
: Liste des devices. Cette liste est constitué des disques séparés par #. -
<sparedevices>
: Idem mais pour les disques de spare. ATTENTION: pour pouvoir mettre des arguments supplémentaires, il faut toujours avoir ce champ rempli. Dans le cas d’un RAID sans disques de spare, il suffit de mettre un # seul. C’est important pour pouvoir spécifier le paramètre metadata pour /dev/md0 de /boot/efi -
<args>
: Les arguments suppémentaires qui correspondent à des options mdadm séparées par #. POur notre RAID1, la partition /dev/md0 utilisera: --metadata=0. IL ne peut pas y avoir d’argument d’option contenant un point car c’est un séparateur de liste (ici de recipes) pour partman.
Définir les partitions
Il faut ensuite créer la « recette » (appelée recipe) avec la commande d-i partman-auto/expert_recipe string
.
On va donc avoir:
Deux définition des partitions raid pour signifier leur taille et leur type (primary pour la partie /boot/efi et non primary pour LVM):
600 512 620 raid \
$lvmignore{ } \
$primary{ } \
method{ raid } \
. \
20000 30 100% raid \
$lvmignore{ } \
method{ raid } \
.\
puis la définition de toutes les partitions LVM (swap, /boot, /, /home, /var, /var/tmp, /var/log, /var/log/audit, /tmp).
Ce qui nous donne pour finir la recette suivante (nommée multiraid):
d-i partman-auto/expert_recipe string \
multiraid :: \
600 512 620 raid \
$lvmignore{ } \
$primary{ } \
method{ raid } \
. \
20000 30 100% raid \
$lvmignore{ } \
method{ raid } \
.\
300% 2048 8000 linux-swap \
$defaultignore{ } \
$lvmok{ } lv_name{ swap } \
method{ swap } format{ } \
. \
256 512 320 ext4 \
$defaultignore{ } \
$lvmok{ } lv_name{ boot } \
method{ lvm } format{ } \
use_filesystem{ } filesystem{ ext4 } \
label{ BOOT } \
mountpoint{ /boot } \
. \
10000 2260000 100000 ext4 \
$defaultignore{ } \
$lvmok{ } lv_name{ root } \
method{ lvm } format{ } \
use_filesystem{ } filesystem{ ext4 } \
label{ ROOT } \
mountpoint{ / } \
options/relatime{ relatime } \
options/errors{ errors=remount-ro } \
. \
4000 904000 25000 ext4 \
$defaultignore{ } \
$lvmok{ } lv_name{ home } \
method{ lvm } format{ } \
use_filesystem{ } filesystem{ ext4 } \
label{ HOME } \
mountpoint{ /home } \
options/relatime{ relatime } \
options/nodev{ nodev } \
options/nosuid{ nosuid } \
. \
10000 2260000 100000 ext4 \
$defaultignore{ } \
$lvmok{ } lv_name{ var } \
method{ lvm } format{ } \
use_filesystem{ } filesystem{ ext4 } \
label{ VAR } \
mountpoint{ /var } \
options/relatime{ relatime } \
options/nodev{ nodev } \
options/nosuid{ nosuid } \
. \
4000 904000 25000 ext4 \
$defaultignore{ } \
$lvmok{ } lv_name{ var_log } \
method{ lvm } format{ } \
use_filesystem{ } filesystem{ ext4 } \
label{ LOG } \
mountpoint{ /var/log } \
options/relatime{ relatime } \
options/nodev{ nodev } \
options/nosuid{ nosuid } \
options/noexec{ noexec } \
. \
4000 904000 25000 ext4 \
$defaultignore{ } \
$lvmok{ } lv_name{ var_log_audit } \
imethod{ lvm } format{ } \
use_filesystem{ } filesystem{ ext4 } \
label{ AUDIT } \
mountpoint{ /var/log/audit } \
options/relatime{ relatime } \
options/nodev{ nodev } \
options/nosuid{ nosuid } \
options/noexec{ noexec } \
. \
2000 452000 8000 ext4 \
$defaultignore{ } \
$lvmok{ } lv_name{ var_tmp } \
method{ lvm } format{ } \
use_filesystem{ } filesystem{ ext4 } \
label{ VARTMP } \
mountpoint{ /var/tmp } \
options/relatime{ relatime } \
options/nodev{ nodev } \
options/nosuid{ nosui/boot/efi d } \
options/noexec{ noexec } \
. \
2000 452000 8000 ext4 \
$defaultignore{ } \
$lvmok{ } lv_name{ tmp } \
method{ lvm } format{ } \
use_filesystem{ } filesystem{ ext4 } \
label{ TMP } \
mountpoint{ /tmp } \
options/relatime{ relatime } \
options/nodev{ nodev } \
options/nosuid{ nosuid } \
. \
1 1 -1 ext4 \
$defaultignore{ } \
$lvmok{ } lv_name{ todelete } \
method{ lvm } format{ } \
.
La dernière partition, nommée todelete, a pour but de ré"cuperer toute la place non utilisée par les autres partition, et ainsi éviter que la dernière n’hérite de cet espace. Elle sera supprimée ensuite.
En effet, le partitionnement ci-dessus est conçu pour des disques de 40Go à 1To mais avec une limitation d’utilisation de l’espace LVM à 300Go environ, laissant les 700Go restant disponible pour étendre les volumes logiques.
les calculs ont été fait manuellement en se basant sur l’algorithme de partman qui détermine la taille de création des partitions. Voici l’algorithme:
6. HOW THE ACTUAL PARTITION SIZES ARE COMPUTED
----------------------------------------------
Suppose we have to create N partitions and min[i], max[i] and
priority[i] are the minimal size, the maximal size and the priority of
the partition #i as described in section 1.
Let free_space be the size of the free space to partition.
Then do the following:
for(i=1;i<=N;i++) {
factor[i] = priority[i] - min[i];
}
ready = FALSE;
while (! ready) {
minsum = min[1] + min[2] + ... + min[N];
factsum = factor[1] + factor[2] + ... + factor[N];
ready = TRUE;
for(i=1;i<=N;i++) {
x = min[i] + (free_space - minsum) * factor[i] / factsum;
if (x > max[i])
x = max[i];
if (x != min[i]) {
ready = FALSE;
min[i] = x;
}
}
}
Then min[i] will be the size of partition #i.
Toutes les autres options sont des classiques ensuite.
Le bootloader
L’installateur de Debian n’est pas capable de faire un RAID1 sur /boot/efi, il est donc nécessaire de le faire « manuellement » avec par la commande d-i preseed/late_command suivante:
d-i preseed/late_command string \
logger "late_command: remove todelete"; \
if [ -n "`mount | grep todelete`" ]; then umount /target/todelete; fi; \
rm -fr /target/todelete; \
lvchange -an /dev/mapper/vg01-todelete; \
lvremove -y /dev/mapper/vg01-todelete; \
sed -Ei '/todelete/d' /target/etc/fstab && logger "todete removed from /etc/fstab"; \
mkfs.fat /dev/md0; mkdir -p /target/boot/efi; mount -t vfat /dev/md0 /target/boot/efi; \
chroot /target grub-install --target=x86_64-efi --force-extra-removable --efi-directory=/boot/efi; \
echo "# /boot/efi was on /dev/md0 during installation" >> /target/etc/fstab; \
echo "/dev/md0 /boot/efi vfat umask=0077 0 1" >> /target/etc/fstab;
Celle-ci réalise:
- la suppression de la partition todelete (lignes 2 à 7), y compris de /etc/fstab
- le formatage de la partition /dev/md0 en fat (vfat), la création du répertoire /boot/efi à la cible, et le montage de la partition (ligne 8)
- l’installation de grub-efi (ligne 9)
- l’enregistrement de la partition dans /etc/fstab de la cible (lignes 10 et 11)
Par ailleurs il faut s’assurer que l’installateur ne réagisse pas à la non installation du bootloader avec les expressions suivantes:
### Description: for internal use; can be preseeded
# Skip installing grub?
d-i grub-installer/skip boolean true
### Description: Continue without installing GRUB?
# You chose not to install GRUB to any devices. If you continue, the boot
# loader may not be properly configured, and when this computer next starts
# up it will use whatever was previously in the boot sector. If there is an
# earlier version of GRUB 2 in the boot sector, it may be unable to load
# modules or handle the current configuration file.
# .
# If you are already using a different boot loader and want to carry on
# doing so, or if this is a special environment where you do not need a boot
# loader, then you should continue anyway. Otherwise, you should install
# GRUB somewhere.
d-i grub-pc/install_devices_empty boolean true
# Don't show information about no boot loader installed
nobootloader nobootloader/confirmation_common note
### Description: Install the GRUB boot loader to your primary drive?
# It seems that this new installation is the only operating system
# on this computer. If so, it should be safe to install the GRUB boot loader
# to your primary drive (UEFI partition/boot record).
# .
# Warning: If your computer has another operating system that the installer
# failed to detect, this will make that operating system temporarily
# unbootable, though GRUB can be manually configured later to boot it.
d-i grub-installer/only_debian boolean false
et s’assurer aussi qu’il n e fasse aps de notifications:
# To avoid message handler information note
d-i grub-installer/exception_handler_note note
# To avoid message information note about no boot loader
d-i grub-installer/nobootloader_note note
Le preseed
Le fichier preseed au complet est ici:
vmssrvraid1.preseed.txt (38,3 Ko)
(au format .txt car .preseed n’est pas autorisé).
C’est un fichier directement utilisable dasn un profil simple-cdd (ici le nom du profil est vmssrvraid1, pour Virtual MachineS SeRVer RAID1).
PS: Pour tout commentaires, soit en MP soit en ouvrant un fil de discussion dans Pause Café spécifique, ou bien celui que j’avais ouvert ici.