Move /tmp/ccache setup to base element
Commit c7d80dd
(Cleanup mount points automatically) removed the unmount
of $TMP_MOUNT_PATH/tmp/ccache in run_d_in_target() and moved the
"rm /tmp/ccache" to elements/base/finalise.d/02-remove-ccache. There
are two problems with this:
1) Not unmounting at the end of run_d_in_target() results in tmp/ccache
being bind mounted muliple times on top of itself (three times, if you
just run `disk-image-create base`). It is eventually unmounted, but
somehow the auto unmount code is confused, and tries to unmount it
one more time than it was mounted, which results in an error like
"umount: /tmp/image.THQkZxQa/mnt/tmp/ccache: not mounted".
This doesn't actually break anything, but it's a little messy.
2) "rm /tmp/ccache" in elements/base/finalise.d/02-remove-ccache never
succeeds in removing /tmp/ccache, because that hook is invoked by
run_d_in_target(), *while* /tmp/ccache is mounted.
This present commit solves the above by moving the ccache setup glue out
of img-functions and into the base element's root.d. This has the
following implications:
1) lib/img-functions is a little cleaner.
2) /tmp/ccache is available in the chroot during the root, extra-data,
pre-install, install and post-install stages. It is not available
during block-device, finalise and cleanup stages as it will have been
automatically unmounted by then.
3) /tmp/ccache won't be setup if you're building an image that doesn't
include the base element.
Change-Id: Ief4c0a6f4ec622db6c6f652776215684178d8943
This commit is contained in:
parent
126099cd6d
commit
43c0082aa7
@ -10,3 +10,8 @@ Notes:
|
|||||||
This may be as simple as having language-pack-XX installed in the
|
This may be as simple as having language-pack-XX installed in the
|
||||||
pre-install stage
|
pre-install stage
|
||||||
|
|
||||||
|
* This element ensures /tmp/ccache will be available in the chroot
|
||||||
|
during the root, extra-data, pre-install, install and post-install
|
||||||
|
stages. /tmp/ccache is unavailable during block-device, finalise
|
||||||
|
and cleanup stages as it will have been automatically unmounted
|
||||||
|
by then.
|
||||||
|
7
elements/base/cleanup.d/01-ccache
Executable file
7
elements/base/cleanup.d/01-ccache
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# As this is run in cleanup, it's already been automatically unmounted,
|
||||||
|
# so all we need to do here is remove the directory
|
||||||
|
sudo rmdir $TMP_MOUNT_PATH/tmp/ccache || true
|
@ -1,4 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
rmdir /tmp/ccache || true
|
|
15
elements/base/root.d/01-ccache
Executable file
15
elements/base/root.d/01-ccache
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Don't do anything if already mounted (if disk-image-create is invoked with
|
||||||
|
# no elements specified, this hook actually fires twice, once during
|
||||||
|
# `run_d root` for the base element, then again when `run_d root` is called
|
||||||
|
# after automatically pulling in the Ubuntu element)
|
||||||
|
grep " $TMP_MOUNT_PATH/tmp/ccache" /proc/mounts && exit
|
||||||
|
|
||||||
|
DIB_CCACHE_DIR=${DIB_CCACHE_DIR:-$HOME/.cache/image-create/ccache}
|
||||||
|
mkdir -p $DIB_CCACHE_DIR
|
||||||
|
|
||||||
|
sudo mkdir -p $TMP_MOUNT_PATH/tmp/ccache
|
||||||
|
sudo mount --bind $DIB_CCACHE_DIR $TMP_MOUNT_PATH/tmp/ccache
|
@ -241,8 +241,10 @@ function create_base () {
|
|||||||
export TMP_MOUNT_PATH=$TMP_BUILD_DIR/mnt
|
export TMP_MOUNT_PATH=$TMP_BUILD_DIR/mnt
|
||||||
# Copy data in to the root.
|
# Copy data in to the root.
|
||||||
TARGET_ROOT=$TMP_MOUNT_PATH run_d root
|
TARGET_ROOT=$TMP_MOUNT_PATH run_d root
|
||||||
if [ -z "$(ls $TMP_MOUNT_PATH | grep -v lost+found)" ] ; then
|
if [ -z "$(ls $TMP_MOUNT_PATH | grep -v '^lost+found\|tmp$')" ] ; then
|
||||||
# Nothing copied in, use Ubuntu.
|
# Nothing copied in, use Ubuntu. Note the test above allows
|
||||||
|
# root.d elements to put things in /tmp, and still have the
|
||||||
|
# automatic Ubuntu behaviour.
|
||||||
echo "Adding ubuntu element as / had no contents"
|
echo "Adding ubuntu element as / had no contents"
|
||||||
IMAGE_ELEMENT=$($SCRIPT_HOME/element-info --expand-dependencies $IMAGE_ELEMENT ubuntu)
|
IMAGE_ELEMENT=$($SCRIPT_HOME/element-info --expand-dependencies $IMAGE_ELEMENT ubuntu)
|
||||||
generate_hooks
|
generate_hooks
|
||||||
|
@ -20,4 +20,3 @@ FS_TYPE=${FS_TYPE:-ext4}
|
|||||||
# Used to set the file extension only at this stage.
|
# Used to set the file extension only at this stage.
|
||||||
IMAGE_TYPE=${IMAGE_TYPE:-qcow2}
|
IMAGE_TYPE=${IMAGE_TYPE:-qcow2}
|
||||||
IMAGE_NAME=${IMAGE_NAME:-image}
|
IMAGE_NAME=${IMAGE_NAME:-image}
|
||||||
DIB_CCACHE_DIR=${DIB_CCACHE_DIR:-~/.cache/image-create/ccache}
|
|
||||||
|
@ -75,9 +75,6 @@ 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
|
||||||
sudo mkdir -p $TMP_MOUNT_PATH/tmp/ccache
|
|
||||||
mkdir -p $DIB_CCACHE_DIR
|
|
||||||
sudo mount --bind $DIB_CCACHE_DIR $TMP_MOUNT_PATH/tmp/ccache
|
|
||||||
check_break before-$1 run_in_target bash
|
check_break before-$1 run_in_target bash
|
||||||
trap "check_break after-error run_in_target bash" ERR
|
trap "check_break after-error run_in_target bash" ERR
|
||||||
run_in_target dib-run-parts /tmp/in_target.d/$1.d
|
run_in_target dib-run-parts /tmp/in_target.d/$1.d
|
||||||
|
Loading…
Reference in New Issue
Block a user