Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifications for USB_BOOTLOADER="grub" #2659

Merged
merged 14 commits into from Jul 27, 2021
Merged

Conversation

jsmeix
Copy link
Member

@jsmeix jsmeix commented Jul 20, 2021

  • Type: Enhancement

  • Impact: Normal

  • Reference to related issue (URL):
    added grub bootloader for USB #2655

  • How was this pull request tested?
    Not at all tested by me

  • Brief description of the changes in this pull request:

Simplifications for USB_BOOTLOADER="grub"

Simplified test when output/USB/Linux-i386/300_create_extlinux.sh is skipped
because GRUB2 is specified to be used as USB bootloader and have that test
at the very beginning of 300_create_extlinux.sh to completely skip it.
@jsmeix jsmeix added the enhancement Adaptions and new features label Jul 20, 2021
@jsmeix jsmeix added this to the ReaR v2.7 milestone Jul 20, 2021
@jsmeix jsmeix requested a review from a team July 20, 2021 09:01
@jsmeix jsmeix self-assigned this Jul 20, 2021
Simpler and more straightforward code in output/USB/Linux-i386/300_create_grub.sh
Simplified test when output/USB/Linux-i386/850_make_USB_bootable.sh is skipped
because GRUB2 is specified to be used as USB bootloader
@jsmeix jsmeix changed the title Some minor improvements for USB_BOOTLOADER="grub" Simplifications for USB_BOOTLOADER="grub" Jul 20, 2021
In default.conf tell that USB_BOOTLOADER="grub" uses GRUB2 as bootloader for USB
and that GRUB1 is not supported.
Use local variables actually as local variables.
Tell that grub2_set_usb_root is a global variable
that is used in the create_grub2_cfg() function
Better wording in default.conf that USB_BOOTLOADER="grub"
is only for systems "with BIOS" and that
"GRUB Legacy" (not "GRUB1") is not supported.
To be on the safe side have the label "REARBOOT" only 8 characters long.
Use GRUB2_SET_USB_ROOT instead of grub2_set_usb_root for that global variable
Use GRUB2_SET_USB_ROOT instead of grub2_set_usb_root for that global variable
Use GRUB2_SET_USB_ROOT instead of grub2_set_usb_root for that global variable
Comment that explains where the $BUILD_DIR/outputfs/$USB_PREFIX directory is needed.
@jsmeix jsmeix added the cleanup label Jul 23, 2021
@jsmeix
Copy link
Member Author

jsmeix commented Jul 23, 2021

This pull request is a part of #2648

Choose the right GRUB2 config depending on what there is on the original system
and error out here if there is neither /boot/grub/grub.cfg nor /boot/grub2/grub.cfg
grub[2]-install creates the $BUILD_DIR/outputfs/boot/grub[2] sub-directory that is needed
to create the GRUB2 config $BUILD_DIR/outputfs/boot/grub[2].cfg in the next step
@jsmeix
Copy link
Member Author

jsmeix commented Jul 26, 2021

With the recent adaptions
USB_BOOTLOADER="grub" works in a basic way for me
on my older x86_64 laptop with traditional BIOS
with a separated boot partition
with GPT partitioning
on openSUSE Leap 15.2 that has /boot/grub2 (but no /boot/grub).

With 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 21208) and its descendant processes ...

