Compare commits

..

14 Commits

Author SHA1 Message Date
Antynea
5fe28d39be Merge remote-tracking branch 'origin/Development' 2015-06-02 15:59:34 +02:00
Antynea
5e8c722c6a v0.6 2015-06-02 15:58:46 +02:00
Antynea
91e72f60f8 Improve perfomance 2015-05-31 22:26:02 +02:00
Antynea
5bff1c80a7 Merge remote-tracking branch 'origin/Development' 2015-05-24 15:57:50 +02:00
Antynea
ed5e7ee6eb Improve snapshot detection 2015-05-23 16:06:05 +02:00
Antynea
1c4cac2397 Merge remote-tracking branch 'origin/Development' 2015-05-19 00:43:36 +02:00
Antynea
c4b9b3df95 Update README.md
Oops rollback last commit
2015-05-15 22:13:15 +02:00
Antynea
9fb9146e5b Update README.md
reflects change
2015-05-15 22:12:26 +02:00
Antynea
e61d0409ac Merge pull request #6 from penetal/patch-3
How to use /etc/default/grub config
2015-05-15 11:45:22 +02:00
Antynea
3f56de34ec Merge pull request #5 from penetal/patch-2
Pull config from /etc/default/grub
2015-05-15 11:44:14 +02:00
penetal
e0ef9c82e9 How to use /etc/default/grub config
How to change from default config via /etc/default/grub
2015-05-15 11:23:46 +02:00
penetal
788390cc93 Pull config from /etc/default/grub
Added parameter substitution so variables can be changed in /etc/default/grub.
This will let the script stay untouched, for easier updating.
2015-05-15 11:17:46 +02:00
Antynea
97dcaeae58 add warning 2015-05-14 00:38:10 +02:00
Antynea
8602220b98 Add warning 2015-05-13 23:59:07 +02:00
2 changed files with 63 additions and 53 deletions

View File

@@ -1,50 +1,58 @@
#! /bin/sh
#! /usr/bin/bash
set -e
. /usr/share/grub/grub-mkconfig_lib
. /etc/default/grub
### variables modifiable ###
## fr: nom du sous-menu
## en: Name of the submenu
submenuname="ArchLinux Snapshots"
## fr: préfixe de l'entrée
## en: Prefix entry
prefixentry="Snapshot"
## fr: nom(s) du ou des kernel(s)
## en: Name(s) of the kernel(s)
nkernel=("vmlinuz-linux")
## fr: nom(s) de(s) l'init
## en: Name(s) of the init(s)
ninit=("initramfs-linux.img" "initramfs-linux-fallback.img")
## fr: nom du microcode intel
## en: Name intel-ucode
intel_ucode=("intel-ucode.img")
######################################
### variables in /etc/default/grub ###
######################################
## Submenu name
submenuname=${GRUB_BTRFS_SUBMENUNAME:-"ArchLinux Snapshots"}
## Prefix entry
prefixentry=${GRUB_BTRFS_PREFIXENTRY:-"Snapshot"}
## Kernel(s) name(s)
nkernel=("${GRUB_BTRFS_NKERNEL[@]:-vmlinuz-linux}")
## Initramfs name(s)
ninit=("${GRUB_BTRFS_NINIT[@]:-initramfs-linux.img initramfs-linux-fallback.img}")
## Intel-ucode name(s)
intel_ucode=("${GRUB_BTRFS_INTEL_UCODE[@]:-intel-ucode.img}")
###########################
### fr: DÉBUT DU SCRIPT ###
### en: NAME OF SCRIPT ###
### fr: NE PAS TOUCHER ###
### en: DO NOT TOUCH ###
###########################
## fr: internationalisation
## en: Internationalization
########################
### variables script ###
########################
## Internationalization (default : english)
export TEXTDOMAIN=grub-btrfs-git
export TEXTDOMAINDIR="/usr/share/locale"
## 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)
## fr: uuid de la partition root
## en: UUID of the root partition
## UUID of the root partition
uuid=$(${grub_probe} "/" --target="fs_uuid" 2>/dev/null)
## fr: uuid de la partition boot
## en: UUID of the boot partition
## UUID of the boot partition
buuid=$(${grub_probe} --target="fs_uuid" "/boot" 2>/dev/null)
## fr: paramêtre passé au kernel
## en: Parameters passed to the kernel
## Parameters passed to the kernel
params="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
##############
### Script ###
##############
typeset -A date_time
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
# fr: on affiche le menu
# en: Display the menu
@@ -60,20 +68,15 @@ for kernel in ${nkernel[@]}; do
# en: If there are >1 kernels, create a menu
if [ ${#nkernel[*]} != 1 ]; then echo " submenu '$kernel' {
submenu '---> Kernel: $kernel <---' { echo }"; fi
# 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
# fr: On écarte les snapshots avec un statut de suppression
# en: Discard deleted snapshots
if [ $item = "DELETED" ]; then continue; fi
# fr: On traite la variable snapshots
# en: Treat the snapshots variable
for item in ${snapshots[@]}; do
# fr: affiche la liste des snapshots trouvés
# en: Output name of snapshot
gettext_printf $"Found Snapshot: %s\n" "$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)
# 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]' {"
echo " submenu '$prefixentry $item [${date_time[$item]}]' {"
# fr: si plusieurs kernel on été trouvé, on affiche un titre indicatif
# en: if more than one kernel is found, create a menu
if [ ${#nkernel[*]} != 1 ]; then echo " submenu '---> Kernel: $kernel <---' { echo }"; fi
@@ -133,4 +136,4 @@ for kernel in ${nkernel[@]}; do
# en: Don't forget to close menus if more than one kernel is found
if [ ${#nkernel[*]} != 1 ]; then echo " }"; fi
done
echo "}"
echo "}"

View File

@@ -1,9 +1,9 @@
### grub-btrfs
This is a version 0.xx of grub-btrfs :
This is a version 0.xx of grub-btrfs
#### Desciption
#### Description
grub-btrfs, add support for btrfs snapshots into grub menu
@@ -15,20 +15,27 @@ Makes a list of all snapshots, kernels, initramfs present on the filesystem and
#### How to use it :
1. Edit 41_snapshots-btrfs file :
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" )
* submenuname = name menu appear in grub ( e.g: submenuname="ArchLinux Snapshots" )
* prefixentry = add a name ahead your snapshots entries ( e.g: GRUB_BTRFS_PREFIXENTRY="Snapshot" )
* prefixentry = add a name ahead your snapshots entries ( e.g: prefixentry="Snapshot" )
* nkernel= name kernel you use it ( e.g: GRUB_BTRFS_NKERNEL=("vmlinuz-linux") )
* nkernel= name kernel you use it ( e.g: nkernel=("vmlinuz-linux") )
* ninit= name initramfs (ramdisk) you use it ( e.g: GRUB_BTRFS_NINIT=("initramfs-linux.img" "initramfs-linux-fallback.img") )
* ninit= name initramfs (ramdisk) you use it ( e.g: ninit=("initramfs-linux.img" "initramfs-linux-fallback.img") )
* intel_ucode= name intel microcode you use it ( e.g: intel_ucode=("intel-ucode.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]
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.