#2662 PR merged: Cleanup of GRUB2 config code in particular for OUTPUT=USB

Labels: cleanup, fixed / solved / done

jsmeix opened issue at 2021-07-27 12:57:

Better GRUB2 menue entry names and 'timeout 300' so the user
can read and understand the GRUB2 menue entry names
(before it "just" boots one after only 5 seconds as it was before)
and cleanup of the get_root_disk_UUID function and
consistent calling of the create_grub2_cfg function always as

create_grub2_cfg "/path/to/kernel" "/path/to/initrd" >/path/to/grub.cfg

also in output/ISO/Linux-i386/250_populate_efibootimg.sh

jsmeix commented at 2021-07-28 13:30:

With the recent changes here up to
https://github.com/rear/rear/pull/2662/commits/d055f90199aee51a0ab3602ba3088e3b4aa52ece
things work OK for me as far as I tested.

On my homeoffice laptop
with UEFI in legacy BIOS mode
and a USB disk as /dev/sdb
with this etc/rear/local.conf

OUTPUT=USB
USB_DEVICE_FILESYSTEM_PERCENTAGE=10
USB_DEVICE_FILESYSTEM_LABEL='MY-DATA'
USB_BOOT_PART_SIZE=1024
USB_BOOTLOADER="grub"
USB_DEVICE_BOOT_LABEL=MY-BOOT
OUTPUT_URL=usb:///dev/disk/by-label/MY-BOOT
USB_DEVICE_PARTED_LABEL=gpt
BACKUP=NETFS
BACKUP_URL=usb:///dev/disk/by-label/MY-DATA

I get

# usr/sbin/rear -D format /dev/sdb
...
Repartitioning /dev/sdb
Creating partition table of type gpt on /dev/sdb
Creating BIOS boot partition /dev/sdb1
Setting 'bios_grub' flag on BIOS boot partition /dev/sdb1
Creating boot partition /dev/sdb2 with size 1024 MiB aligned at 8 MiB
Setting 'legacy_boot' flag on boot partition /dev/sdb2
Creating ReaR data partition /dev/sdb3 up to 10% of /dev/sdb
Creating ext2 filesystem with label 'MY-BOOT' on boot partition /dev/sdb2
Creating ext3 filesystem with label 'MY-DATA' on ReaR data partition /dev/sdb3
Adjusting filesystem parameters on ReaR data partition /dev/sdb3
Exiting rear format (PID 21762) and its descendant processes ...

# usr/sbin/rear -D mkbackup
...
Created initrd.cgz with gzip default compression (68593336 bytes) in 15 seconds
Using GRUB2 as USB bootloader for legacy BIOS boot on /dev/sdb (USB_BOOTLOADER='grub')
Installing GRUB2 as USB bootloader on /dev/sdb
Creating GRUB2 config for legacy BIOS boot as USB bootloader
Configuring GRUB2 kernel /rear/linux-h9wr/20210728.1514/kernel
Configuring GRUB2 initrd /rear/linux-h9wr/20210728.1514/initrd.cgz
Configuring GRUB2 root device as 'search --no-floppy --set=root --label MY-BOOT'
Saved /root/rear.github.master/var/log/rear/rear-linux-h9wr.log as rear/linux-h9wr/20210728.1514/rear-linux-h9wr.log
Making backup (using backup method NETFS)
Creating tar archive '/tmp/rear.cGwwQgh7eRSpMwP/outputfs/rear/linux-h9wr/20210728.1514/backup.tar.gz'
Preparing archive operation
OK
Exiting rear mkbackup (PID 22415) and its descendant processes ...

# parted -s /dev/sdb unit MiB print
Model: TOSHIBA External USB 3.0 (scsi)
Disk /dev/sdb: 476940MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
Number  Start    End       Size      File system  Name     Flags
 1      0.02MiB  8.00MiB   7.98MiB                primary  bios_grub
 2      8.00MiB  1032MiB   1024MiB   ext2         primary  legacy_boot
 3      1032MiB  47694MiB  46662MiB  ext3         primary

