#!/bin/bash # Installation semi automatique d'une VM Arch Linux # avec les propriétés suivantes : # - Firmware : EFI # - Partionnement : #  * / : 50Go #  * /boot : 128Mo # - Chiffrement de la partition principale (/) avec DM-crypt/LUKS # - Utilisateur root + un utilisateur sudo ############################################################################### # PREREQUIS # ############################################################################### # On verifie le mode de boot : MBR ou EFI. if [ -d /sys/firmware/efi ] ; then echo "[+] Systeme UEFI... OK" else echo "[-] System MBR, merci de rebooter en UEFI" exit 1 fi # Verifie que le reseau est OK ping -c 1 example.net &> /dev/null if [ $? -eq 0 ] ; then echo "[+] Reseau fonctionnel... OK" else echo "[-] Reseau non accessible !" exit 1 fi ############################################################################### # PARTITIONNEMENT # ############################################################################### # Choix du disque a utiliser echo "" fdisk -l echo "" disk_options=( $(fdisk -l | grep -E "/dev/.*sec" | awk '{print $2}' | sed -e "s/://g") ) echo "[+] Choisissez le disque a utiliser, tout le contenu sera ecrase:" for (( **0; i<${#disk_options[@]}; i++ )); do echo " - $i : ${disk_options[$i]}" done DISK=-1 while [ ! "$DISK" -ge 0 ] || [ ! "$DISK" -le ${#disk_options[@]} ] do read -p " > Choix : " DISK done read -p "[+] Le disque ${disk_options[$DISK]} va être partitionné ! OK ? (Yy)" -n 1 -r if [[ ! $REPLY =~ ^[Yy]$ ]] ; then exit 1 fi # Partionnement automatique avec fdisk sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk ${disk_options[$DISK]} o # clear the in memory partition table n # new partition p # primary partition 1 # partition number 1 # default - start at beginning of disk +128M # 100 MB boot parttion n # new partition p # primary partition 2 # partion number 2 # default, start immediately after preceding partition # default, extend partition to end of disk t # change partition type 1 # partition 1 ef # type EFI a # make a partition bootable 1 # bootable partition is partition 1 -- /dev/sda1 p # print the in-memory partition table w # write the partition table q # and we're done EOF echo "[+] Le partitionnement est termine." lsblk ROOT_PART=`lsblk | grep part | grep G | awk '{print $1}' | tr -cd '\11\12\15\40-\176'` echo "[+] Preparation du chiffrement sur la partition $ROOT_PART" until cryptsetup -y -v luksFormat /dev/$ROOT_PART do echo "[-] Erreur, on reessaie !" done cryptsetup open /dev/$ROOT_PART cryptroot mkfs.ext4 /dev/mapper/cryptroot mount /dev/mapper/cryptroot /mnt BOOT_PART=`lsblk | grep 128M | awk '{print $1}' | tr -cd '\11\12\15\40-\176'` echo "[+] Creation du systeme de fichier pour la partition de boot /dev/$BOOT_PART" if [ -n "${BOOT_PART}" ] ; then mkfs.fat -F 32 /dev/$BOOT_PART fi mkdir -p /mnt/boot/EFI mount /dev/$BOOT_PART /mnt/boot/EFI ############################################################################### # CONFIGURATION # ############################################################################### echo "[+] Installation des paquets de base" pacstrap /mnt base linux linux-firmware grub os-prober efibootmgr echo "[+] Generation du fstab" genfstab -U /mnt >> /mnt/etc/fstab echo "[+] Configuration de la langue et du fuseau horaire" arch-chroot /mnt ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime arch-chroot /mnt hwclock --systohc sed -i "s/#fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8" /mnt/etc/locale.gen arch-chroot /mnt locale-gen echo "LANG=fr_FR.UTF-8" >> /mnt/etc/locale.conf echo "KEYMAP=fr" >> /mnt/etc/vconsole.conf echo "pentest-jdemianenko" >> /mnt/etc/hostname echo "[+] Mot de passe root" arch-chroot /mnt passwd echo "[+] Ajouter un utilisateur standard" arch-chroot /mnt useradd -m -g users -G wheel,power -s /bin/bash julie arch-chroot /mnt passwd julie echo "[+] Configuration de mkinitcpio pour inclure les modules de chiffrement" sed -i "s/HOOKS=.*/HOOKS=(base udev autodetect keyboard keymap consolefont modconf block encrypt filesystems fsck)/g" /mnt/etc/mkinitcpio.conf echo "[+] Ajustement de GRUB pour LUKS" ** /mnt/etc/default/grub /mnt/etc/default/grub.bak CRYPT_UUID=$(blkid | grep cryptroot | awk -F\" '{print $2}') sed -E "s/GRUB_CMDLINE_LINUX=\"(.*)\"/GRUB_CMDLINE_LINUX=\"\1 cryptdevice=UUID=$CRYPT_UUID:cryptroot root=\/dev\/mapper\/cryptroot\"/g" /mnt/etc/default/grub.bak > /mnt/etc/default/grub sed -i "s/^#GRUB_ENABLE_CRYPTODISK=y/GRUB_ENABLE_CRYPTODISK=y/g" /mnt/etc/default/grub echo "Installation de GRUB" arch-chroot /mnt mkinitcpio -P arch-chroot /mnt grub-install --target=x86_64-efi --efi-directory /boot/EFI --bootloader-id=GRUB --recheck arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg