brunp
Posts: 9
Joined: Fri Jan 11, 2019 6:10 pm

What does on_chroot do?

Thu Jan 17, 2019 2:57 am

when looking at 00-run.sh within the build scripts, what is meant by the routine on_chroot from scripts/common? Why is it used? I saw a reply in an incident ticket, but not sure what "run as if it were on the Pi" mean? I am generating an image on Debian Stretch
The key line here is capsh --drop=cap_setfcap "--chroot=${ROOTFS_DIR}/" -- "[email protected]", where "[email protected]" is whatever is 'wrapped' in on_chroot.

--chroot=${ROOTFS_DIR}/ means that the command is run as if it were on the Pi, rather than on the host machine.

tempest766
Posts: 105
Joined: Sun Jan 07, 2018 3:44 pm

Re: What does on_chroot do?

Thu Jan 17, 2019 7:54 am

chroot is a jail for tasks that restrict their opration to a specific branch of the filesystem. It's designed to lessen the chance of contaminating the filesystem with erroneous changes.

brunp
Posts: 9
Joined: Fri Jan 11, 2019 6:10 pm

Re: What does on_chroot do?

Thu Jan 17, 2019 6:03 pm

on that note, if I was intending on making a Raspbian Lite build and generate custom stage3 which consisted of simply installing a package (via PyPI) which has a UI, would I do that within the on_chroot syntax? So, it would be contained within my image? Or, do I make some changes to have it run on first launch?

Paul

DirkS
Posts: 9902
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: What does on_chroot do?

Thu Jan 17, 2019 6:15 pm

brunp wrote:
Thu Jan 17, 2019 6:03 pm
on that note, if I was intending on making a Raspbian Lite build and generate custom stage3 which consisted of simply installing a package (via PyPI) which has a UI, would I do that within the on_chroot syntax? So, it would be contained within my image? Or, do I make some changes to have it run on first launch?
Yes, you would use on_chroot for that.
Personally I would not change stage 3, but add it to stage 2. I left stage 3 (which installs X programs, etc) untouched in case I want to use that in future.
But it doesn't really matter.

I added a directory to stage 2 ('04-pip-installs' in my case) and added a run file ('00-run.sh') with contents

Code: Select all

#!/bin/bash -e

on_chroot << EOF
pip install --upgrade pip
pip install spidev
pip3 install --upgrade pip
pip3 install spidev
EOF

brunp
Posts: 9
Joined: Fri Jan 11, 2019 6:10 pm

Re: What does on_chroot do?

Thu Jan 17, 2019 6:19 pm

alright, makes sense. This is good news. This would then allow you to perform some config's after re-imaging allowing you to configure WiFI after the fact.

Paul

Return to “Raspbian”