Make grub boot entry to load recovery menu
Using Lubuntu 22.04 LTS
I'm trying to add a grub entry that would be able to load a menu. This menu should have 4 options:
- Backup sda
dd if=/dev/nvme0n1 of=/mnt/data/backup/nvme0n1.img bs=4M conv=noerror status=progress
- Restore sda
dd if=/mnt/data/backup/nvme0n1.img of=/dev/nvme0n1 bs=4M conv=noerror status=progress
- Back to grub root menu
- Reboot
I've found here how to make a bash script to make a menu that would use dd to backup or restore my system disk. Here's what I made of it:
#!/bin/sh
show_menu(){
normal=`echo "\033[m"`
menu=`echo "\033[36m"` #Blue
number=`echo "\033[33m"` #yellow
bgred=`echo "\033[41m"`
fgred=`echo "\033[31m"`
printf "\n${menu}*********************************************${normal}\n"
printf "${menu}**${number} 1)${menu} Backup sda ${normal}\n"
printf "${menu}**${number} 2)${menu} Restore sda ${normal}\n"
printf "${menu}**${number} 3)${menu} Restart computer ${normal}\n"
printf "${menu}**${number} 4)${menu} Back to grub ${normal}\n"
printf "${menu}**${number} 5)${menu} Test${normal}\n"
printf "${menu}*********************************************${normal}\n"
printf "Please enter a menu option and enter or ${fgred}x to exit. ${normal}"
read opt
}
option_picked(){
msgcolor=`echo "\033[01;31m"` # bold red
normal=`echo "\033[00;00m"` # normal white
message=${@:-"${normal}Error: No message passed"}
printf "${msgcolor}${message}${normal}\n"
}
clear
show_menu
while [ $opt != '' ]
do
if [ $opt = '' ]; then
exit;
else
case $opt in
1) clear;
option_picked "Option 1 Picked";
dd if=/dev/nvme0n1 of=/mnt/data/backup/nvme0n1.img bs=4M conv=noerror status=progress;
show_menu;
;;
2) clear;
option_picked "Option 2 Picked";
dd if=/mnt/data/backup/nvme0n1.img of=/dev/nvme0n1 bs=4M conv=noerror status=progress;
show_menu;
;;
3) clear;
option_picked "Option 3 Picked";
"back to root menu";
show_menu;
;;
4) clear;
option_picked "Option 4 Picked";
reboot;
show_menu;
;;
x)exit;
;;
\n)exit;
;;
*)clear;
option_picked "Pick an option from the menu";
show_menu;
;;
esac
fi
done
Results of this bash script on an Ubuntu server run:
It could do the trick, but it's not easy I've made a mistake with the disk and file locations probably, because my system couldn't start anymore. I was good for reinstalling it.
I would like to have such a menu entry into my default grub. Therefor I thought I could add an entry into /etc/grub.d/40.custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry 'Lubuntu Root Terminal' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-5bba636c-5b61-4ef9-857b-c5d4bf51c2cd' {
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_gpt
insmod ext2
search --no-floppy --fs-uuid --set=root 5bba636c-5b61-4ef9-857b-c5d4bf51c2cd
linux /boot/vmlinuz-5.15.0-37-generic root=UUID=5bba636c-5b61-4ef9-857b-c5d4bf51c2cd \ ro init=/bin/bash rw $vt_handoff
initrd /boot/initrd.img-5.15.0-37-generic
}
I didn't get the system to boot into terminal with this menu entry yet. I probably did something wrong.
I'm looking how to add TTY options in my grub menu trough this entry, but do not find how exactly. I would like to know how to mount the system as root and launch the shell with the made bash for example.
Ubuntu server minimal on a small partition of the same disk. From there I'll try to setup the bash to launch. The problem is that the server commands and configuration seems different. I can't get my raid-0 partition to work/map. So I do not have access to my files to test.
I tried to build a custom kernel I've made a mistake installing these packages after the building. The point was to build a kernel on the recovery partition that doesn't contain the X11 modules. It is to complicated procedure for me it seems. I had trouble with certificates and at the installed the packages on my system, what crashed everything.
TTS0 grub entry: I've also found information about a terminal TTS0 session I could add to the grub. But when I select it on boot, I just run into my system like usual.
Here is my custom grub entry TTYS0:
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_gpt
insmod ext2
set root='hd0,gpt2'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint='hd0,gpt2' adf801ee-4bd7-4e13-aeef-210e10ef58e8
else
search --no-floppy --fs-uuid --set=root adf801ee-4bd7-4e13-aeef-210e10ef58e8
fi
linux /boot/vmlinuz-5.15.0-25-generic root=UUID=adf801ee-4bd7-4e13-aeef-210e10ef58e8 ro quiet splash $vt_handoff vga=787 console=tty0 console=ttyS0,115200n8
initrd /boot/initrd.img-5.15.0-25-generic
I understand know I have more as one question here:
What is best:
a. A grub to terminal that launches my script menu ?
b. A separate system boot to clone partitions ?
How to add a grub entry that enter TTY to load a bash script?
Or how do I build custom kernel (If it is a correct alternative) to boot without desktop my same install on another partition and adding this entry to the boot.
The information I found on Help Ubuntu suggests a way to backup my system with dd. I'm looking for something already available, small and accessible trough command line with the bash.
I would like help on the make command to get the right config for my purposed build.
or
I would like help on the way to add a grub entry that uses my current system TTY to load the menu bash at boot.
Is there a way to do any of these?
I found a pretty example to start with : Clonezilla on HD
I added this to /etc/grub.d/40_custom with Grub Customizer following the instructions:
menuentry "Clonezilla" {
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_gpt
insmod ext2
set root=(hd0,gpt1)
linux /recovery/vmlinuz boot=live union=overlay username=user config components quiet noswap nolocales edd=on nomodeset ocs_live_run=\"ocs-live-general\" ocs_live_extra_param=\"\" keyboard-layouts= ocs_live_batch=\"no\" locales= vga=788 ip=frommedia nosplash live-media-path=/recovery bootfrom=/dev/nvme0n1 toram=recovery,syslinux,EFI
initrd /recovery/initrd.img
}
This is the Linux system disk partition information:
nvme0n1 259:0 0 119.2G 0 disk
├─nvme0n1p1 259:1 0 26.1G 0 part
├─nvme0n1p2 259:2 0 87.9G 0 part /
└─nvme0n1p3 259:3 0 5.3G 0 part /boot/efi
- p1 is the recovery partiton
- p2 is the lubuntu root partition
- p3 is the efi-boot partition
When I try to start this boot entry, it creates a new one. When I try the new one, I get an error it can't find the boot files needed.
Here's the content my recovery partition:
ls /mnt/recovery
amd64-release.txt EFI live
boot GPL lost+found
clonezilla-live-20220522-jammy-amd64.zip home syslinux
Clonezilla-Live-Version linux-5.18.4.tar.xz utils
I presume it comes from the grub entry path that isn't right. I'm not sure what has to filled in this value ...
bootfrom=/dev/nvme0n1
or
bootfrom=/dev/nvme0n1p1
I found the errors in the folder name, that should change to "live-hd" instead of "live" and edited the grub entry as follow:
I took the information of the Lubuntu's grub entry and changed the disk id's based on what I could see in the gnome-disk-utility and removed the commands recordfail - load_video - gfxmode $linux_gfx_mode
.
menuentry "Clonezilla" {
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_gpt
insmod ext2
set root=(hd0,gpt1)
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint='hd0,gpt1' 22d397bb-9bf4-4486-a84f-e2b193a49e85
else
search --no-floppy --fs-uuid --set=root 22d397bb-9bf4-4486-a84f-e2b193a49e85
fi
linux /live-hd/vmlinuz boot=live union=overlay username=user config components quiet noswap nolocales edd=on nomodeset ocs_live_run=\"ocs-live-general\" ocs_live_extra_param=\"\" keyboard-layouts= ocs_live_batch=\"no\" locales= vga=788 ip=frommedia nosplash live-media-path=/live-hd bootfrom=/dev/nvme0n1p1 toram=live-hd,syslinux,EFI
initrd /live-hd/initrd.img
}
After that, I selected Clonezilla what made a new entry in the grub menu with the same name:
So I tried to boot on the new entry, and it worked fine, but why does it make this second entry first ?
The point is it boots, and I could clone the system partition of the disk where the Clonezilla is installed as recovery partition.
At top of that, I was gladly surprised that Clonezilla has detected my FakeRaid and the partitions on it without any additional settings. I could save the image on it without inconvenience.
It took approximately 10 minutes with the verification included. Now I'm still searching how to make it a menu to choose between backup or restore only, with always the same source and destination alternatively. I presume this must be possible, so I continue my research.
sudo update-grub
to actually generate a new GRUB menu? Also consider usinggrub-emu
to check everything without rebooting, which is also a safer way. unix.stackexchange.com/questions/405515/…