Logo Pastebin.fr
Pastebin

Retrouvez, créez et partagez vos snippets en temps réel.

tes

#!/bin/bash
# Script d'installation Automatique Chainloader Gen8
# A copier sur pastebin.com (RAW)

echo "=== Gen8 Chainloader Auto-Installer ==="
echo "ATTENTION : Ce script va effacer la carte SD/USB cible."

# 1. Detection des disques
lsblk -o NAME,MODEL,SIZE,TYPE,FSTYPE
echo ""
echo "Identifiez votre carte MicroSD ou clé USB Chainloader (ex: sdb, sdc)."
echo "Ne choisissez PAS sda (votre SSD TrueNAS)!"
read -p "Entrez le nom du device (ex: sdb) : " DISK
DEVICE="/dev/$DISK"

if; then
    echo "Erreur: $DEVICE n'existe pas."
    exit 1
fi

echo "Vous avez choisi : $DEVICE"
read -p "Etes-vous sur de vouloir TOUT EFFACER sur $DEVICE? (y/n) " CONFIRM
if; then
    echo "Annulation."
    exit 0
fi

# 2. Preparation Disque
echo "[+] Nettoyage et Partitionnement..."
umount ${DEVICE}* 2>/dev/null
parted -s $DEVICE mklabel msdos
parted -s $DEVICE mkpart primary ext2 1MiB 100%
parted -s $DEVICE set 1 boot on
mdev -s 2>/dev/null # Refresh devices
sleep 2

# 3. Formatage
echo "[+] Formatage ext2..."
mkfs.ext2 ${DEVICE}1 > /dev/null

# 4. Montage
echo "[+] Montage..."
mkdir -p /mnt/chainboot
mount ${DEVICE}1 /mnt/chainboot

# 5. Installation GRUB
echo "[+] Installation GRUB (i386-pc)..."
grub-install --target=i386-pc --boot-directory=/mnt/chainboot/boot $DEVICE

# 6. Configuration GRUB Dynamique
echo "[+] Creation grub.cfg..."
cat > /mnt/chainboot/boot/grub/grub.cfg <<EOF
set timeout=2
set default=0
insmod part_gpt
insmod part_msdos
insmod zfs
insmod ext2
insmod chain

menuentry "TrueNAS SCALE (Auto-Detect Gen8)" {
    echo "Scanning ports for TrueNAS..."
    # On scanne les ports SATA 5 a 0
    # TrueNAS cree generalement une partition BIOS boot (1) ou EFI (2) et ZFS (3)
    # On cherche la partition 3 (ZFS) pour identifier le disque
    for i in 5 4 3 2 1 0; do
        if [ -e (hd\$i,gpt3) ]; then
            echo "Found TrueNAS on hd\$i"
            set root=(hd\$i)
            chainloader +1
            boot
        fi
    done
    echo "Erreur: TrueNAS introuvable. Verifiez le mode BIOS/Legacy."
    sleep 10
}
EOF

# 7. Finalisation
echo "[+] Termine!"
umount /mnt/chainboot
echo "Vous pouvez redemarrer. Retirez la cle d'installation."
reboot

Créé il y a 2 semaines.

Rechercher un Pastebin

Aucun paste trouvé.