From 7fe5fc9c32da54cd37d72cf9e67d65248c0f9dc8 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 2 Mar 2018 10:58:09 -0500 Subject: [PATCH] grub_install: Add LOOP_NO_UDEV for builds in a container 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. --- build_library/grub_install.sh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/build_library/grub_install.sh b/build_library/grub_install.sh index adf411596a..f3248c2d01 100755 --- a/build_library/grub_install.sh +++ b/build_library/grub_install.sh @@ -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 ) @@ -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 @@ -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