Skip to content
This repository has been archived by the owner on Sep 18, 2020. It is now read-only.

Commit

Permalink
grub_install: Add LOOP_NO_UDEV for builds in a container
Browse files Browse the repository at this point in the history
A lot of the SDK instructions seem to assume you're in a "classic" Linux login
session. I use Fedora Atomic Workstation and do all of my development in "dev
containers" (currently docker, in the process of switching to podman).

In my setup the `/dev` setup is separate and won't pick up udev changes.
(Ideally I'd filter out a lot of host devices, that's another issue)

Anyone in a similar situation (which I assume would also include trying
to do the SDK build inside a Docker container on CoreOS) can do:
`env LOOP_NO_UDEV=1 ./build_images.sh`
to have it manually set up the partition mounts.

Loopback mounts with containers in general are ugly since they're not
namespaced.

A whole better solution to this IMO is to use something like
http://libguestfs.org/ which basically spawns a VM, although it doesn't support
grub2. So we'd really have to do instead something like what Fedora does with
using Anaconda. Or the "helper VM" could probably just be an existing CoreOS
qcow2.
  • Loading branch information
cgwalters committed Mar 2, 2018
1 parent 575f7cd commit 7fe5fc9
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion build_library/grub_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ CORE_NAME=
# fixed up the board root's grub will always be used.
BOARD_GRUB=0

# This may be useful if you're running the build process inside a container
# (e.g. docker/podman/etc) distinct from the host; in that case you'll have
# a distinct /dev normally and won't pick up udev probed devices. But if you
# do the probe from the host side, it should show up in the container.
LOOP_NO_UDEV=${LOOP_NO_UDEV:-0}

case "${FLAGS_target}" in
i386-pc)
CORE_MODULES+=( biosdisk serial )
Expand Down Expand Up @@ -110,6 +116,21 @@ info "Installing GRUB ${FLAGS_target} in ${FLAGS_disk_image##*/}"
LOOP_DEV=$(sudo losetup --find --show --partscan "${FLAGS_disk_image}")
ESP_DIR=$(mktemp --directory)

# Hack available for doing the build in a container; see the LOOP_NO_UDEV
# comments above.
if [[ ${LOOP_NO_UDEV} -eq 1 ]]; then
echo "LOOP_NO_UDEV enabled, creating device nodes directly"
LOOPNUM=$(echo ${LOOP_DEV} | sed -e 's,/dev/loop,,')
for d in /sys/block/loop${LOOPNUM}/loop${LOOPNUM}p*; do
p=$(cat ${d}/partition)
dev=$(cat ${d}/dev)
min=${dev##*:}
maj=${dev%:*}
devpath=/dev/loop${LOOPNUM}p${p}
sudo rm -f ${devpath}
sudo mknod -m 660 ${devpath} b ${maj} ${min}
done
fi
# work around slow/buggy udev, make sure the node is there before mounting
if [[ ! -b "${LOOP_DEV}p1" ]]; then
# sleep a little just in case udev is ok but just not finished yet
Expand All @@ -119,11 +140,12 @@ if [[ ! -b "${LOOP_DEV}p1" ]]; then
if [[ -b "${LOOP_DEV}p1" ]]; then
break
fi
warn "looback device node still ${LOOP_DEV}p1 missing, reprobing..."
warn "loopback device node still ${LOOP_DEV}p1 missing, reprobing..."
sudo blockdev --rereadpt ${LOOP_DEV}
sleep 0.5
done
if [[ ! -b "${LOOP_DEV}p1" ]]; then
ls -al /dev/loop*
failboat "${LOOP_DEV}p1 where art thou? udev has forsaken us!"
fi
fi
Expand Down

0 comments on commit 7fe5fc9

Please sign in to comment.