Add the ability to break into a shell during builds.

Change-Id: I87af952d892f8622e4c916085fc896c735a35438
This commit is contained in:
Robert Collins 2012-12-14 20:17:00 +13:00
parent 012116cad6
commit d03825b504
3 changed files with 34 additions and 0 deletions

View File

@ -125,6 +125,20 @@ Ramdisk elements support the following files in their element directories:
* init : a POSIX shell script fragment that will be appended to the default * init : a POSIX shell script fragment that will be appended to the default
script executed as the ramdisk is booted (/init) script executed as the ramdisk is booted (/init)
Debugging elements
------------------
Export 'break' to drop to a shell during the image build. Break points can be
set either before or after any of the hook points by exporting
"break=[before|after]-hook-name". Multiple break points can be specified as a
comma-delimited string. Some examples:
* break=before-block-device-size will break before the block device size hooks
are called.
* break=after-first-boot,before-pre-install will break after the first-boot
hooks and before the pre-install hooks.
Third party elements Third party elements
-------------------- --------------------

View File

@ -44,6 +44,20 @@ function generate_hooks () {
done done
} }
# Call the supplied break-in routine if the named point is listed in the break
# list.
# $1 the break point.
# $2.. what to call if a break is needed
function check_break () {
if echo "$break" | egrep -e "(,|^)$1(,|$)" -q; then
echo "Starting debug shell. Exit to resume building." >&2
echo At stage $1 >&2
shift
"$@"
echo "Resuming" >&2
fi
}
# Check that a real element has been chosen (prevents foot-guns) # Check that a real element has been chosen (prevents foot-guns)
function check_element () { function check_element () {
[ -d $TMP_HOOKS_PATH ] || generate_hooks [ -d $TMP_HOOKS_PATH ] || generate_hooks

View File

@ -122,7 +122,9 @@ function run_d_in_target() {
sudo mkdir $TMP_MOUNT_PATH/tmp/in_target.d sudo mkdir $TMP_MOUNT_PATH/tmp/in_target.d
sudo mount --bind ${TMP_HOOKS_PATH} $TMP_MOUNT_PATH/tmp/in_target.d sudo mount --bind ${TMP_HOOKS_PATH} $TMP_MOUNT_PATH/tmp/in_target.d
sudo mount -o remount,ro,bind ${TMP_HOOKS_PATH} $TMP_MOUNT_PATH/tmp/in_target.d sudo mount -o remount,ro,bind ${TMP_HOOKS_PATH} $TMP_MOUNT_PATH/tmp/in_target.d
check_break before-$1 run_in_target bash
run_in_target run-parts -v /tmp/in_target.d/$1.d run_in_target run-parts -v /tmp/in_target.d/$1.d
check_break after-$1 run_in_target bash
sudo umount -f $TMP_MOUNT_PATH/tmp/in_target.d sudo umount -f $TMP_MOUNT_PATH/tmp/in_target.d
sudo rmdir $TMP_MOUNT_PATH/tmp/in_target.d sudo rmdir $TMP_MOUNT_PATH/tmp/in_target.d
fi fi
@ -131,12 +133,15 @@ function run_d_in_target() {
# Run a directory of hooks outside the target. # Run a directory of hooks outside the target.
function run_d() { function run_d() {
check_element check_element
check_break before-$1 bash
if [ -d ${TMP_HOOKS_PATH}/$1.d ] ; then if [ -d ${TMP_HOOKS_PATH}/$1.d ] ; then
run-parts ${TMP_HOOKS_PATH}/$1.d run-parts ${TMP_HOOKS_PATH}/$1.d
fi fi
check_break after-$1 bash
} }
function prepare_first_boot () { function prepare_first_boot () {
check_break before-first-boot run_in_target bash
if [ -d ${TMP_HOOKS_PATH}/first-boot.d ] ; then if [ -d ${TMP_HOOKS_PATH}/first-boot.d ] ; then
sudo cp -t $TMP_MOUNT_PATH/etc/ -a $TMP_HOOKS_PATH/first-boot.d sudo cp -t $TMP_MOUNT_PATH/etc/ -a $TMP_HOOKS_PATH/first-boot.d
run_in_target mv /etc/rc.local /etc/rc.local.REAL run_in_target mv /etc/rc.local /etc/rc.local.REAL
@ -152,6 +157,7 @@ exit 0
EOF EOF
run_in_target chmod 755 /etc/rc.local run_in_target chmod 755 /etc/rc.local
fi fi
check_break after-first-boot run_in_target bash
} }
function finalise_base () { function finalise_base () {