# lsblk -ipo NAME,TRAN,TYPE,FSTYPE,SIZE,LABEL /dev/sdb
NAME        TRAN TYPE FSTYPE   SIZE LABEL
/dev/sdb    usb  disk        465.8G 
|-/dev/sdb1      part            8M 
|-/dev/sdb2      part ext2       1G MY-BOOT
`-/dev/sdb3      part ext3    45.6G MY-DATA

# find /dev/disk/by-*/ -ls | grep 'MY-'
... /dev/disk/by-label/MY-DATA -> ../../sdb3
... /dev/disk/by-label/MY-BOOT -> ../../sdb2

# mount /dev/sdb2 /mnt

# cat /mnt/boot/grub2/grub.cfg
echo 'Processing GRUB2 configuration...'
sleep --verbose --interruptible 5
search --no-floppy --set=root --label MY-BOOT
set default="0"
insmod all_video
set gfxpayload=keep
insmod part_gpt
insmod part_msdos
insmod ext2
set timeout=300

menuentry "Relax-and-Recover (BIOS or UEFI in legacy BIOS mode)"  --class gnu-linux --class gnu --class os {
    insmod gzio
    echo 'Loading kernel /rear/linux-h9wr/20210728.1514/kernel ...'
    linux /rear/linux-h9wr/20210728.1514/kernel root=UUID=f05af948-6075-40a3-9191-354b0a0a9afc  selinux=0
    echo 'Loading initial ramdisk /rear/linux-h9wr/20210728.1514/initrd.cgz ...'
    initrd /rear/linux-h9wr/20210728.1514/initrd.cgz
}
menuentry "Boot from second disk hd1 (usually the original system disk)" {
    insmod chain
    set root=(hd1)
    chainloader +1
}
menuentry "Reboot" {
     reboot
}
menuentry "Exit (possibly continue bootchain)" {
     exit
}

Booting from that USB disk works well for me
on my other older x86_64 laptop with traditional BIOS
both booting the ReaR recovery system and
chainloading its bootloader on its built-in harddisk
to boot its original system.

jsmeix commented at 2021-07-28 13:50:

@pcahyna
if you find time for it I would much appreciate it
if you could test whether or not my changes here still work for you.

DEvil0000 commented at 2021-07-28 17:01:

@jsmeix Please add a config option for the timeout. My usecase is keeping the USB stick (or separate drive) in the machine and configure a 1s or 3s timout with default option chainload. So a normal boot is chained over the USB media and is quick on booting but one can still easily access the menu and recover without pluggin in a stick first.

jsmeix commented at 2021-07-29 11:05:

@DEvil0000
thank you for having a look here and for the description of your use case.
I implemented what you ask for via
https://github.com/rear/rear/pull/2662/commits/25f86d4f9cb320db637e65550830cb19a7fd2b02
and
https://github.com/rear/rear/pull/2662/commits/9a0daaa66fd19ce53bde46e9067c27c22666e6fe

jsmeix commented at 2021-07-29 11:06:

I will re-test if things still work OK for me with my recent changes.
My used etc/rear/local.conf:

OUTPUT=USB
USB_DEVICE_FILESYSTEM_PERCENTAGE=10
USB_DEVICE_FILESYSTEM_LABEL='MY-DATA'
USB_BOOT_PART_SIZE=1024
USB_BOOTLOADER="grub"
USB_DEVICE_BOOT_LABEL=MY-BOOT
OUTPUT_URL=usb:///dev/disk/by-label/MY-BOOT
USB_DEVICE_PARTED_LABEL=gpt
GRUB2_DEFAULT_BOOT="rear"
GRUB2_TIMEOUT=60
BACKUP=NETFS
BACKUP_URL=usb:///dev/disk/by-label/MY-DATA

and what grub.cfg I got created with that

search --no-floppy --set=root --label MY-BOOT
insmod all_video
set gfxpayload=keep
insmod part_gpt
insmod part_msdos
insmod ext2

set timeout="60"
set default="rear"
set fallback="chainloader"
echo 'Switching to GRUB2 boot menu...'
sleep --verbose --interruptible 3
menuentry "Relax-and-Recover (BIOS or UEFI in legacy BIOS mode)" --id=rear {
    insmod gzio
    echo 'Loading kernel /rear/linux-h9wr/20210729.1326/kernel ...'
    linux /rear/linux-h9wr/20210729.1326/kernel root=UUID=f05af948-6075-40a3-9191-354b0a0a9afc  selinux=0
    echo 'Loading initial ramdisk /rear/linux-h9wr/20210729.1326/initrd.cgz ...'
    initrd /rear/linux-h9wr/20210729.1326/initrd.cgz
}
menuentry "Boot from second disk hd1 (usually the original system disk)" --id=chainloader {
    insmod chain
    set root=(hd1)
    chainloader +1
}
menuentry "Reboot" --id=reboot {
    reboot
}
menuentry "Exit (possibly continue bootchain)" --id=exit {
    exit
}

jsmeix commented at 2021-07-29 11:40:

Because things still work OK for me with my recent changes
I would like to merge it right now (i.e. in an hour or so)
unless there are immediate objections
so that it can be tested by just using our current master code,
cf. "Testing current ReaR upstream GitHub master code" in
https://en.opensuse.org/SDB:Disaster_Recovery


[Export of Github issue for rear/rear.]