Can not understand bootloader (grub) option

1,102 views
Skip to first unread message

Roman Kalashnikov

unread,
Aug 14, 2017, 5:34:43 PM8/14/17
to swupdate
Hi all.

I'm using swupdate as standalone service for updating my system:
* Intel Atom x86_64
* Ubuntu 16.04
With partition schema:
| EFI | rootfs1-/dev/sda2 | rootfs2-/dev/sda3 | swap | USER DATA |

Building swupdate with needed params has no problems for me. But i can not understand how exactly realised grub support in swupdate.
As i know grub boot sequence splitted into several stages for me:
1 EFI starts with script: ln -s /boot/efi/EFI/BOOT/ubuntu/grubx64.efi /boot/startup.nsh - grub microprogram
2 Grub microprogram using 1st config-file: /boot/efi/EFI/BOOT/ubuntu/grub.cfg - contains parition's UUID for continue loading (this directory can contains grubenv, but not out of the box, should use 'grub-editenv create' before)
3 Then grub loads 2nd config : rootfsX-EXT4/boot/grub/grub.cfg - contains menu entries and grubenv
4 Now the kernel loaded

So, in case swupdate i use simple, RAW, gzipped image for partition /dev/sda3. sw-description contains simple code:
software =
{
        version = "0.1";
        hardware-compatibility = [ "1.0" ];
        stable:
        {
                main:
                {
                        images: (
                        {
                                filename = "rootfs.img.gz";
                                device = "/dev/sda2";
                                compressed = true;
                        }
                        );
                };
                alt:
                {
                        images: (
                        {
                                filename = "rootfs.img.gz";
                                device = "/dev/sda3";
                                compressed = true;
                        }
                        );
                };
        };
}

Command for install it:
swupdate -e "stable,alt" -v -i update_image.swu

And all works fine, my image delivered into /dev/sda3, BUT grub have no any information for boot from new partitions (f.e. failsafe flags or UUID for new partition).
As i can understand from source codes, swupdate uses grubenv for configuration grub for next boot. How can i put my own or automatically generated grub-boot-scripts through swupdate into grub.cfg/grubenv? 
If I am trying put boot-options into grub using grub-editenv 'just by hands' - grub ignores grubenv variables and use old config (i was trying to check grubenv from grub command line while boot and it show me expected grubenv variables) O_o

Best regards, Roman.
P.S. Sorry for my english :)

Stefano Babic

unread,
Aug 15, 2017, 5:22:52 AM8/15/17
to Roman Kalashnikov, swupdate
Hi Roman,

On 14/08/2017 23:34, Roman Kalashnikov wrote:
> Hi all.
>
> I'm using *swupdate* as standalone service for updating my system:
> * Intel Atom x86_64
> * Ubuntu 16.04

I've never thought when I started this project that it could be used to
update a standard Linux distro, too. Life is surprising....

> With partition schema:
> *|* EFI *|* rootfs1-/dev/sda2*| *rootfs2-/dev/sda3 *|* swap*|* USER DATA *|*

ok

>
> Building *swupdate* with needed params has no problems for me. But i can
> not understand how exactly realised grub support in *swupdate*.
> As i know grub boot sequence splitted into several stages for me:
> 1 EFI starts with script: ln -s /boot/efi/EFI/BOOT/ubuntu/grubx64.efi
> /boot/startup.nsh - grub microprogram
> 2 Grub microprogram using 1st config-file:
> /boot/efi/EFI/BOOT/ubuntu/grub.cfg - contains parition's UUID for
> continue loading (this directory can contains *grubenv*, but not out of
> the box, should use 'grub-editenv create' before)

The structure of grubenv file is very simple. It can generate in a lot
of ways.

> 3 Then grub loads 2nd config : rootfsX-EXT4/boot/grub/grub.cfg -
> contains menu entries and *grubenv*

It is required that grub.cfg calls load_env

