diff --git a/release/Makefile.vm b/release/Makefile.vm --- a/release/Makefile.vm +++ b/release/Makefile.vm @@ -126,6 +126,7 @@ env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \ QEMUSTATIC=${QEMUSTATIC} \ WITHOUT_QEMU=${WITHOUT_QEMU:Dtrue} \ + NO_ROOT=${NO_ROOT:Dtrue} \ ${.CURDIR}/scripts/mk-vmimage.sh \ -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} -F ${_FS} \ -i ${.OBJDIR}/${_CW:tl}.${_FS}.${_FMT}.img -s ${VMSIZE} -f ${_FMT} \ diff --git a/release/tools/vmimage.subr b/release/tools/vmimage.subr --- a/release/tools/vmimage.subr +++ b/release/tools/vmimage.subr @@ -49,8 +49,9 @@ } vm_install_base() { - # Installs the FreeBSD userland/kernel to the virtual machine disk. + local etcupdate_noroot + # Installs the FreeBSD userland/kernel to the virtual machine disk. cd ${WORLDDIR} && \ make DESTDIR=${DESTDIR} ${INSTALLOPTS} \ installworld installkernel distribution || \ @@ -58,10 +59,19 @@ # Bootstrap etcupdate(8) database. mkdir -p ${DESTDIR}/var/db/etcupdate + if [ -n "${NO_ROOT}" ]; then + etcupdate_noroot="-N" + fi etcupdate extract -B \ -M "TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}" \ -s ${WORLDDIR} -d ${DESTDIR}/var/db/etcupdate \ - -L /dev/stdout + -L /dev/stdout $etcupdate_noroot + if [ -n "${NO_ROOT}" ]; then + sed -n 's,^\.,./var/db/etcupdate/current,p' \ + ${DESTDIR}/var/db/etcupdate/current/METALOG | \ + env -i LC_COLLATE=C sort >> ${DESTDIR}/METALOG + rm ${DESTDIR}/var/db/etcupdate/current/METALOG + fi echo '# Custom /etc/fstab for FreeBSD VM images' \ > ${DESTDIR}/etc/fstab @@ -73,16 +83,28 @@ echo '/dev/gpt/swapfs none swap sw 0 0' \ >> ${DESTDIR}/etc/fstab fi + if [ -n "${NO_ROOT}" ]; then + echo './etc/fstab type=file uname=root gname=wheel mode=0644' >> \ + ${DESTDIR}/METALOG + fi local hostname hostname="$(echo $(uname -o) | tr '[:upper:]' '[:lower:]')" echo "hostname=\"${hostname}\"" >> ${DESTDIR}/etc/rc.conf + if [ -n "${NO_ROOT}" ]; then + echo './etc/rc.conf type=file uname=root gname=wheel mode=0644' >> \ + ${DESTDIR}/METALOG + fi if [ "${VMFS}" = zfs ]; then echo "zfs_enable=\"YES\"" >> ${DESTDIR}/etc/rc.conf echo "zpool_reguid=\"zroot\"" >> ${DESTDIR}/etc/rc.conf echo "zpool_upgrade=\"zroot\"" >> ${DESTDIR}/etc/rc.conf echo "kern.geom.label.disk_ident.enable=0" >> ${DESTDIR}/boot/loader.conf echo "zfs_load=YES" >> ${DESTDIR}/boot/loader.conf + if [ -n "${NO_ROOT}" ]; then + echo './boot/loader.conf type=file uname=root gname=wheel mode=0644' >> \ + ${DESTDIR}/METALOG + fi fi return 0 @@ -187,15 +209,21 @@ } buildfs() { - local md tmppool + local md tmppool sourcepath + + if [ -z "${NO_ROOT}" ]; then + sourcepath=${DESTDIR} + else + sourcepath=${DESTDIR}/METALOG + fi case "${VMFS}" in ufs) - makefs ${MAKEFSARGS} -o label=rootfs -o version=2 -o softupdates=1 \ - ${VMBASE} ${DESTDIR} + cd ${DESTDIR} && makefs ${MAKEFSARGS} -o label=rootfs -o version=2 -o softupdates=1 \ + ${VMBASE} ${sourcepath} ;; zfs) - makefs -t zfs ${MAKEFSARGS} \ + cd ${DESTDIR} && makefs -t zfs ${MAKEFSARGS} \ -o poolname=zroot -o bootfs=zroot/ROOT/default -o rootpath=/ \ -o fs=zroot\;mountpoint=none \ -o fs=zroot/ROOT\;mountpoint=none \ @@ -212,7 +240,7 @@ -o fs=zroot/var/log\;setuid=off\;exec=off \ -o fs=zroot/var/mail\;atime=on \ -o fs=zroot/var/tmp\;setuid=off \ - ${VMBASE} ${DESTDIR} + ${VMBASE} ${sourcepath} ;; *) echo "Unexpected VMFS value '${VMFS}'" @@ -276,7 +304,7 @@ WITH_UNIFIED_OBJDIR=yes \ make -C ${WORLDDIR}/stand -V .OBJDIR)" BOOTFILES="$(realpath ${BOOTFILES})" - MAKEFSARGS="-s ${VMSIZE}" + MAKEFSARGS="-s ${VMSIZE} -D" case "${TARGET}:${TARGET_ARCH}" in amd64:amd64 | i386:i386)