view more/chroot-splice.sh @ 1684:7b4566efd8bd draft 1.2.8

Silence some asynchronous messages linux produces on top of the shell prompt.
author Rob Landley <rob@landley.net>
date Sun, 07 Sep 2014 10:39:51 -0500
parents f7eaa514d628
children 4921adb23771
line wrap: on
line source

#!/bin/bash

# Combine a root filesystem directory and a control image into an $ARCH-specific
# chroot containing native build control files, suitable for chrooting into.

if [ $# -ne 2 ]
then
  echo "usage: $0 "'$ARCH $CONTROL_IMAGE' >&2
  exit 1
fi

# Make sure prerequisites exist

for i in "build/root-filesystem-$1" "$2"
do
  if [ ! -e "$i" ]
  then
    echo "No $i" >&2
    exit 1
  fi
done

if [ `id -u` -ne 0 ]
then
  echo "Not root">&2
  exit 1
fi

# Zap old stuff (if any)

[ -z "$CHROOT" ] && CHROOT="build/chroot-$1"
trap 'more/zapchroot.sh "$CHROOT"' EXIT
if [ -e "$CHROOT" ]
then
  more/zapchroot.sh "$CHROOT" || exit 1
fi

# Copy root filesystem and splice in control image
cp -lan "build/root-filesystem-$1/." "$CHROOT" || exit 1

if [ -d "$2" ]
then
  mount -o bind "$2" "$CHROOT/mnt" &&
  mount -o remount,ro "$CHROOT/mnt"|| exit 1
else
  mount -o loop "$2" "$CHROOT/mnt" || exit 1
fi

# Output some usage hints

CPUS=1 HOST="$1" chroot "$CHROOT" /sbin/init.sh