> 4 Now the kernel loaded
>
> So, in case *swupdate* i use simple, RAW, gzipped image for partition
> /dev/sda3. *sw-description* contains simple code:
> software =
> {
> version = "0.1";
> hardware-compatibility = [ "1.0" ];
> stable:
> {
> main:
> {
> images: (
> {
> filename = "rootfs.img.gz";
> device = "/dev/sda2";
> compressed = true;
> }
> );
> };
> alt:
> {
> images: (
> {
> filename = "rootfs.img.gz";
> device = "/dev/sda3";
> compressed = true;
> }
> );
> };
> };
> }

you need to add a bootloader entry for each of them where you set the
variable to be processed by Grub. For example, you can set "next_entry"
or "default". Of course, it could be you have to change grub.cfg for
your needs. See example with bootloader or U-Boot in examples directory.

>
> Command for install it:
> swupdate -e "stable,alt" -v -i update_image.swu
>
> And all works fine, my image delivered into /dev/sda3, BUT grub have no
> any information for boot from new partitions (f.e. failsafe flags or
> UUID for new partition).

Well. you have not added any information to sw-description. You need
also to add Grub support to SWUpdate CONFIG_BOOTLOADER_GRUB) and check
if grubev is in the correct path (CONFIG_GRUBENV_PATH).

> As i can understand from source codes, *swupdate* uses *grubenv* for
> configuration grub for next boot.

Right.

> How can i put my own or automatically
> generated grub-boot-scripts through *swupdate *into grub.cfg/grubenv?

See above. Please note they are not scripts, but just variables.

> If I am trying put boot-options into grub using grub-editenv 'just by
> hands' - *grub* ignores grubenv variables and use old config

This is maybe caused by "standard" grub.cfg installed with Ubuntu.
Ubuntu has different goals and uses variables in a different way - see
grub.cfg.

> (i was
> trying to check grubenv from grub command line while boot and it show me
> expected grubenv variables) O_o
>

The whole logic is inside grub.cfg, and Ubuntu installed a script that
well fits the distro. You could simplify it with just two "menuentry" (A
/B) and setting default with a variable read from grubenv.

> Best regards, Roman.
> P.S. Sorry for my english :)

Never mind.

Best regards,
Stefano Babic

--
=====================================================================
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=====================================================================

Roman Kalashnikov

unread,
Aug 15, 2017, 6:03:33 AM8/15/17
to Stefano Babic, swupdate
Thanks a lot!
I'll check it out.

Roman Kalashnikov

unread,
Aug 15, 2017, 11:50:08 AM8/15/17
to Stefano Babic, swupdate
Finally it works.
1. I was installed grub only into EFI-partition with simple grub.cfg
2. I was added bootenv entries with correct partitions values for next boot

Next Stephen to detect partition for updating automatically.

Thanks a lot again :)

Roman Kalashnikov

unread,
Aug 15, 2017, 11:51:06 AM8/15/17
to Stefano Babic, swupdate
Next step^
IPhone autocorrection >_<

Stefano Babic

unread,
Aug 15, 2017, 12:09:43 PM8/15/17
to Roman Kalashnikov, Stefano Babic, swupdate
Hi Roman,

On 15/08/2017 17:49, Roman Kalashnikov wrote:
> Finally it works.
> 1. I was installed grub only into EFI-partition with simple grub.cfg
> 2. I was added bootenv entries with correct partitions values for next boot
>

Fine - feel free to post your grub.cfg / sw-description so that other
users can profit of your experience.

There is no example about grub - if you want, please post a patch for
documentation and / or examples directory as use case.

> Next Stephen to detect partition for updating automatically.
>
> Thanks a lot again :)

Roman Kalashnikov

unread,
Aug 15, 2017, 12:20:20 PM8/15/17
to Stefano Babic, swupdate
Okay
I will share my expirience tomorrow.

Roman Kalashnikov

unread,
Aug 16, 2017, 5:49:44 AM8/16/17
to swupdate, sba...@denx.de
Hi!

I'm not sure for correct way to upload patches by using github pull-request, so i just post git-diff here:

