mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-03-08 07:14:38 +08:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f7fb178fb | ||
|
|
d561206775 | ||
|
|
563151507d | ||
|
|
fda6eb8c00 | ||
|
|
2385312345 | ||
|
|
5fe28d39be | ||
|
|
5e8c722c6a | ||
|
|
91e72f60f8 | ||
|
|
5bff1c80a7 | ||
|
|
ed5e7ee6eb | ||
|
|
1c4cac2397 | ||
|
|
c4b9b3df95 | ||
|
|
9fb9146e5b | ||
|
|
e61d0409ac | ||
|
|
3f56de34ec | ||
|
|
e0ef9c82e9 | ||
|
|
788390cc93 | ||
|
|
97dcaeae58 | ||
|
|
8602220b98 | ||
|
|
7441e573f3 | ||
|
|
e06a8e1dd8 | ||
|
|
aeff81e861 | ||
|
|
876d1c5e98 | ||
|
|
4fb1f71b17 | ||
|
|
b80c04a751 | ||
|
|
11af1f69ba | ||
|
|
5ca00a1aa2 | ||
|
|
a1b876188c | ||
|
|
50f63a9bec | ||
|
|
a10f775b8d | ||
|
|
7ebfbe05f9 | ||
|
|
eeae1d3084 | ||
|
|
6a76ec8837 |
@@ -1,83 +1,112 @@
|
|||||||
#! /bin/sh
|
#! /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
|
||||||
. /etc/default/grub
|
. /etc/default/grub
|
||||||
|
|
||||||
### variables modifiable ###
|
######################################
|
||||||
## fr: nom du sous-menu
|
### variables in /etc/default/grub ###
|
||||||
## en: Name of the submenu
|
######################################
|
||||||
submenuname="ArchLinux Snapshots"
|
## Submenu name
|
||||||
## fr: préfixe de l'entrée
|
submenuname=${GRUB_BTRFS_SUBMENUNAME:-"ArchLinux Snapshots"}
|
||||||
## en: Prefix entry
|
## Prefix entry
|
||||||
prefixentry="Snapshot"
|
prefixentry=${GRUB_BTRFS_PREFIXENTRY:-"Snapshot"}
|
||||||
## fr: nom(s) du ou des kernel(s)
|
## Kernel(s) name(s)
|
||||||
## en: Name(s) of the kernel(s)
|
nkernel=("${GRUB_BTRFS_NKERNEL[@]:-vmlinuz-linux}")
|
||||||
nkernel=("vmlinuz-linux")
|
## Initramfs name(s)
|
||||||
## fr: nom(s) de(s) l'init
|
ninit=("${GRUB_BTRFS_NINIT[@]:-initramfs-linux.img initramfs-linux-fallback.img}")
|
||||||
## en: Name(s) of the init(s)
|
## Intel-ucode name(s)
|
||||||
ninit=("initramfs-linux.img" "initramfs-linux-fallback.img")
|
intel_ucode=("${GRUB_BTRFS_INTEL_UCODE[@]:-intel-ucode.img}")
|
||||||
|
|
||||||
|
########################
|
||||||
###########################
|
### variables script ###
|
||||||
### fr: DÉBUT DU SCRIPT ###
|
########################
|
||||||
### en: NAME OF SCRIPT ###
|
## Internationalization (default : english)
|
||||||
### fr: NE PAS TOUCHER ###
|
export TEXTDOMAIN=grub-btrfs-git
|
||||||
### en: DO NOT TOUCH ###
|
export TEXTDOMAINDIR="/usr/share/locale"
|
||||||
###########################
|
## hints string
|
||||||
## 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)
|
||||||
## fr: uuid de la partition root
|
## UUID of the root partition
|
||||||
## en: UUID of the root partition
|
|
||||||
uuid=$(${grub_probe} "/" --target="fs_uuid" 2>/dev/null)
|
uuid=$(${grub_probe} "/" --target="fs_uuid" 2>/dev/null)
|
||||||
## fr: uuid de la partition boot
|
## UUID of the boot partition
|
||||||
## 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)
|
||||||
## fr: paramêtre passé au kernel
|
## Parameters passed to the kernel
|
||||||
## en: Parameters passed to the kernel
|
|
||||||
params="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
|
params="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
|
||||||
|
|
||||||
|
##############
|
||||||
|
### Script ###
|
||||||
|
##############
|
||||||
|
|
||||||
# fr: on affiche le menu
|
typeset -A date_time
|
||||||
# en: Display the menu
|
unset snapshots
|
||||||
|
|
||||||
|
# Create list of filesystem snapshots
|
||||||
|
oldIFS=$IFS
|
||||||
|
IFS=$'\n'
|
||||||
|
|
||||||
|
for snap in $($bindir/btrfs subvolume list -sa / --sort=-ogen | $bindir/awk '{gsub(/^.*<FS_TREE>\//,"",$NF);print $11" "$12"?"$NF}'); do
|
||||||
|
snap_name="${snap#*"?"}"
|
||||||
|
# Discard deleted snapshots
|
||||||
|
if [ $snap_name = "DELETED" ]; then continue; fi
|
||||||
|
snapshots+=("$snap_name")
|
||||||
|
date_time[$snap_name]="${snap%"?"*}"
|
||||||
|
done
|
||||||
|
IFS=$oldIFS
|
||||||
|
|
||||||
|
# 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 echo "/boot/$kernel: fr: Fichier inexistant en: File does not exist" >&2; exit 1; fi
|
# If there are >1 kernels, create a menu
|
||||||
# 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
|
||||||
|
# Treat the snapshots variable
|
||||||
# fr: On liste les snapshots présent sur le système de fichier
|
for item in ${snapshots[@]}; do
|
||||||
# en: List filesystem snapshots
|
# Output name of snapshot
|
||||||
for item in $($bindir/btrfs subvolume list -s / --sort=-ogen | $bindir/awk '{print $NF}'); do
|
gettext_printf $"Found Snapshot: %s\n" "$item ${date_time[$item]}" >&2
|
||||||
# fr: On écarte les snapshots avec un statut de suppression
|
# Create a menu for remaining snapshots (name + creation date)
|
||||||
# en: Discard deleted snapshots
|
echo " submenu '$prefixentry $item [${date_time[$item]}]' {"
|
||||||
if [ $item = "DELETED" ]; then continue; fi
|
# if more than one kernel is found, create a menu
|
||||||
# fr: affiche la liste des snapshots trouvés
|
|
||||||
# en: Output name of snapshot
|
|
||||||
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
|
||||||
# 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 echo "/boot/$init: Fichier inexistant" >&2; exit 1; fi
|
# Specify a kernel and initramfs for every snapshot
|
||||||
# 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
|
||||||
@@ -88,26 +117,38 @@ 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 ...'"
|
||||||
|
# Check intel microcode exist
|
||||||
|
if [ -f /boot/$intel_ucode ]; then
|
||||||
|
echo "\
|
||||||
|
initrd /$item/boot/$intel_ucode /$item/boot/$init"
|
||||||
|
else
|
||||||
|
echo "\
|
||||||
initrd /$item/boot/$init"
|
initrd /$item/boot/$init"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
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 ...'"
|
||||||
|
# Check intel microcode exist
|
||||||
|
if [ -f /boot/$intel_ucode ]; then
|
||||||
|
echo "\
|
||||||
|
initrd /$intel_ucode /$init"
|
||||||
|
else
|
||||||
|
echo "\
|
||||||
initrd /$init"
|
initrd /$init"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
echo "\
|
echo "\
|
||||||
}"
|
}"
|
||||||
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 "}"
|
||||||
|
|||||||
41
README.md
41
README.md
@@ -1,4 +1,41 @@
|
|||||||
grub-btrfs
|
### grub-btrfs
|
||||||
==========
|
|
||||||
|
|
||||||
|
This is a version 0.xx of grub-btrfs
|
||||||
|
|
||||||
|
#### Description
|
||||||
|
|
||||||
grub-btrfs, add support for btrfs snapshots into grub menu
|
grub-btrfs, add support for btrfs snapshots into grub menu
|
||||||
|
|
||||||
|
#### What does grub-btrfs v0.xx do :
|
||||||
|
|
||||||
|
Simple rollback using snapshots you made previous.
|
||||||
|
|
||||||
|
Makes a list of all snapshots, kernels, initramfs present on the filesystem and then creates a corresponding entered with name and date of snapshots in grub.cfg, which ensures a very easy rollback.
|
||||||
|
|
||||||
|
#### How to use it :
|
||||||
|
|
||||||
|
1. Add lines to /etc/default/grub as needed, defaults listed as examples:
|
||||||
|
2.
|
||||||
|
* submenuname = name menu appear in grub ( e.g: GRUB_BTRFS_SUBMENUNAME="ArchLinux Snapshots" )
|
||||||
|
|
||||||
|
* prefixentry = add a name ahead your snapshots entries ( e.g: GRUB_BTRFS_PREFIXENTRY="Snapshot" )
|
||||||
|
|
||||||
|
* nkernel= name kernel you use it ( e.g: GRUB_BTRFS_NKERNEL=("vmlinuz-linux") )
|
||||||
|
|
||||||
|
* ninit= name initramfs (ramdisk) you use it ( e.g: GRUB_BTRFS_NINIT=("initramfs-linux.img" "initramfs-linux-fallback.img") )
|
||||||
|
|
||||||
|
* intel_ucode= name intel microcode you use it ( e.g: GRUB_BTRFS_INTEL_UCODE=("intel-ucode.img") )
|
||||||
|
|
||||||
|
2. Generate grub.cfg (on Archlinux is 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
|
||||||
|
|
||||||
|
Version 0.xx detect kernels,initramfs,intel microcode only in boot partition, not in snapshot.
|
||||||
|
If kernels,initramfs,intel microcode, are present in boot partition but not in snapshot, entry will be created but not fonctional, you don't boot it.
|
||||||
|
|
||||||
|
Version 1.xx will do it, release soon.
|
||||||
|
|||||||
BIN
localisation/fr/grub-btrfs-git.mo
Normal file
BIN
localisation/fr/grub-btrfs-git.mo
Normal file
Binary file not shown.
Reference in New Issue
Block a user