Créer l'arborescence suivante:
sudo mkdir -p /data/{extract,isos,mnt,config}
sudo chown -R $USER /data
/data/
├── extract
├── isos
├── mnt
└── config
Script pour recupération des fichiers a modifier:
Remarque: A lancer en tant que root
Script pour extraire grub
Remarque: Modifier la version de l'image si besoin
#!/bin/bash
export ISO_NAME="ubuntu-22.04.4-live-server-amd64.iso"
export ISO_URL="https://releases.ubuntu.com/22.04/$ISO_NAME"
if [ ! -f "/data/isos/${ISO_NAME}" ]; then
wget -P /data/isos $ISO_URL
else
echo "Fichier ${ISO_NAME} present."
fi
echo "Montage ${ISO_NAME} dans /data/mnt"
sudo mount -o loop /data/isos/${ISO_NAME} /data/mnt
echo "Copy de grub"
cp --no-preserve=all /data/mnt/boot/grub/grub.cfg /data/extract/grub.cfg
sudo umount /data/mnt
Ajouter a /data/extract/grub.cfg la section:
menuentry "Autoinstall cloud on http://192.168.88.15:4000/" {
set gfxpayload=keep
linux /casper/vmlinuz autoinstall "ds=nocloud;s=http://192.168.88.15:4000/static-cloudinit/" ---
initrd /casper/initrd
}
Preparer votre fichier user-data
#cloud-config
autoinstall:
version: 1
packages:
- ubuntu-desktop
snaps:
- name: firefox
- name: gnome-3-38-2004
- name: gtk-common-themes
- name: snap-store
- name: snapd-desktop-integration
interactive-sections:
- identity
keyboard:
layout: fr
toggle: null
variant: ''
locale: fr_FR.UTF-8
storage:
layout:
name: lvm
password: touch
ssh:
install-server: true
# option "allow-pw" defaults to `true` if authorized_keys is empty, `false` otherwise.
allow-pw: false
updates: security
# Ubuntu Desktop uses the hwe flavor kernel by default.
early-commands:
- echo 'linux-generic-hwe-22.04' > /run/kernel-meta-package
# "[late-commands] are run in the installer environment with the installed system mounted at /target."
late-commands:
# randomly generate the hostname & show the IP at boot
- echo ubuntu-host-$(openssl rand -hex 3) > /target/etc/hostname
# dump the IP out at login screen
- echo "Ubuntu 22.04 LTS \nIP - $(hostname -I)\n" > /target/etc/issue
# Let NetworkManager handle network
- rm /target/etc/netplan/00-installer-config*yaml
- >-
printf "network:\n version: 2\n renderer: NetworkManager"
> /target/etc/netplan/01-network-manager-all.yaml
# shut-down the host to avoid an infinite installer loop
- shutdown -h now
user-data:
disable_root: true
timezone: Europe/Paris
package_upgrade: false
users:
- name: useritlu
primary_group: users
groups: sudo
lock_passwd: false
# don't need PW since using SSH, leaving this in though...
# password is "changeme" - created with `docker run -it --rm alpine mkpasswd --method=SHA-512`
passwd: "$5$IWwNqL9VUSDoc4Jv$DEUGR.cZQcbz/QvdCOmU13fX5ZW0rANg8LqkAtX3nBA"
shell: /bin/bash
# use cat ~/.ssh/id_rsa.pub or generate to get your public key
ssh_authorized_keys:
- "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC14slyp/JGv9iqLH4D94x+7v4PB/ec0YbLUPexdBip6OJaflbmp3s25WJ+oyO6U78Ee0jZUZt0TapYozyNx9UksP9JhirwKeNJnQSzSX0RKc6kQffoCgWHZmnzuoalEzaE7XyH+K8wP+hKi052ak9yR7XWDp6CG3V1Qpyq80VD1XNUzEL2xkITGQ6KojxrOJ1O0A9ISRu1t85Ul2N0syIylE2Ukvns1/NkArhC2g8N8T5XxPq39AUH78A3I0/kHowIzW9BpPVwim0tJTLSVNnVqq1NPG+gi1XvrXKzO/jb4kT01tnMG9vKcYqdH4g0y01ADEcCgMo1jGAjwq6gPLqT imported-openssh-key"
sudo: ALL=(ALL) NOPASSWD:ALL
# shutdown after first host initial provisioning
power_state:
mode: poweroff
il faut egalemnt un fichier vide meta-data
touch /data/extract/meta-data
sudo apt install git xorriso squashfs-tools python3-debian gpg liblz4-tool python3-pip -y
git clone https://github.com/mwhudson/livefs-editor
cd livefs-editor/
sudo python3 -m pip install .
/data/config/ubuntu.yaml
- name: cp
source: /data/extract/grub.cfg
dest: new/iso/boot/grub/grub.cfg
cd /data
sudo livefs-edit isos/ubuntu-22.04.4-live-server-amd64.iso isos/ubuntu-modif.iso --action-yaml config/ubuntu.yml
[{'name': 'cp', 'source': '/data/extract/grub.cfg', 'dest': 'new/iso/boot/grub/grub.cfg'}, {'name': 'cp', 'source': '/data/extract/user-data', 'dest': 'new/iso/server/user-data'}]
set up loop device /dev/loop8 backing isos/ubuntu-22.04.4-live-server-amd64.iso
found live iso9660 filesystem on /dev/loop8p1
running cp with arguments {'source': '/data/extract/grub.cfg', 'dest': 'new/iso/boot/grub/grub.cfg'}
.. snip ...
xorriso : UPDATE : 95.32% done, estimate finish Mon Apr 15 21:34:12 2024
xorriso : UPDATE : 97.40% done
ISO image produced: 1027282 sectors
Written to medium : 1027282 sectors at LBA 0
Writing to 'stdio:isos/ubuntu-modif.iso' completed successfully.
Inserer votre clé USB
Verifier le path
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
.. snip ..
sda 8:0 1 57,8G 0 disk
└─sda1 8:1 1 57,7G 0 part /media/stef/KINGSTON
.. snip ...
Demonter la clé
umount /media/stef/KINGSTON
Ecrire l'image iso nouvellement généré sur la clé USB
sudo dd bs=4M if=/data/isos/ubuntu-22.04-modif.iso of=/dev/sda status=progress oflag=sync
2080374784 octets (2,1 GB, 1,9 GiB) copiés, 93 s, 22,3 MB/s
501+1 enregistrements lus
501+1 enregistrements écrits
2103867392 octets (2,1 GB, 2,0 GiB) copiés, 93,7069 s, 22,5 MB/s
Démarrer un PC en bootant sur la clé usb
Selectionner l'entrée que vous avez ajouté (Dans l'exemple: Autoinstall cloud on http://votreurl/ )