diff options
Diffstat (limited to 'bin/debvm-create')
-rwxr-xr-x | bin/debvm-create | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/bin/debvm-create b/bin/debvm-create index bfc02e3..b93fa23 100755 --- a/bin/debvm-create +++ b/bin/debvm-create @@ -74,8 +74,8 @@ This is specific to using B<finit>, B<runit>, B<systemd> or B<sysv> as init syst =item B<ext4> -Internally, B<mmdebstrap> creates a tar archive first and converts that to ext2, which is then upgraded to ext4. -This option causes the conversion to ext2 and further steps to be skipped and the output image will be a tar archive instead. +Normally, B<mmdebstrap> bootstraps to a temporary directory and we create the output ext4 image from that directory. +This option causes the creation of the ext4 image to be skipped and the output file becomes a tar archive of the temporary directory instead. Such a tar archive is not suitable for being booted by B<debvm-run>. =item B<ifupdown> @@ -116,7 +116,7 @@ Without the hook, dependencies will pull the B<usrmerge> package as needed, whic =item B<-z> I<size>, B<--size>=I<size> Specify the minimum image size as an integer and optional unit (example: 10K is 10*1024). -Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000). +Units are K,M,G,T (powers of 1024). The resulting image will be grown as a sparse file to this size if necessary. The default is 1 GB. @@ -294,7 +294,7 @@ if ! check_skip kernel; then set -- "--customize-hook=$SHARE_DIR/customize-kernel.sh" "$@" fi -MMFORMAT=ext2 +MMFORMAT=directory # output a tarball if the ext4 step is skipped if check_skip ext4; then MMFORMAT=tar @@ -303,6 +303,7 @@ fi # construct mmdebstrap options as $@: set -- \ --verbose \ + --mode=unshare \ --variant=apt \ "--format=$MMFORMAT" \ '--customize-hook=echo "LABEL=debvm / ext4 defaults 0 0" >"$1/etc/fstab"' \ @@ -393,20 +394,34 @@ if ! check_skip autologin; then set -- "--customize-hook=$SHARE_DIR/customize-autologin.sh" "$@" fi -set -- "$SUITE" "$IMAGE" "$@" +run_inside_userns() { + unshare --user --map-auto --map-user=65536 --map-group=65536 --keep-caps -- "$@" +} -set -ex +TEMPROOT= +cleanup() { + if test -n "$TEMPROOT"; then + run_inside_userns rm -Rf "$TEMPROOT" + fi +} -mmdebstrap "$@" +if check_skip ext4; then + set -- "$IMAGE" "$@" +else + trap cleanup EXIT + trap 'exit 1' HUP INT QUIT TERM + TEMPROOT="$(mktemp -d)" -{ set +x; } 2>/dev/null -check_skip ext4 && exit + set -- "$TEMPROOT" "$@" +fi + +set -- "$SUITE" "$@" -set -x +set -ex + +mmdebstrap "$@" -truncate -s ">$SIZE" "$IMAGE" -/sbin/resize2fs "$IMAGE" -/sbin/tune2fs -L debvm -c 0 -i 0 -O dir_index,dir_nlink,extents,extra_isize,flex_bg,has_journal,huge_file "$IMAGE" -/sbin/resize2fs -b "$IMAGE" -# Must fsck after tune2fs: https://ext4.wiki.kernel.org/index.php/UpgradeToExt4 -/sbin/fsck.ext4 -fDp "$IMAGE" +# Create and truncate the file with "normal" permission. +: >"$IMAGE" +check_skip ext4 || + run_inside_userns /sbin/mkfs.ext4 -L debvm -d "$TEMPROOT" "$IMAGE" "$SIZE" |