bugGNU GRUB - Bugs: bug #63476, configuration getting damaged...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #63476: configuration getting damaged after embedding it using grub-mkimage

Submitter:  Kareem Zarka <the_zarka>
Submitted:  Tue 06 Dec 2022 11:29:03 AM UTC
   
 
Category:  Installation Severity:  Major
Priority:  5 - Normal Item Group:  Software Error
Status:  None Privacy:  Public
Assigned to:  None Originator Name:  Kareem Zarka
Open/Closed:  Open Release:  2.00
Release:  Reproducibility:  Every Time
Planned Release:  None

Tue 06 Dec 2022 11:29:03 AM UTC, original submission:  

Hi I'm using grub 2.00
after the process of embedding an early configuration file into the grub's binary the configuration file loses some lines from it
something is going wrong with parsing
during this command
```
grub-mkimage -v -c ../cfg -p ${EFIDIR} -d ./grub-core/ \
               -O ${GRUB_TARGET}-efi -o ./${GRUB_IMAGE_PREFIX}${GRUB_IMAGE} \
               ${GRUB_MKIMAGE_MODULES}
```
my cfg file is the following

```
# SPDX-FileCopyrightText: Huawei Inc.
#
# SPDX-License-Identifier: MIT

# NOTE: This file is referenced from x-gpt-efi-disk.wks.in
# Please be careful when moving it around the tree.

serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1

set CMDLINE="console=@SERIAL_CONSOLES@ panic=60 rootwait quiet"

# Find the boot partition. We need to know where to load from and save the
# environment to. The boot partition is saved into the ONIRO_GRUB_BOOT
# variable.
#
# TODO: switch to out-of-tree search by partition type uuid.
#
# XXX: the boot string is hard-coded but the .wks file allows customization via
# BOOT_PARTITION_LABEL, which is unsupported here.
if search --label --set ONIRO_BOOT_PART --no-floppy --hint-efi=hd0,gpt1 boot; then
    echo "note: found ONIRO_BOOT_PART=$ONIRO_BOOT_PART"
else
    echo "error: cannot find boot partition, halting"
    halt
fi

# Load a specific list of GRUB variables from the grubenv file. Ideally we
# would never have this and we would use EFI variables instead but this is not
# supported by RAUC without opting out of using GRUB itself.
load_env --skip-sig --file "(${ONIRO_BOOT_PART})/EFI/BOOT/grubenv" SYSOTA_BOOT_ACTIVE SYSOTA_BOOT_TRY SYSOTA_BOOT_TRIED
echo "note: loaded SYSOTA_BOOT_ACTIVE=$SYSOTA_BOOT_ACTIVE SYSOTA_BOOT_TRY=$SYSOTA_BOOT_TRY SYSOTA_BOOT_TRIED=$SYSOTA_BOOT_TRIED"

# Recover active slot if the file is corrupted.
if [ -z "$SYSOTA_BOOT_ACTIVE" ]; then
    echo "warning: SYSOTA_BOOT_ACTIVE is unset, attempting recovery"
    if [ -e "(hd0,gpt2)/boot/@KERNEL_IMAGETYPE@" -a -e "(hd0,gpt3)/boot/@KERNEL_IMAGETYPE@" ]; then
        # Both slots are available, pick the more recent slot.
        # TODO: handle rollback prevention flags (how?)
        if [ "(hd0,gpt2)/boot/@KERNEL_IMAGETYPE@" -nt "(hd0,gpt3)/boot/@KERNEL_IMAGETYPE@" ]; then
            echo "note: recovered SYSOTA_BOOT_ACTIVE=A (slot A kernel is newer than slot B)"
            set SYSOTA_BOOT_ACTIVE="A"
        else
            echo "note: recovered SYSOTA_BOOT_ACTIVE=B (slot B kernel is newer than slot A)"
            set SYSOTA_BOOT_ACTIVE="B"
        fi
    elif [ -e "(hd0,gpt2)/boot/@KERNEL_IMAGETYPE@" ]; then
        echo "note: recovered SYSOTA_BOOT_ACTIVE=A"
        set SYSOTA_BOOT_ACTIVE="A"
    elif [ -e "(hd0,gpt3)/boot/@KERNEL_IMAGETYPE@" ]; then
        echo "note: recovered SYSOTA_BOOT_ACTIVE=B"
        set SYSOTA_BOOT_ACTIVE="B"
    else
        echo "error: cannot recover GRUB environment block: both slots are corrupted, halting"
        halt
    fi

    echo "note: saving recovered GRUB environment block"
    save_env --file "($ONIRO_BOOT_PART)/EFI/BOOT/grubenv" SYSOTA_BOOT_ACTIVE SYSOTA_BOOT_TRY SYSOTA_BOOT_TRIED
fi

# Find the slot to boot from.
if [ -n "$SYSOTA_BOOT_TRY" ]; then
    echo "note: performing one-time boot from slot $SYSOTA_BOOT_TRY"
    set SLOT="$SYSOTA_BOOT_TRY"
    set SYSOTA_BOOT_TRIED="$SYSOTA_BOOT_TRY"
    unset SYSOTA_BOOT_TRY

    echo "note: saving modified GRUB environment block"
    save_env --file "($ONIRO_BOOT_PART)/EFI/BOOT/grubenv" SYSOTA_BOOT_ACTIVE SYSOTA_BOOT_TRY SYSOTA_BOOT_TRIED
else
    echo "note: performing normal boot from slot $SYSOTA_BOOT_ACTIVE"
    set SLOT="$SYSOTA_BOOT_ACTIVE"
fi

timeout=@WIC_BOOTLOADER_TIMEOUT@
default=boot

# Load the kernel from a fixed location of the slot selected for booting.
# The partition identifiers below refer to the fixed sys-a and sys-b
# partitions.
#
# For a description of how to package the kernel into the rootfs image, refer
# to the wiki page:
# https://gitlab.eclipse.org/eclipse/oniro-core/sysota/-/wikis/Boot%20Assets%20Specification#efigrub
if [ "$SLOT" == "A" ]; then
    # TODO pass root partition by partuuid.
menuentry 'boot' {
    linux "(hd0,gpt2)/boot/@KERNEL_IMAGETYPE@" root=@RAUC_SLOT_A@ rauc.slot=A $CMDLINE
}
elif [ "$SLOT" == "B" ]; then
menuentry 'boot' {
    linux "(hd0,gpt3)/boot/@KERNEL_IMAGETYPE@" root=@RAUC_SLOT_B@ rauc.slot=B $CMDLINE
}
else
    echo "error: cannot select slot to boot from, halting"
    halt
fi

boot

```

the resulting embedded file inside of the binary is differnet from the original one
here's the link for the differnce between both of them
https://www.diffchecker.com/1g3BHMXd/
I'm losing empty lines , {  ,fi and #

I'm trying to fuse this stand-alone configuration into the binary
but I realised I can't embed boot-menu-entries directly but I need to install it into rootfs then embed a file to look for it
is there a way around this ?
and lastly is there a way around to not lost lines from the embedded file ?

My end goal is to have one file including both the binary and the stand-alone-configuration and being able to boot :D

Thanks in advance

Kareem Zarka <the_zarka>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #54061:  11.png added by the_zarka (458KiB - image/png - some of the the differnces)
file #54062:  Screenshot@from@2022-12-06@12-25-56.png added by the_zarka (542KiB - image/png - some of the the differnces)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by the_zarka (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-12-06 the_zarka Attached File- Added 11.png, #54061
        Attached File- Added Screenshot@from@2022-12-06@12-25-56.png, #54062

    Back to the top

    Powered by Savane 3.14-f13d.
    Corresponding source code