setuparchlinux.zsh
· 3.5 KiB · Bash
Raw
#!/usr/bin/env zsh
set -euo nounset
#############################################
# Arch Linux install non-interactif (UEFI)
# - ESP montée sur /boot de 2G (FAT32)
# - Wi-Fi via wlan0 (SSID/PSK en variables)
#
# ATTENTION: CE SCRIPT EFFACE LE DISQUE.
# À lancer depuis l'ISO Arch (archiso) en root.
#############################################
### ====== VARIABLES À REMPLIR ======
DISK="/dev/nvme0n1" # ex: /dev/sda ou /dev/nvme0n1
HOSTNAME="arch"
USERNAME="user"
USER_PASSWORD="changeme"
ROOT_PASSWORD="changeme"
WIFI_INTERFACE="wlan0"
WIFI_SSID="TON_SSID"
WIFI_PSK="TON_PSK"
TIMEZONE="Europe/Paris"
LOCALE="fr_FR.UTF-8"
KEYMAP="fr"
### =================================
die() {
print -u2 "ERROR: $*"
exit 1
}
need() {
command -v "$1" >/dev/null 2>&1 || die "Commande manquante: $1"
}
for c in sgdisk mkfs.fat mkfs.ext4 mount umount pacstrap genfstab arch-chroot iwctl; do
need "$c"
done
[[ -b "$DISK" ]] || die "Disque invalide: $DISK"
print "==> Vérification UEFI..."
[[ -d /sys/firmware/efi ]] || die "UEFI requis"
print "==> Synchronisation de l'heure..."
timedatectl set-ntp true 2>/dev/null || true
print "==> Connexion Wi-Fi ($WIFI_INTERFACE)..."
iwctl --passphrase "$WIFI_PSK" station "$WIFI_INTERFACE" connect "$WIFI_SSID" \
|| die "Connexion Wi-Fi échouée"
ping -c 1 archlinux.org >/dev/null 2>&1 || die "Pas d'accès réseau"
print "==> Partitionnement GPT sur $DISK"
swapoff -a 2>/dev/null || true
umount -R /mnt 2>/dev/null || true
PART_PREFIX="$DISK"
[[ "$DISK" == *nvme* ]] && PART_PREFIX="${DISK}p"
BOOT_PART="${PART_PREFIX}1"
ROOT_PART="${PART_PREFIX}2"
sgdisk --zap-all "$DISK"
sgdisk -n 1:0:+2G -t 1:ef00 -c 1:"EFI_SYSTEM" "$DISK"
sgdisk -n 2:0:0 -t 2:8300 -c 2:"ARCH_ROOT" "$DISK"
partprobe "$DISK"
sleep 2
print "==> Formatage..."
mkfs.fat -F32 -n BOOT "$BOOT_PART"
mkfs.ext4 -F -L ROOT "$ROOT_PART"
print "==> Montage..."
mount "$ROOT_PART" /mnt
mkdir -p /mnt/boot
mount "$BOOT_PART" /mnt/boot
print "==> Installation du système de base..."
pacstrap -K /mnt \
base linux linux-firmware \
networkmanager iwd sudo vim
print "==> Génération fstab..."
genfstab -U /mnt >> /mnt/etc/fstab
print "==> Configuration système (chroot)..."
arch-chroot /mnt /usr/bin/env zsh <<EOF
set -euo nounset
ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
hwclock --systohc
sed -i 's/^#\\($LOCALE\\)/\\1/' /etc/locale.gen
locale-gen
print "LANG=$LOCALE" > /etc/locale.conf
print "KEYMAP=$KEYMAP" > /etc/vconsole.conf
print "$HOSTNAME" > /etc/hostname
cat >/etc/hosts <<H
127.0.0.1 localhost
::1 localhost
127.0.1.1 $HOSTNAME.localdomain $HOSTNAME
H
print "root:$ROOT_PASSWORD" | chpasswd
useradd -m -G wheel -s /bin/zsh "$USERNAME"
print "$USERNAME:$USER_PASSWORD" | chpasswd
sed -i 's/^# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
systemctl enable NetworkManager
systemctl enable iwd
mkdir -p /etc/NetworkManager/system-connections
cat >/etc/NetworkManager/system-connections/wifi.nmconnection <<NMC
[connection]
id=wifi
type=wifi
autoconnect=true
[wifi]
ssid=$WIFI_SSID
mode=infrastructure
[wifi-security]
key-mgmt=wpa-psk
psk=$WIFI_PSK
[ipv4]
method=auto
[ipv6]
method=auto
NMC
chmod 600 /etc/NetworkManager/system-connections/wifi.nmconnection
bootctl install
ROOT_UUID=\$(blkid -s UUID -o value "$ROOT_PART")
cat >/boot/loader/loader.conf <<L
default arch
timeout 3
editor no
L
cat >/boot/loader/entries/arch.conf <<E
title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options root=UUID=\$ROOT_UUID rw
E
EOF
print "==> Nettoyage..."
umount -R /mnt
print "==> Installation terminée. Reboot possible."
| 1 | #!/usr/bin/env zsh |
| 2 | set -euo nounset |
| 3 | |
| 4 | ############################################# |
| 5 | # Arch Linux install non-interactif (UEFI) |
| 6 | # - ESP montée sur /boot de 2G (FAT32) |
| 7 | # - Wi-Fi via wlan0 (SSID/PSK en variables) |
| 8 | # |
| 9 | # ATTENTION: CE SCRIPT EFFACE LE DISQUE. |
| 10 | # À lancer depuis l'ISO Arch (archiso) en root. |
| 11 | ############################################# |
| 12 | |
| 13 | ### ====== VARIABLES À REMPLIR ====== |
| 14 | DISK="/dev/nvme0n1" # ex: /dev/sda ou /dev/nvme0n1 |
| 15 | HOSTNAME="arch" |
| 16 | USERNAME="user" |
| 17 | USER_PASSWORD="changeme" |
| 18 | ROOT_PASSWORD="changeme" |
| 19 | |
| 20 | WIFI_INTERFACE="wlan0" |
| 21 | WIFI_SSID="TON_SSID" |
| 22 | WIFI_PSK="TON_PSK" |
| 23 | |
| 24 | TIMEZONE="Europe/Paris" |
| 25 | LOCALE="fr_FR.UTF-8" |
| 26 | KEYMAP="fr" |
| 27 | ### ================================= |
| 28 | |
| 29 | die() { |
| 30 | print -u2 "ERROR: $*" |
| 31 | exit 1 |
| 32 | } |
| 33 | |
| 34 | need() { |
| 35 | command -v "$1" >/dev/null 2>&1 || die "Commande manquante: $1" |
| 36 | } |
| 37 | |
| 38 | for c in sgdisk mkfs.fat mkfs.ext4 mount umount pacstrap genfstab arch-chroot iwctl; do |
| 39 | need "$c" |
| 40 | done |
| 41 | |
| 42 | [[ -b "$DISK" ]] || die "Disque invalide: $DISK" |
| 43 | |
| 44 | print "==> Vérification UEFI..." |
| 45 | [[ -d /sys/firmware/efi ]] || die "UEFI requis" |
| 46 | |
| 47 | print "==> Synchronisation de l'heure..." |
| 48 | timedatectl set-ntp true 2>/dev/null || true |
| 49 | |
| 50 | print "==> Connexion Wi-Fi ($WIFI_INTERFACE)..." |
| 51 | iwctl --passphrase "$WIFI_PSK" station "$WIFI_INTERFACE" connect "$WIFI_SSID" \ |
| 52 | || die "Connexion Wi-Fi échouée" |
| 53 | |
| 54 | ping -c 1 archlinux.org >/dev/null 2>&1 || die "Pas d'accès réseau" |
| 55 | |
| 56 | print "==> Partitionnement GPT sur $DISK" |
| 57 | swapoff -a 2>/dev/null || true |
| 58 | umount -R /mnt 2>/dev/null || true |
| 59 | |
| 60 | PART_PREFIX="$DISK" |
| 61 | [[ "$DISK" == *nvme* ]] && PART_PREFIX="${DISK}p" |
| 62 | |
| 63 | BOOT_PART="${PART_PREFIX}1" |
| 64 | ROOT_PART="${PART_PREFIX}2" |
| 65 | |
| 66 | sgdisk --zap-all "$DISK" |
| 67 | sgdisk -n 1:0:+2G -t 1:ef00 -c 1:"EFI_SYSTEM" "$DISK" |
| 68 | sgdisk -n 2:0:0 -t 2:8300 -c 2:"ARCH_ROOT" "$DISK" |
| 69 | partprobe "$DISK" |
| 70 | sleep 2 |
| 71 | |
| 72 | print "==> Formatage..." |
| 73 | mkfs.fat -F32 -n BOOT "$BOOT_PART" |
| 74 | mkfs.ext4 -F -L ROOT "$ROOT_PART" |
| 75 | |
| 76 | print "==> Montage..." |
| 77 | mount "$ROOT_PART" /mnt |
| 78 | mkdir -p /mnt/boot |
| 79 | mount "$BOOT_PART" /mnt/boot |
| 80 | |
| 81 | print "==> Installation du système de base..." |
| 82 | pacstrap -K /mnt \ |
| 83 | base linux linux-firmware \ |
| 84 | networkmanager iwd sudo vim |
| 85 | |
| 86 | print "==> Génération fstab..." |
| 87 | genfstab -U /mnt >> /mnt/etc/fstab |
| 88 | |
| 89 | print "==> Configuration système (chroot)..." |
| 90 | arch-chroot /mnt /usr/bin/env zsh <<EOF |
| 91 | set -euo nounset |
| 92 | |
| 93 | ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime |
| 94 | hwclock --systohc |
| 95 | |
| 96 | sed -i 's/^#\\($LOCALE\\)/\\1/' /etc/locale.gen |
| 97 | locale-gen |
| 98 | print "LANG=$LOCALE" > /etc/locale.conf |
| 99 | print "KEYMAP=$KEYMAP" > /etc/vconsole.conf |
| 100 | |
| 101 | print "$HOSTNAME" > /etc/hostname |
| 102 | cat >/etc/hosts <<H |
| 103 | 127.0.0.1 localhost |
| 104 | ::1 localhost |
| 105 | 127.0.1.1 $HOSTNAME.localdomain $HOSTNAME |
| 106 | H |
| 107 | |
| 108 | print "root:$ROOT_PASSWORD" | chpasswd |
| 109 | useradd -m -G wheel -s /bin/zsh "$USERNAME" |
| 110 | print "$USERNAME:$USER_PASSWORD" | chpasswd |
| 111 | sed -i 's/^# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers |
| 112 | |
| 113 | systemctl enable NetworkManager |
| 114 | systemctl enable iwd |
| 115 | |
| 116 | mkdir -p /etc/NetworkManager/system-connections |
| 117 | cat >/etc/NetworkManager/system-connections/wifi.nmconnection <<NMC |
| 118 | [connection] |
| 119 | id=wifi |
| 120 | type=wifi |
| 121 | autoconnect=true |
| 122 | |
| 123 | [wifi] |
| 124 | ssid=$WIFI_SSID |
| 125 | mode=infrastructure |
| 126 | |
| 127 | [wifi-security] |
| 128 | key-mgmt=wpa-psk |
| 129 | psk=$WIFI_PSK |
| 130 | |
| 131 | [ipv4] |
| 132 | method=auto |
| 133 | |
| 134 | [ipv6] |
| 135 | method=auto |
| 136 | NMC |
| 137 | chmod 600 /etc/NetworkManager/system-connections/wifi.nmconnection |
| 138 | |
| 139 | bootctl install |
| 140 | ROOT_UUID=\$(blkid -s UUID -o value "$ROOT_PART") |
| 141 | |
| 142 | cat >/boot/loader/loader.conf <<L |
| 143 | default arch |
| 144 | timeout 3 |
| 145 | editor no |
| 146 | L |
| 147 | |
| 148 | cat >/boot/loader/entries/arch.conf <<E |
| 149 | title Arch Linux |
| 150 | linux /vmlinuz-linux |
| 151 | initrd /initramfs-linux.img |
| 152 | options root=UUID=\$ROOT_UUID rw |
| 153 | E |
| 154 | EOF |
| 155 | |
| 156 | print "==> Nettoyage..." |
| 157 | umount -R /mnt |
| 158 | |
| 159 | print "==> Installation terminée. Reboot possible." |
| 160 |