```
diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst
index b4e8d75..4a798ee 100644
--- a/doc/source/sw-description.rst
+++ b/doc/source/sw-description.rst
@@ -548,26 +548,6 @@ that must be changed:
 SWUpdate will internally generate a script that will be passed to the
 bootloader handler for adjusting the environment.
 
-For example to use GRUB environment - after update some of partition
-and boot from it:
-
-::
-
-       bootenv: (
-               {
-                       name = "default";
-                       value = "1";
-               },
-               {
-                       name = "fallback";
-                       value = "0";
-               },
-       )
-
-Note the `value` must contain correct partition's number in
-GRUB menuentry. Also `bootenv` can contains variable like `fallback`
-for failsafe boot if the new default menu entry fails to boot.
-
 For backward compatibility with previously built .swu images, "uboot "group name
 is still relevant (as an alias).
```
My sw-description posted here https://pastebin.com/9YyTsDDB.

For "GRUB supporting" i had to reconfigure it while zero-provision stage (before using swupdate):
1. grub-install --boot-directory=/boot --bootloader-id=ubuntu --target=x86_64-efi --efi-directory=/boot/efi --recheck --debug /dev/sda
2. grub-mkconfig -o /boot/efi/EFI/ubuntu/grub.cfg
3. grub-editenv /boot/efi/EFI/ubuntu/grubenv create
It creates grub.cfg by the "right way". It is resason i don't post grub.cfg here - it creates automactiacally.

Then i build swupdate with GRUB params in .config:
CONFIG_GRUBENV_PATH="/boot/efi/EFI/ubuntu/grubenv"
CONFIG_BOOTLOADER_GRUB=y

Now i can use swupdate traditionaly.

Best regards, Roman.

md.jamal...@gmail.com

unread,
Apr 3, 2018, 5:41:26 AM4/3/18
to swupdate
Hi Roman,

I was able to successfully build (ext4.gz), I want to implement single-copy approach.. How did you add a new partition in this. I mean what files did you modify..

Roman Kalashnikov

unread,
Apr 3, 2018, 3:27:18 PM4/3/18
to md.jamal...@gmail.com, swupdate
For now I do not use grub.
I can help you if you will share at least partition scheme and more information about your environment.

Best regards,
Kalashnikov Roman.
> --
> You received this message because you are subscribed to a topic in the Google Groups "swupdate" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/swupdate/OhMBA7AcoTk/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to swupdate+u...@googlegroups.com.
> To post to this group, send email to swup...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jamal Mohammad

unread,
Apr 3, 2018, 8:48:21 PM4/3/18
to Roman Kalashnikov, swupdate
Thanks for your reply.
We have Apollo lake motherboard (Intel 64 bit)

We are planning to use swupdate for OS updates in our project.

The partition scheme is 20 MB EFI partition, 5% of swap partition and remaining is used by rootfs . this is done by initinstallefi.sh script

We need to have a single copy rescue system. I am able to generate initrd image by running bitbake swupdate-image

The place where I am struck is how to modify the script to copy the initrd into a new partition and where to modify in GRUB for switching between them

Thanks for your time as there is almost no information on this online.
  I can provide you more information if you need

Roman Kalashnikov

unread,
Apr 4, 2018, 3:01:47 PM4/4/18
to Jamal Mohammad, swupdate
Unfortunately I did not used yocto project and did not used copy for updates (I use full partition update). But in common we have similar systems (also Apollo lake).

1. You can copy any files using swupdate, just look at the doc https://sbabic.github.io/swupdate/sw-description.html#files. You should add similar block into your sw-update, but destination should be mounted before updating.
2. Then you can do 2 different things:
2.1 Prepare grub.cfg with boot options for each initrd. In simple way
2.1.1 just keep initrd in different static directories/partitions
2.1.2 update each time another using ‘files’ mechanism
2.1.3 switch default in grub between initrd using grub env param ‘default’, you can see how to here https://sbabic.github.io/swupdate/sw-description.html#bootloader or in this thread
2.2 Similar with 2.1, but update grub.cfg dynamically after each update.

Do you use one kernel or/and rootfs (without it) and update just initrd?
You can keep kernel on EFI partition or in another special partition.
Reply all
Reply to author
Forward
0 new messages