Skip to contentSkip to conversation

Running chroot-like command in Yocto #yocto

DISCUSSION Nicolas Wirth 4 participants 7 messages May 15, 2024 – May 16, 2024

lore
Share & tools
lore
#0 lore raw

Greetings,

I would like to run a command that has to use my target-generated tools and on my target-generated rootfs. For example, I would like to install an utility such as IMAGE_INSTALL = "unzip" and then run a command such as "${IMAGE_ROOTFS}/usr/bin/unzip ${IMAGE_ROOTFS}/home/user/test.zip" in ROOTFS_POSTPROCESS_COMMAND or IMAGE_POSTPROCESS_COMMAND .

Do you have any advices ?

Best,
Nicolas

#1 lore raw
Quoted 3 lines · Nicolas Wirth via lists.yoctoproject.org

I would like to run a command that has to use my target-generated tools and on my target-generated rootfs. For example, I would like to install an utility such as IMAGE_INSTALL = "unzip" and then run a command such as "${IMAGE_ROOTFS}/usr/bin/unzip ${IMAGE_ROOTFS}/home/user/test.zip" in ROOTFS_POSTPROCESS_COMMAND or IMAGE_POSTPROCESS_COMMAND .

Do you have any advices ?

It would be good to understand why this can't be done in a recipe, and why you need to run target unzip and not native one. E.g. you can unpack the zip in a recipe, then package the contents and install those packages into the image, where they will be unpacked in do_rootfs as any other packages are.

Alex

#2 lore raw

Really good point, my example can be misleading. I didn't wanted to add confusion by fully explaining my goal.

The goal is to run extlinux --install ${IMAGE_ROOTFS} /boot/syslinux, as I've understood, this command install the sylinux required file but also does write some bytes at the start of the partition, for the MBR. In debbos, I could do that using the following code and now I'm trying to reproduce that in the Yocto build system:

- action : run
description : Set up Syslinux
chroot : true
command : extlinux --install /boot/syslinux

#3 lore raw

I have no idea what this does, but MBR is not a file in the root filesystem, it's data structure in the first disk sector. Unfortunately I don't remember how legacy pre-UEFI ootloaders are installed 'offline' during yocto builds.

Can you do this on target during first boot?

Alex

Quoted 19 lines · Nicolas Wirth via lists.yoctoproject.org

Really good point, my example can be misleading. I didn't wanted to add confusion by fully explaining my goal.

The goal is to run extlinux --install ${IMAGE_ROOTFS}/boot/syslinux, as I've understood, this command install the sylinux required file but also does write some bytes at the start of the partition, for the MBR. In debbos, I could do that using the following code and now I'm trying to reproduce that in the Yocto build system:

- action: run
description: Set up Syslinux
chroot: true
command: extlinux --install /boot/syslinux

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#13351): https://lists.yoctoproject.org/g/poky/message/13351
Mute This Topic: https://lists.yoctoproject.org/mt/106112604/1686489
Mute #yocto:https://lists.yoctoproject.org/g/poky/mutehashtag/yocto Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/poky/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#4 lore raw
In reply to Nicolas Wirth
Quoted 11 lines · Nicolas Wirth via lists.yoctoproject.org

Really good point, my example can be misleading. I didn't wanted to add confusion by fully explaining my goal.

The goal is to run extlinux --install ${IMAGE_ROOTFS}/boot/syslinux, as I've understood, this command install the sylinux required file but also does write some bytes at the start of the partition, for the MBR. In debbos, I could do that using the following code and now I'm trying to reproduce that in the Yocto build system:
- action: run
description: Set up Syslinux
chroot: true
command: extlinux --install /boot/syslinux

The syslinux class already basically does a lot of this. If you want to do something bespoke and custom you just ensure do_image depends on syslinux-native and run the commands in an IMAGE_POSTPROCESS_COMMAND. But if you’re generating the correct image type then this will be done already.

Ross

#5 lore raw

That's not entirely true. The syslinux class does indeed a lot of this, I was able to experiment with this using the live hddimage. However, this mechanism ends up creating 2 different partitions, one containing the bootloader, and one containing the rootfs. I would like to have them in the same partition. I was able to find how to do it by scripting, but it's outside of the build environment. My script looks like this:
loop_dev =$( losetup --find --partscan --show " my-image-genericx86-64.wic " )
if [[ -z " $loop_dev " ]]; then
echo " Failed to set up loop device! "
exit 1
fi

if [[ " $arch " == " amd64 " ]]; then
echo " Setting up Extlinux "
mount_dir =$( mktemp --directory )
mount ${ loop_dev } p1 ${ mount_dir }
extlinux --install ${ mount_dir } /boot/syslinux
umount ${ loop_dev } p1
fi

#6 lore raw

I haven't tried, but you can test with the following approach:

  1.  Setup nopasswd sudo
  2.  In you custom command, disable pseudo (export PSEUDO_UNLOAD=1)
  3.  Run 'sudo chroot ...'
  4.  You may also need to enable the 'network' flag for do_rootfs/do_image_xxx task (whichever task your command is run in) to avoid namespace messing things up. E.g., do_rootfs['network'] = 1

Anyway, if you can find a way to adjust syslinux class to add extra functionality to it, that would be best.

Regards,
Qi

From: [email protected] <[email protected]> On Behalf Of Nicolas Wirth via lists.yoctoproject.org
Sent: Wednesday, May 15, 2024 10:42 PM
To: [email protected]
Subject: Re: [poky] Running chroot-like command in Yocto #yocto

That's not entirely true. The syslinux class does indeed a lot of this, I was able to experiment with this using the live hddimage. However, this mechanism ends up creating 2 different partitions, one containing the bootloader, and one containing the rootfs. I would like to have them in the same partition. I was able to find how to do it by scripting, but it's outside of the build environment. My script looks like this:

loop_dev=$(losetup --find --partscan --show "my-image-genericx86-64.wic")

if [[ -z "$loop_dev" ]]; then

echo "Failed to set up loop device!"

exit 1

fi

if [[ "$arch" == "amd64" ]]; then

    echo "Setting up Extlinux"

    mount_dir=$(mktemp --directory)

    mount ${loop_dev}p1 ${mount_dir}

    extlinux --install ${mount_dir}/boot/syslinux

    umount ${loop_dev}p1

fi