mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-03-04 21:15:02 +08:00
detect partition boot separate
check, ok
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
# #
|
||||
# What this script does: #
|
||||
# - Automatically List snapshots existing on root partition (btrfs). #
|
||||
# - Automatically detect kernel, initramfs and intel microcode in "/boot" directory on snapshots. (For custon name, see below.) #
|
||||
# - Automatically Detect kernel, initramfs and intel microcode in "/boot" directory on snapshots. (For custon name, see below.) #
|
||||
# - Automatically Create corresponding menuentry in grub.cfg , which ensures a very easy rollback. #
|
||||
# #
|
||||
# How to use it: #
|
||||
@@ -30,7 +30,7 @@
|
||||
# Script in progress #
|
||||
# to do : #
|
||||
# # #
|
||||
# * detect partition boot separate #
|
||||
# * verify compatibility with manjaro and snapper (but I don't use them, so it will take some time) #
|
||||
# #
|
||||
#########################################################################################################################################################
|
||||
|
||||
@@ -83,6 +83,13 @@ gbgmp="/tmp/gbgmp"
|
||||
CLASS="--class snapshots --class gnu-linux --class gnu --class os"
|
||||
## save IFS
|
||||
oldIFS=$IFS
|
||||
## grub path (auto-detect if /boot is separate partition or not)
|
||||
grub_path()
|
||||
{
|
||||
grub_path="$gbgmp/$snap_dir_name/boot"
|
||||
[[ root_uuid != boot_uuid ]] && grub_path="/boot"
|
||||
echo "$grub_path"
|
||||
}
|
||||
|
||||
|
||||
##############
|
||||
@@ -94,6 +101,7 @@ oldIFS=$IFS
|
||||
## menu entries
|
||||
snapshots_entry()
|
||||
{
|
||||
## \" required for snap,kernels,init,microcode with space in their name
|
||||
echo " submenu '${1} ${2} ${3}' {"
|
||||
for k in "${name_kernel[@]}"; do
|
||||
for i in "${name_initramfs[@]}"; do
|
||||
@@ -110,16 +118,16 @@ snapshots_entry()
|
||||
else
|
||||
search --no-floppy --fs-uuid --set=root ${boot_uuid}
|
||||
fi
|
||||
echo 'Loading Snapshot: ${snap_dir_name}'
|
||||
echo 'Loading Snapshot: "${snap_dir_name}" "${snap_date_time}"'
|
||||
echo 'Loading Kernel: "${k}" ...'
|
||||
linux \"/${snap_dir_name}/boot/"${k}"\" root=UUID=${root_uuid} rw rootflags=subvol=${snap_dir_name} ${kernel_parameters}
|
||||
linux \"/${snap_dir_name}/boot/"${k}"\" root=UUID=${root_uuid} rw rootflags=subvol=\""${snap_dir_name}"\" ${kernel_parameters}
|
||||
echo 'Loading Initramfs: "${i}" ...'"
|
||||
if [ -f "/${snap_dir_name}/boot/${microcode}" ] ; then
|
||||
if [ -f "/${snap_dir_name}/boot/"${microcode}"" ] ; then
|
||||
echo "\
|
||||
initrd \"/${snap_dir_name}/boot/${microcode}\" initrd \"/${snap_dir_name}/boot/${i}\""
|
||||
initrd \"/${snap_dir_name}/boot/"${microcode}"\" initrd \"/${snap_dir_name}/boot/"${i}"\""
|
||||
else
|
||||
echo "\
|
||||
initrd \"/${snap_dir_name}/boot/${i}\""
|
||||
initrd \"/${snap_dir_name}/boot/"${i}"\""
|
||||
fi
|
||||
echo " }"
|
||||
done
|
||||
@@ -144,14 +152,14 @@ snapshot_list()
|
||||
detect_kernel()
|
||||
{
|
||||
## Arch original kernel (auto-detect)
|
||||
for akernel in $snap_dir_boot/vmlinuz-* ; do
|
||||
for akernel in $(grub_path)/vmlinuz-* ; do
|
||||
list_kernel+=("$akernel")
|
||||
done
|
||||
|
||||
## Custom name kernel in GRUB_BTRFS_NKERNEL
|
||||
if [ ! -z ${nkernel} ] ; then
|
||||
for ckernel in "${nkernel[@]}" ; do
|
||||
[[ ! -f /${snap_dir_boot}/${ckernel} ]] && continue;
|
||||
[[ ! -f /$(grub_path)/${ckernel} ]] && continue;
|
||||
list_kernel+=("$ckernel")
|
||||
done
|
||||
fi
|
||||
@@ -160,14 +168,14 @@ detect_kernel()
|
||||
detect_initramfs()
|
||||
{
|
||||
## Arch original kernel (auto-detect)
|
||||
for ainitramfs in $snap_dir_boot/initramfs-* ; do
|
||||
for ainitramfs in $(grub_path)/initramfs-* ; do
|
||||
list_initramfs+=("$ainitramfs")
|
||||
done
|
||||
|
||||
## Custom name initramfs in GRUB_BTRFS_NINIT
|
||||
if [ ! -z ${ninit} ] ; then
|
||||
for cinitramfs in "${ninit[@]}" ; do
|
||||
[[ ! -f /${snap_dir_boot}/${ninit} ]] && continue;
|
||||
[[ ! -f /$(grub_path)/${ninit} ]] && continue;
|
||||
list_initramfs+=("$ninit")
|
||||
done
|
||||
fi
|
||||
@@ -176,40 +184,41 @@ detect_initramfs()
|
||||
## List of kernels and initramfs in snapshots
|
||||
list_kernels_initramfs()
|
||||
{
|
||||
[[ ! -d $gbgmp ]] && mkdir -p $gbgmp
|
||||
mount -o subvolid=0 /dev/disk/by-uuid/$root_uuid $gbgmp/
|
||||
echo "submenu '${submenuname}' {"
|
||||
IFS=$'\n'
|
||||
for item in $(snapshot_list); do
|
||||
IFS=$oldIFS
|
||||
item=($item)
|
||||
snap_dir_name=${item[@]:2:${#item[@]}}
|
||||
if [ -f $gbgmp/$snap_dir_name/boot/grub/grub.cfg ]; then
|
||||
snap_date_time=${item[@]:0:2}
|
||||
gettext_printf $"Found Snapshot: %s\n" "$snap_dir_name $snap_date_time" >&2 ;
|
||||
snap_dir_boot=$gbgmp/$snap_dir_name/boot
|
||||
unset list_kernel
|
||||
detect_kernel
|
||||
name_kernel=("${list_kernel[@]##*"/"}")
|
||||
# echo "kernel = ${name_kernel[*]}"
|
||||
unset list_initramfs
|
||||
detect_initramfs
|
||||
name_initramfs=("${list_initramfs[@]##*"/"}")
|
||||
# echo "initramfs = ${name_initramfs[*]}"
|
||||
fi
|
||||
# Create menu entries
|
||||
snapshots_entry "${prefixentry}" "${snap_dir_name}" "${snap_date_time}"
|
||||
done
|
||||
echo "}"
|
||||
if [ $root_uuid = $boot_uuid ] ; then
|
||||
[[ ! -d $gbgmp ]] && mkdir -p $gbgmp
|
||||
mount -o subvolid=0 /dev/disk/by-uuid/$root_uuid $gbgmp/
|
||||
fi
|
||||
IFS=$'\n'
|
||||
for item in $(snapshot_list); do
|
||||
IFS=$oldIFS
|
||||
item=($item)
|
||||
snap_dir_name=${item[@]:2:${#item[@]}}
|
||||
if [ -f $(grub_path)/grub/grub.cfg ]; then
|
||||
snap_date_time=${item[@]:0:2}
|
||||
gettext_printf $"# Found Snapshot: %s\n" "$snap_dir_name $snap_date_time" >&2 ;
|
||||
unset list_kernel
|
||||
detect_kernel
|
||||
name_kernel=("${list_kernel[@]##*"/"}")
|
||||
# echo "kernel = ${name_kernel[*]}"
|
||||
unset list_initramfs
|
||||
detect_initramfs
|
||||
name_initramfs=("${list_initramfs[@]##*"/"}")
|
||||
# echo "initramfs = ${name_initramfs[*]}"
|
||||
fi
|
||||
# Create menu entries
|
||||
snapshots_entry "${prefixentry}" "${snap_dir_name}" "${snap_date_time}"
|
||||
done
|
||||
IFS=$oldIFS
|
||||
umount $gbgmp
|
||||
if [ $root_uuid = $boot_uuid ] ; then umount $gbgmp ; fi
|
||||
}
|
||||
### END auto detect ###
|
||||
|
||||
### Choice of method ###
|
||||
if [ ${choise_of_method} = "1" ] ; then
|
||||
gettext_printf "###### - Grub-btrfs: Auto-detect - ######\n" >&2 ;
|
||||
echo "submenu '${submenuname}' {"
|
||||
list_kernels_initramfs ;
|
||||
echo "}"
|
||||
gettext_printf "###### - Grub-btrfs: Auto-detect - ######\n" >&2 ;
|
||||
fi
|
||||
### End choice of method ###
|
||||
Reference in New Issue
Block a user