mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-03-10 08:15:30 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7916ca2da9 | ||
|
|
6b4e3f05e7 | ||
|
|
618f82af2f | ||
|
|
1120c268f2 |
@@ -5,54 +5,79 @@ set -e
|
|||||||
. /etc/default/grub
|
. /etc/default/grub
|
||||||
|
|
||||||
### variables modifiable ###
|
### variables modifiable ###
|
||||||
## nom du sous-menu
|
## fr: nom du sous-menu
|
||||||
|
## en: Name of the submenu
|
||||||
submenuname="ArchLinux Snapshots"
|
submenuname="ArchLinux Snapshots"
|
||||||
## préfixe de l'entrée
|
## fr: préfixe de l'entrée
|
||||||
|
## en: Prefix entry
|
||||||
prefixentry="Snapshot"
|
prefixentry="Snapshot"
|
||||||
## nom(s) du ou des kernel(s)
|
## fr: nom(s) du ou des kernel(s)
|
||||||
|
## en: Name(s) of the kernel(s)
|
||||||
nkernel=("vmlinuz-linux")
|
nkernel=("vmlinuz-linux")
|
||||||
## nom(s) de(s) l'init
|
## fr: nom(s) de(s) l'init
|
||||||
|
## en: Name(s) of the init(s)
|
||||||
ninit=("initramfs-linux.img" "initramfs-linux-fallback.img")
|
ninit=("initramfs-linux.img" "initramfs-linux-fallback.img")
|
||||||
|
|
||||||
|
|
||||||
#######################
|
###########################
|
||||||
### DÉBUT DU SCRIPT ###
|
### fr: DÉBUT DU SCRIPT ###
|
||||||
### NE PAS TOUCHER ###
|
### en: NAME OF SCRIPT ###
|
||||||
#######################
|
### fr: NE PAS TOUCHER ###
|
||||||
## paramêtre des chaînes --hint
|
### en: DO NOT TOUCH ###
|
||||||
|
###########################
|
||||||
|
## fr: paramêtre des chaînes --hint
|
||||||
|
## en: Parameter of the chains --hint (Translation unclear)
|
||||||
pboot=$(${grub_probe} --target="hints_string" "/boot" 2>/dev/null)
|
pboot=$(${grub_probe} --target="hints_string" "/boot" 2>/dev/null)
|
||||||
## uuid de la partition root
|
## fr: uuid de la partition root
|
||||||
|
## en: UUID of the root partition
|
||||||
uuid=$(${grub_probe} "/" --target="fs_uuid" 2>/dev/null)
|
uuid=$(${grub_probe} "/" --target="fs_uuid" 2>/dev/null)
|
||||||
## uuid de la partition boot
|
## fr: uuid de la partition boot
|
||||||
|
## en: UUID of the boot partition
|
||||||
buuid=$(${grub_probe} --target="fs_uuid" "/boot" 2>/dev/null)
|
buuid=$(${grub_probe} --target="fs_uuid" "/boot" 2>/dev/null)
|
||||||
## paramêtre passé au kernel
|
## fr: paramêtre passé au kernel
|
||||||
|
## en: Parameters passed to the kernel
|
||||||
params="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
|
params="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
|
||||||
|
|
||||||
|
|
||||||
# on affiche le menu
|
# fr: on affiche le menu
|
||||||
|
# en: Display the menu
|
||||||
echo "submenu '$submenuname' {"
|
echo "submenu '$submenuname' {"
|
||||||
|
|
||||||
# on traite la variable kernel
|
# fr: on traite la variable kernel
|
||||||
|
# en: Treat the kernel variables (Translation unclear)
|
||||||
for kernel in ${nkernel[@]}; do
|
for kernel in ${nkernel[@]}; do
|
||||||
# on test si le(s) nom(s) du(des) kernel existe(nt), autrement on affiche une erreur et on sort
|
# fr: on test si le(s) nom(s) du(des) kernel existe(nt), autrement on affiche une erreur et on sort
|
||||||
if [ ! -f /boot/$kernel ]; then echo "/boot/$kernel: Fichier inexistant" >&2; exit 1; fi
|
# en: Check the specified kernel(s) exist, if it/they don't, display an error and exit
|
||||||
# on vérifie le nombre de kernel présent, si >1 on crée un menu
|
if [ ! -f /boot/$kernel ]; then echo "/boot/$kernel: fr: Fichier inexistant en: File does not exist" >&2; exit 1; fi
|
||||||
|
# fr: on vérifie le nombre de kernel présent, si >1 on crée un menu
|
||||||
|
# en: If there are >1 kernels, create a menu
|
||||||
if [ ${#nkernel[*]} != 1 ]; then echo " submenu '$kernel' {
|
if [ ${#nkernel[*]} != 1 ]; then echo " submenu '$kernel' {
|
||||||
submenu '---> Kernel: $kernel <---' { echo }"; fi
|
submenu '---> Kernel: $kernel <---' { echo }"; fi
|
||||||
|
|
||||||
# On liste les snapshots présent sur le système de fichier
|
# fr: On liste les snapshots présent sur le système de fichier
|
||||||
|
# en: List filesystem snapshots
|
||||||
for item in $($bindir/btrfs subvolume list -s / --sort=-ogen | $bindir/awk '{print $NF}'); do
|
for item in $($bindir/btrfs subvolume list -s / --sort=-ogen | $bindir/awk '{print $NF}'); do
|
||||||
# On écarte les snapshots avec un statut de suppression
|
# fr: On écarte les snapshots avec un statut de suppression
|
||||||
|
# en: Discard deleted snapshots
|
||||||
if [ $item = "DELETED" ]; then continue; fi
|
if [ $item = "DELETED" ]; then continue; fi
|
||||||
# on crée un menu pour chaque snapshot présent
|
# fr: affiche la liste des snapshots trouvés
|
||||||
echo " submenu '$prefixentry $item' {"
|
# en: Output name of snapshot
|
||||||
# si plusieurs kernel on été trouvé, on affiche un titre indicatif
|
gettext_printf "Found Snapshot: %s\n" "$item" >&2
|
||||||
|
# fr: on crée un menu pour chaque snapshot présent (nom + date de création)
|
||||||
|
# en: Create a menu for remaining snapshots (name + creation date)
|
||||||
|
date_time=$($bindir/btrfs subvolume list -s / | $bindir/grep $item | $bindir/cut -d" " -f 11-12)
|
||||||
|
echo " submenu '$prefixentry $item [$date_time]' {"
|
||||||
|
# fr: si plusieurs kernel on été trouvé, on affiche un titre indicatif
|
||||||
|
# en: Display message if more than one kernel is found
|
||||||
if [ ${#nkernel[*]} != 1 ]; then echo " submenu '---> Kernel: $kernel <---' { echo }"; fi
|
if [ ${#nkernel[*]} != 1 ]; then echo " submenu '---> Kernel: $kernel <---' { echo }"; fi
|
||||||
# on traite la variable de l'initframs
|
# fr: on traite la variable de l'initramfs
|
||||||
|
# en: Treat the initramfs variables (Translation unclear)
|
||||||
for init in ${ninit[@]}; do
|
for init in ${ninit[@]}; do
|
||||||
# on test si le(s) nom(s) du(des) initframs existe(nt), autrement on affiche une erreur et on sort
|
# fr: on test si le(s) nom(s) du(des) initramfs existe(nt), autrement on affiche une erreur et on sort
|
||||||
|
# en: Check the specified initramfs(es) exist, if it/they don't, display an error and exit
|
||||||
if [ ! -f /boot/$init ]; then echo "/boot/$init: Fichier inexistant" >&2; exit 1; fi
|
if [ ! -f /boot/$init ]; then echo "/boot/$init: Fichier inexistant" >&2; exit 1; fi
|
||||||
# on traite chaque entrée des snapshots avec leurs kernel et initframs respectifs
|
# fr: on traite chaque entrée des snapshots avec leurs kernel et initramfs respectifs
|
||||||
|
# en: Specify a kernel and initramfs for every snapshot
|
||||||
echo "\
|
echo "\
|
||||||
menuentry '$item $init' --class arch --class gnu-linux --class gnu --class os "\$menuentry_id_option" 'gnulinux-snapshots-$uuid'{
|
menuentry '$item $init' --class arch --class gnu-linux --class gnu --class os "\$menuentry_id_option" 'gnulinux-snapshots-$uuid'{
|
||||||
load_video
|
load_video
|
||||||
@@ -63,7 +88,8 @@ for kernel in ${nkernel[@]}; do
|
|||||||
search --no-floppy --fs-uuid --set=root $buuid
|
search --no-floppy --fs-uuid --set=root $buuid
|
||||||
fi
|
fi
|
||||||
echo 'Loading Linux snapshot ...'"
|
echo 'Loading Linux snapshot ...'"
|
||||||
# on vérifie l'emplacement de la partition /boot
|
# fr: on vérifie l'emplacement de la partition /boot
|
||||||
|
# en: Check the location of the /boot partition
|
||||||
if [ $uuid = $buuid ]; then
|
if [ $uuid = $buuid ]; then
|
||||||
echo "\
|
echo "\
|
||||||
linux /$item/boot/$kernel root=UUID=$uuid rw rootflags=subvol=$item $params
|
linux /$item/boot/$kernel root=UUID=$uuid rw rootflags=subvol=$item $params
|
||||||
@@ -80,7 +106,8 @@ for kernel in ${nkernel[@]}; do
|
|||||||
done
|
done
|
||||||
echo " }"
|
echo " }"
|
||||||
done
|
done
|
||||||
# on oubli pas de fermer le menu si plusieurs kernels ont été trouvé
|
# fr: on oubli pas de fermer le menu si plusieurs kernels ont été trouvé
|
||||||
|
# en: Don't forget to close menus if more than one kernel is found
|
||||||
if [ ${#nkernel[*]} != 1 ]; then echo " }"; fi
|
if [ ${#nkernel[*]} != 1 ]; then echo " }"; fi
|
||||||
done
|
done
|
||||||
echo "}"
|
echo "}"
|
||||||
|
|||||||
Reference in New Issue
Block a user