Only use tmpfs if build machine has 4GB+ RAM.
For machines with low RAM (or no access to /proc/meminfo) the builder will still run, but will just build inside the filesystem that is hosting /tmp. This will result in a slower build (especially if there are a lot of .deb packages installed). Fixes bug #1175453 Change-Id: I79f2672058c11e377548820df0ab4fad8f47ffdc
This commit is contained in:
parent
f13570d322
commit
d9a2211d14
13
README.md
13
README.md
@ -293,6 +293,19 @@ It's a colon (:) separated path list, and it will work in a first path/element f
|
||||
first served approach. The included elements tree is used when no path is supplied,
|
||||
and is added to the end of the path if a path is supplied.
|
||||
|
||||
Requirements
|
||||
============
|
||||
|
||||
If you have 4GB of available physical RAM\*, or more, diskimage-builder will
|
||||
create a tmpfs mount to build the image in. This will improve image build time
|
||||
by building in RAM. This can be disabled completely by passing --no-tmpfs to
|
||||
disk-image-create. ramdisk-image-create does not use a tmpfs mount. If tmpfs
|
||||
is not used, you will need enough room in /tmp to store two uncompressed
|
||||
cloud images. If you do have tmpfs, you will still need /tmp space for one
|
||||
uncompressed cloud image and about 20% of that for working files.
|
||||
|
||||
\* As reported by /proc/meminfo MemTotal
|
||||
|
||||
Copyright
|
||||
=========
|
||||
|
||||
|
@ -39,6 +39,7 @@ function show_options () {
|
||||
echo " -c -- clear environment before starting work"
|
||||
echo " -n skip the default inclusion of the 'base' element"
|
||||
echo " -p package[,package,package] -- list of packages to install in the image"
|
||||
echo " --no-tmpfs -- do not use tmpfs to speed image build"
|
||||
echo
|
||||
echo "ELEMENTS_PATH will allow you to specify multiple locations for the elements."
|
||||
exit 0
|
||||
@ -46,7 +47,7 @@ function show_options () {
|
||||
|
||||
INSTALL_PACKAGES=""
|
||||
COMPRESS_IMAGE="true"
|
||||
TEMP=`getopt -o a:ho:xucnp: -n $SCRIPTNAME -- "$@"`
|
||||
TEMP=`getopt -o a:ho:xucnp: -l no-tmpfs -n $SCRIPTNAME -- "$@"`
|
||||
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
|
||||
|
||||
# Note the quotes around `$TEMP': they are essential!
|
||||
@ -62,6 +63,7 @@ while true ; do
|
||||
-c) shift ; export CLEAR_ENV=1;;
|
||||
-n) shift; export SKIP_BASE="1";;
|
||||
-p) IFS="," read -a INSTALL_PACKAGES <<< "$2"; export INSTALL_PACKAGES ; shift 2 ;;
|
||||
--no-tmpfs) shift; export DIB_NO_TMPFS=1;;
|
||||
--) shift ; break ;;
|
||||
*) echo "Internal error!" ; exit 1 ;;
|
||||
esac
|
||||
|
@ -13,10 +13,21 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
function tmpfs_check() {
|
||||
[ "$DIB_NO_TMPFS" == "0" ] || return 1
|
||||
[ -r /proc/meminfo ] || return 1
|
||||
total_kB=$(awk '/^MemTotal/ { print $2 }' /proc/meminfo)
|
||||
[ $total_kB -lt $((4*1024*1024)) ] || return 0
|
||||
echo "Not enough RAM to use tmpfs for build. ($total_kB < 4G)"
|
||||
return 1
|
||||
}
|
||||
|
||||
function mk_build_dir () {
|
||||
export TMP_BUILD_DIR=$(mktemp -t -d --tmpdir=${TMP_DIR:-/tmp} image.XXXXXXXX)
|
||||
[ $? -eq 0 ] || die "Failed to create tmp directory"
|
||||
sudo mount -t tmpfs tmpfs $TMP_BUILD_DIR
|
||||
if tmpfs_check ; then
|
||||
sudo mount -t tmpfs tmpfs $TMP_BUILD_DIR
|
||||
fi
|
||||
sudo chown $(id -u):$(id -g) $TMP_BUILD_DIR
|
||||
trap cleanup EXIT
|
||||
echo Building in $TMP_BUILD_DIR
|
||||
|
@ -38,6 +38,7 @@ FS_TYPE=${FS_TYPE:-ext4}
|
||||
IMAGE_TYPE=${IMAGE_TYPE:-qcow2}
|
||||
IMAGE_NAME=${IMAGE_NAME:-image}
|
||||
export DIB_IMAGE_SIZE=${DIB_IMAGE_SIZE:-2} # N.B. This size is in GB
|
||||
export DIB_NO_TMPFS=${DIB_NO_TMPFS:-0}
|
||||
# Set via the CLI normally.
|
||||
# IMAGE_ELEMENT=
|
||||
_BASE_ELEMENT_DIR=$(dirname $0)/../elements
|
||||
|
@ -41,7 +41,7 @@ function cleanup () {
|
||||
function cleanup_dirs () {
|
||||
sudo rm -rf $TMP_BUILD_DIR/built
|
||||
sudo rm -rf $TMP_BUILD_DIR/mnt
|
||||
sudo umount $TMP_BUILD_DIR
|
||||
sudo umount -f $TMP_BUILD_DIR || true
|
||||
rm -rf $TMP_BUILD_DIR
|
||||
}
|
||||
|
||||
|
@ -24,3 +24,4 @@ IMAGE_NAME=${IMAGE_NAME:-"ramdisk"}
|
||||
_BASE_ELEMENT_DIR=$(dirname $0)/../elements
|
||||
ELEMENTS_PATH=${ELEMENTS_PATH:+"$ELEMENTS_PATH:$_BASE_ELEMENT_DIR"}
|
||||
export ELEMENTS_PATH=${ELEMENTS_PATH:-$_BASE_ELEMENT_DIR}
|
||||
export DIB_NO_TMPFS=${DIB_NO_TMPFS:-1}
|
||||
|
@ -25,6 +25,7 @@ function fullpath() {
|
||||
}
|
||||
|
||||
function cleanup () {
|
||||
sudo umount -f $TMP_BUILD_DIR || true
|
||||
rm -rf "$TMP_BUILD_DIR"
|
||||
}
|
||||
|
||||
|
@ -54,5 +54,5 @@ ALL ALL=(root) NOPASSWD: /sbin/losetup -d /dev/loop*
|
||||
ALL ALL=(root) NOPASSWD: /sbin/partprobe /dev/loop*
|
||||
ALL ALL=(root) NOPASSWD: /usr/bin/du --block-size=* -x -s /tmp/*/built
|
||||
ALL ALL=(root) NOPASSWD: /bin/mount -t tmpfs tmpfs /tmp/image.*
|
||||
ALL ALL=(root) NOPASSWD: /bin/umount /tmp/image.*
|
||||
ALL ALL=(root) NOPASSWD: /bin/umount -f /tmp/image.*
|
||||
ALL ALL=(root) NOPASSWD: /bin/chown *\:* /tmp/image.*
|
||||
|
Loading…
Reference in New Issue
Block a user