mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-03-10 00:05:32 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f7fb178fb | ||
|
|
d561206775 | ||
|
|
563151507d |
@@ -1,4 +1,35 @@
|
|||||||
#! /usr/bin/bash
|
#! /usr/bin/bash
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#########################################################################################################################################
|
||||||
|
# Written by: Antynea #
|
||||||
|
# #
|
||||||
|
# Purpose: Include btrfs snapshots at boot options. #
|
||||||
|
# #
|
||||||
|
# What this script does: #
|
||||||
|
# - List snapshots existing on root partition (btrfs). #
|
||||||
|
# - Create corresponding menuentry in grub.cfg , which ensures a very easy rollback. #
|
||||||
|
# #
|
||||||
|
# How to use it: #
|
||||||
|
# - Add this lines to /etc/default/grub: #
|
||||||
|
# #
|
||||||
|
# * GRUB_BTRFS_SUBMENUNAME="ArchLinux Snapshots" (Name menu appearing in grub.) #
|
||||||
|
# * GRUB_BTRFS_PREFIXENTRY="Snapshot" (Add a name ahead your snapshots entries.) #
|
||||||
|
# * GRUB_BTRFS_NKERNEL=("vmlinuz-linux") (Custom Name kernel you use it.) #
|
||||||
|
# * GRUB_BTRFS_NINIT=("initramfs-linux.img" "initramfs-linux-fallback.img") (Custom Name initramfs (ramdisk) you use it.) #
|
||||||
|
# * GRUB_BTRFS_INTEL_UCODE=("intel-ucode.img") (Custom Name intel microcode you use it.) #
|
||||||
|
# #
|
||||||
|
# - Generate grub.cfg (on Archlinux use grub-mkconfig -o /boot/grub/grub.cfg ) #
|
||||||
|
# #
|
||||||
|
# - grub-btrfs automatically generates snapshots entries. #
|
||||||
|
# - You will see it appear different entries, e.g : Prefixentry name of snapshot [2013-02-11 04:00:00] #
|
||||||
|
# #
|
||||||
|
# Warning: #
|
||||||
|
# This version detect kernels,initramfs,intel microcode only in boot partition, not in snapshot. #
|
||||||
|
# If those that are present in boot partition but not in snapshot, #
|
||||||
|
# entry will be created but not fonctional, you don't boot it. #
|
||||||
|
# #
|
||||||
|
#########################################################################################################################################
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
. /usr/share/grub/grub-mkconfig_lib
|
. /usr/share/grub/grub-mkconfig_lib
|
||||||
@@ -24,8 +55,7 @@ intel_ucode=("${GRUB_BTRFS_INTEL_UCODE[@]:-intel-ucode.img}")
|
|||||||
## Internationalization (default : english)
|
## Internationalization (default : english)
|
||||||
export TEXTDOMAIN=grub-btrfs-git
|
export TEXTDOMAIN=grub-btrfs-git
|
||||||
export TEXTDOMAINDIR="/usr/share/locale"
|
export TEXTDOMAINDIR="/usr/share/locale"
|
||||||
## fr: paramêtre des chaînes --hint
|
## hints string
|
||||||
## 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 of the root partition
|
## UUID of the root partition
|
||||||
uuid=$(${grub_probe} "/" --target="fs_uuid" 2>/dev/null)
|
uuid=$(${grub_probe} "/" --target="fs_uuid" 2>/dev/null)
|
||||||
@@ -54,40 +84,29 @@ for snap in $($bindir/btrfs subvolume list -sa / --sort=-ogen | $bindir/awk '{gs
|
|||||||
done
|
done
|
||||||
IFS=$oldIFS
|
IFS=$oldIFS
|
||||||
|
|
||||||
# fr: on affiche le menu
|
# Display the menu
|
||||||
# en: Display the menu
|
|
||||||
echo "submenu '$submenuname' {"
|
echo "submenu '$submenuname' {"
|
||||||
|
|
||||||
# fr: on traite la variable kernel
|
# Treat the kernel variables (Translation unclear)
|
||||||
# en: Treat the kernel variables (Translation unclear)
|
|
||||||
for kernel in ${nkernel[@]}; do
|
for kernel in ${nkernel[@]}; do
|
||||||
# fr: on test si le(s) nom(s) du(des) kernel existe(nt), autrement on affiche une erreur et on sort
|
# Check the specified kernel(s) exist, if it/they don't, display an error and exit
|
||||||
# en: Check the specified kernel(s) exist, if it/they don't, display an error and exit
|
|
||||||
if [ ! -f /boot/$kernel ]; then gettext_printf $"Error: /boot/$kernel, kernel does not exist" >&2; exit 1; fi
|
if [ ! -f /boot/$kernel ]; then gettext_printf $"Error: /boot/$kernel, kernel does not exist" >&2; exit 1; fi
|
||||||
# fr: on vérifie le nombre de kernel présent, si >1 on crée un menu
|
# If there are >1 kernels, create a 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
|
||||||
# fr: On traite la variable snapshots
|
# Treat the snapshots variable
|
||||||
# en: Treat the snapshots variable
|
|
||||||
for item in ${snapshots[@]}; do
|
for item in ${snapshots[@]}; do
|
||||||
# fr: affiche la liste des snapshots trouvés
|
# Output name of snapshot
|
||||||
# en: Output name of snapshot
|
|
||||||
gettext_printf $"Found Snapshot: %s\n" "$item ${date_time[$item]}" >&2
|
gettext_printf $"Found Snapshot: %s\n" "$item ${date_time[$item]}" >&2
|
||||||
# fr: on crée un menu pour chaque snapshot présent (nom + date de création)
|
# Create a menu for remaining snapshots (name + creation date)
|
||||||
# en: Create a menu for remaining snapshots (name + creation date)
|
|
||||||
echo " submenu '$prefixentry $item [${date_time[$item]}]' {"
|
echo " submenu '$prefixentry $item [${date_time[$item]}]' {"
|
||||||
# fr: si plusieurs kernel on été trouvé, on affiche un titre indicatif
|
# if more than one kernel is found, create a menu
|
||||||
# en: if more than one kernel is found, create a menu
|
|
||||||
if [ ${#nkernel[*]} != 1 ]; then echo " submenu '---> Kernel: $kernel <---' { echo }"; fi
|
if [ ${#nkernel[*]} != 1 ]; then echo " submenu '---> Kernel: $kernel <---' { echo }"; fi
|
||||||
# fr: on traite la variable de l'initramfs
|
# Treat the initramfs variable
|
||||||
# en: Treat the initramfs variables (Translation unclear)
|
|
||||||
for init in ${ninit[@]}; do
|
for init in ${ninit[@]}; do
|
||||||
# fr: on test si le(s) nom(s) du(des) initramfs existe(nt), autrement on affiche une erreur et on sort
|
# Check the specified initramfs(es) exist, if it/they don't, display an error and exit
|
||||||
# en: Check the specified initramfs(es) exist, if it/they don't, display an error and exit
|
|
||||||
if [ ! -f /boot/$init ]; then gettext_printf $"Error: /boot/$init, initramfs does not exist" >&2; exit 1; fi
|
if [ ! -f /boot/$init ]; then gettext_printf $"Error: /boot/$init, initramfs does not exist" >&2; exit 1; fi
|
||||||
# fr: on traite chaque entrée des snapshots avec leurs kernel et initramfs respectifs
|
# Specify a kernel and initramfs for every snapshot
|
||||||
# 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
|
||||||
@@ -98,14 +117,12 @@ 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 ...'"
|
||||||
# fr: on vérifie l'emplacement de la partition /boot
|
# Check the location of the /boot partition
|
||||||
# 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
|
||||||
echo 'Loading initial ramdisk ...'"
|
echo 'Loading initial ramdisk ...'"
|
||||||
# fr: on vérifie la présence du microcode intel
|
# Check intel microcode exist
|
||||||
# en: Check intel microcode exist
|
|
||||||
if [ -f /boot/$intel_ucode ]; then
|
if [ -f /boot/$intel_ucode ]; then
|
||||||
echo "\
|
echo "\
|
||||||
initrd /$item/boot/$intel_ucode /$item/boot/$init"
|
initrd /$item/boot/$intel_ucode /$item/boot/$init"
|
||||||
@@ -117,8 +134,7 @@ for kernel in ${nkernel[@]}; do
|
|||||||
echo "\
|
echo "\
|
||||||
linux /$kernel root=UUID=$uuid rw rootflags=subvol=$item $params
|
linux /$kernel root=UUID=$uuid rw rootflags=subvol=$item $params
|
||||||
echo 'Loading initial ramdisk ...'"
|
echo 'Loading initial ramdisk ...'"
|
||||||
# fr: on vérifie la présence du microcode intel
|
# Check intel microcode exist
|
||||||
# en: Check intel microcode exist
|
|
||||||
if [ -f /boot/$intel_ucode ]; then
|
if [ -f /boot/$intel_ucode ]; then
|
||||||
echo "\
|
echo "\
|
||||||
initrd /$intel_ucode /$init"
|
initrd /$intel_ucode /$init"
|
||||||
@@ -132,8 +148,7 @@ for kernel in ${nkernel[@]}; do
|
|||||||
done
|
done
|
||||||
echo " }"
|
echo " }"
|
||||||
done
|
done
|
||||||
# fr: on oubli pas de fermer le menu si plusieurs kernels ont été trouvé
|
# Don't forget to close menus if more than one kernel is found
|
||||||
# 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