Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F142978502
D34426.id103451.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D34426.id103451.diff
View Options
Index: release/Makefile.vm
===================================================================
--- release/Makefile.vm
+++ release/Makefile.vm
@@ -7,6 +7,7 @@
VMTARGETS= vm-image
VMFORMATS?= vhd vmdk qcow2 raw
+VMFS?= ufs
VMSIZE?= 4096m
SWAPSIZE?= 1g
VMBASE?= vm
@@ -86,7 +87,7 @@
env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
QEMUSTATIC=${QEMUSTATIC} \
${.CURDIR}/scripts/mk-vmimage.sh \
- -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} \
+ -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} -F ${VMFS} \
-i ${.OBJDIR}/${_CW:tl}.img -s ${VMSIZE} -f ${${_CW:tu}_FORMAT} \
-S ${WORLDDIR} -o ${.OBJDIR}/${${_CW:tu}IMAGE} -c ${${_CW:tu}CONF}
touch ${.TARGET}
@@ -120,7 +121,7 @@
mkdir -p ${.OBJDIR}/${.TARGET}
env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
${.CURDIR}/scripts/mk-vmimage.sh \
- -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} \
+ -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} -F ${VMFS} \
-i ${.OBJDIR}/${FORMAT}.img -s ${VMSIZE} -f ${FORMAT} \
-S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FORMAT}
. endfor
Index: release/scripts/mk-vmimage.sh
===================================================================
--- release/scripts/mk-vmimage.sh
+++ release/scripts/mk-vmimage.sh
@@ -41,7 +41,7 @@
main() {
local arg
VMCONFIG="/dev/null"
- while getopts "C:c:d:f:i:o:s:S:" arg; do
+ while getopts "C:c:d:F:f:i:o:s:S:" arg; do
case "${arg}" in
C)
VMBUILDCONF="${OPTARG}"
@@ -52,6 +52,9 @@
d)
DESTDIR="${OPTARG}"
;;
+ F)
+ VMFS="${OPTARG}"
+ ;;
f)
VMFORMAT="${OPTARG}"
;;
@@ -77,7 +80,8 @@
-z "${WORLDDIR}" -o \
-z "${DESTDIR}" -o \
-z "${VMSIZE}" -o \
- -z "${VMIMAGE}" ];
+ -z "${VMIMAGE}" -o \
+ -z "${VMFS}" ];
then
usage || exit 0
fi
Index: release/tools/ec2.conf
===================================================================
--- release/tools/ec2.conf
+++ release/tools/ec2.conf
@@ -21,11 +21,11 @@
# Set to a list of third-party software to enable in rc.conf(5).
export VM_RC_LIST="ec2_configinit ec2_fetchkey ec2_loghostkey firstboot_freebsd_update firstboot_pkgs ntpd dev_aws_disk"
-# Build with a 4.9 GB UFS partition; the growfs rc.d script will expand
+# Build with a 4.9 GB partition; the growfs rc.d script will expand
# the partition to fill the root disk after the EC2 instance is launched.
# Note that if this is set to <N>G, we will end up with an <N+1> GB disk
-# image since VMSIZE is the size of the UFS partition, not the disk which
-# it resides within.
+# image since VMSIZE is the size of the filesystem partition, not the disk
+# which it resides within.
export VMSIZE=5000m
# No swap space; the ec2_ephemeralswap rc.d script will allocate swap
Index: release/tools/vmimage.subr
===================================================================
--- release/tools/vmimage.subr
+++ release/tools/vmimage.subr
@@ -39,11 +39,47 @@
}
vm_create_base() {
- # Creates the UFS root filesystem for the virtual machine disk,
- # written to the formatted disk image with mkimg(1).
+ local tmppool
+
+ # Creates the root filesystem for the virtual machine disk,
+ # later written to the formatted disk image with mkimg(1).
mkdir -p ${DESTDIR}
+ if [ "${VMFS}" = zfs ]; then
+ tmppool=release.$(jot -r 1 1000000000)
+
+ rm -f ${VMBASE}
+ truncate -s ${VMSIZE} ${VMBASE}
+ ZFSMD=$(mdconfig -f ${VMBASE})
+
+ kldload -n zfs
+ zpool create -O compress=zstd -O atime=off -t $tmppool \
+ -R $DESTDIR zroot /dev/$ZFSMD
+
+ while read dataset opts; do
+ zfs create $opts ${tmppool}/$dataset
+ done <<__EOF__
+ROOT -o mountpoint=none
+ROOT/default -o mountpoint=/
+tmp -o mountpoint=/tmp -o exec=on -o setuid=off
+usr -o mountpoint=/usr -o canmount=off
+usr/home
+usr/ports -o setuid=off
+usr/src
+usr/obj
+var -o mountpoint=/var -o canmount=off
+var/audit -o setuid=off -o exec=off
+var/crash -o setuid=off -o exec=off
+var/log -o setuid=off -o exec=off
+var/mail -o atime=on
+var/tmp -o setuid=off
+__EOF__
+
+ zpool set bootfs=${tmppool}/ROOT/default ${tmppool}
+ zpool set autoexpand=on ${tmppool}
+ fi
+
return 0
}
@@ -70,8 +106,10 @@
echo '# Custom /etc/fstab for FreeBSD VM images' \
> ${DESTDIR}/etc/fstab
- echo "/dev/${ROOTLABEL}/rootfs / ufs rw 1 1" \
- >> ${DESTDIR}/etc/fstab
+ if [ "${VMFS}" = ufs ]; then
+ echo "/dev/${ROOTLABEL}/rootfs / ufs rw 1 1" \
+ >> ${DESTDIR}/etc/fstab
+ fi
if [ -z "${NOSWAP}" ]; then
echo '/dev/gpt/swapfs none swap sw 0 0' \
>> ${DESTDIR}/etc/fstab
@@ -94,6 +132,11 @@
cp /etc/resolv.conf ${DESTDIR}/etc/resolv.conf
+ if [ "${VMFS}" = zfs ]; then
+ echo "kern.geom.label.disk_ident.enable=0" >> ${DESTDIR}/boot/loader.conf
+ echo "zfs_load=YES" >> ${DESTDIR}/boot/loader.conf
+ fi
+
return 0
}
@@ -169,6 +212,21 @@
return 0
}
+buildfs() {
+ local md tmppool
+
+ if [ "${VMFS}" = ufs ]; then
+ makefs ${MAKEFSARGS} -o label=rootfs -o version=2 -o softupdates=1 \
+ -s ${VMSIZE} ${VMBASE} ${DESTDIR}
+ else
+ tmppool=$(zpool list -H | awk '{if ($NF == "'${DESTDIR}'") print $1}')
+ md=$(mdconfig -lv | awk '{if ($NF == "'${VMBASE}'") print $1}')
+
+ zpool export $tmppool
+ mdconfig -d -u ${md#md}
+ fi
+}
+
umount_loop() {
DIR=$1
i=0
@@ -188,6 +246,8 @@
}
vm_create_disk() {
+ local BOOTFILES BOOTPARTSOFFSET FSPARTTYPE GPTBOOTFILE
+
echo "Creating image... Please wait."
echo
@@ -199,6 +259,13 @@
BOOTPARTSOFFSET=":${VM_BOOTPARTSOFFSET}"
fi
+ if [ "${VMFS}" = ufs ]; then
+ FSPARTTYPE=freebsd-ufs
+ GPTBOOTFILE=i386/gptboot/gptboot
+ else
+ FSPARTTYPE=freebsd-zfs
+ GPTBOOTFILE=i386/gptzfsboot/gptzfsboot
+ fi
BOOTFILES="$(env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
WITH_UNIFIED_OBJDIR=yes \
@@ -209,14 +276,14 @@
amd64:amd64 | i386:i386)
ESP=yes
BOOTPARTS="-b ${BOOTFILES}/i386/pmbr/pmbr \
- -p freebsd-boot/bootfs:=${BOOTFILES}/i386/gptboot/gptboot${BOOTPARTSOFFSET}"
- ROOTFSPART="-p freebsd-ufs/rootfs:=${VMBASE}"
+ -p freebsd-boot/bootfs:=${BOOTFILES}/${GPTBOOTFILE}${BOOTPARTSOFFSET}"
+ ROOTFSPART="-p ${FSPARTTYPE}/rootfs:=${VMBASE}"
MAKEFSARGS="-B little"
;;
arm64:aarch64 | riscv:riscv64*)
ESP=yes
BOOTPARTS=
- ROOTFSPART="-p freebsd-ufs/rootfs:=${VMBASE}"
+ ROOTFSPART="-p ${FSPARTTYPE}/rootfs:=${VMBASE}"
MAKEFSARGS="-B little"
;;
powerpc:powerpc*)
@@ -248,8 +315,7 @@
fi
echo "Building filesystem... Please wait."
- makefs ${MAKEFSARGS} -o label=rootfs -o version=2 -o softupdates=1 \
- -s ${VMSIZE} ${VMBASE} ${DESTDIR}
+ buildfs
echo "Building final disk image... Please wait."
mkimg -s ${PARTSCHEME} -f ${VMFORMAT} \
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jan 26, 1:36 AM (6 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27988909
Default Alt Text
D34426.id103451.diff (6 KB)
Attached To
Mode
D34426: release: Add support for creating ZFS-based images
Attached
Detach File
Event Timeline
Log In to Comment