# usr/sbin/rear -D mkbackup
...
Created initrd.cgz with gzip default compression (68582767 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
Saved /root/rear.github.master/var/log/rear/rear-linux-h9wr.log as rear/linux-h9wr/20210726.1506/rear-linux-h9wr.log
Making backup (using backup method NETFS)
Creating tar archive '/tmp/rear.l5lqCsqFVPTjR6o/outputfs/rear/linux-h9wr/20210726.1506/backup.tar.gz'
Preparing archive operation
OK
Exiting rear mkbackup (PID 21898) and its descendant processes ...

# usr/sbin/rear -D mkbackup
...
Created initrd.cgz with gzip default compression (68580499 bytes) in 14 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
Saved /root/rear.github.master/var/log/rear/rear-linux-h9wr.log as rear/linux-h9wr/20210726.1508/rear-linux-h9wr.log
Making backup (using backup method NETFS)
Creating tar archive '/tmp/rear.9fHYUxaJSUPH3EX/outputfs/rear/linux-h9wr/20210726.1508/backup.tar.gz'
Preparing archive operation
OK
Exiting rear mkbackup (PID 14065) 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 ; find /mnt ; umount /mnt
/mnt
/mnt/lost+found
/mnt/boot
/mnt/boot/grub2
/mnt/boot/grub2/grub.cfg
/mnt/boot/grub2/i386-pc
/mnt/boot/grub2/i386-pc/xnu.mod
...
/mnt/boot/grub2/i386-pc/ufs2.mod
/mnt/boot/grub2/fonts
/mnt/boot/grub2/fonts/unicode.pf2
/mnt/boot/grub2/grubenv
/mnt/linux-h9wr
/mnt/rear
/mnt/rear/linux-h9wr
/mnt/rear/linux-h9wr/20210726.1506
/mnt/rear/linux-h9wr/20210726.1506/kernel
/mnt/rear/linux-h9wr/20210726.1506/initrd.cgz
/mnt/rear/linux-h9wr/20210726.1506/rear-linux-h9wr.log
/mnt/rear/linux-h9wr/20210726.1508
/mnt/rear/linux-h9wr/20210726.1508/kernel
/mnt/rear/linux-h9wr/20210726.1508/initrd.cgz
/mnt/rear/linux-h9wr/20210726.1508/rear-linux-h9wr.log

# mount /dev/sdb3 /mnt ; find /mnt ; umount /mnt
/mnt
/mnt/lost+found
/mnt/rear
/mnt/rear/linux-h9wr
/mnt/rear/linux-h9wr/20210726.1506
/mnt/rear/linux-h9wr/20210726.1506/backup.log
/mnt/rear/linux-h9wr/20210726.1506/backup.tar.gz
/mnt/rear/linux-h9wr/20210726.1508
/mnt/rear/linux-h9wr/20210726.1508/backup.log
/mnt/rear/linux-h9wr/20210726.1508/backup.tar.gz

That USB disk boots with GRUB2
on my older x86_64 laptop with traditional BIOS.
The ReaR recovery system starts up and is usable.

What does not yet work is:

Selection in the GRUB2 boot menue what to boot i.e.
the recovery system and backup dated 20210726.1506
or the recovery system and backup dated 20210726.1508
Currently only the last one can be booted because
e.g. im my case the created boot/grub2/grub.cfg contains

menuentry "Relax-and-Recover (no Secure Boot)"  --class gnu-linux --class gnu --class os {
     echo 'Loading kernel ...'
     linux /rear/linux-h9wr/20210726.1508/kernel root=UUID=f05af948-6075-40a3-9191-354b0a0a9afc  selinux=0
     echo 'Loading initial ramdisk ...'
     initrd /rear/linux-h9wr/20210726.1508/initrd.cgz
}

menuentry "Relax-and-Recover (Secure Boot)"  --class gnu-linux --class gnu --class os {
     echo 'Loading kernel ...'
     linuxefi /rear/linux-h9wr/20210726.1508/kernel root=UUID=f05af948-6075-40a3-9191-354b0a0a9afc  selinux=0
     echo 'Loading initial ramdisk ...'
     initrdefi /rear/linux-h9wr/20210726.1508/initrd.cgz
}

Booting the existing system from the built-in local harddisk does not work
because e.g. im my case the created boot/grub2/grub.cfg contains

menuentry "Boot original system" {
    search --fs-uuid --no-floppy --set=esp 
    chainloader ($esp)
}

The GRUB2 default is to boot the recovery system via
Relax-and-Recover (no Secure Boot)

@jsmeix
Copy link
Member Author

jsmeix commented Jul 26, 2021

I think some things will get already fixed by
#2661

So my plan is to merge this pull request here soon
so that I can then merge #2661
and then I will re-test how things behave in particular with
SUSE and openSUSE systems that have things like
grub2-install (but no grub-install) and /boot/grub2 (but no /boot/grub).

@jsmeix
Copy link
Member Author

jsmeix commented Jul 26, 2021

@rear/contributors
if there are no objections
I would like to merge this pull request tomorrow morning.

@DEvil0000
Copy link
Contributor

you are correct, #2661 fixes some of the issues you face with grub config.
Just for additional explanation:
"Relax-and-Recover (no Secure Boot)" is correct in case you don't use EFI and should work for EFI with secure boot disabled.
"Relax-and-Recover (Secure Boot)" only works with EFI (and you may need secure boot enabled).
The mentioned PR makes this a bit more clear and fixes some other things around EFI/no EFI and serial config.

@jsmeix jsmeix merged commit 93a53b0 into master Jul 27, 2021
@jsmeix jsmeix deleted the jsmeix-improve-GRUB2-USB branch July 27, 2021 09:00
@jsmeix jsmeix mentioned this pull request Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants