6 # Common functions for virtual machine image build scripts.
9 export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
10 trap "cleanup" INT QUIT TRAP ABRT TERM
12 write_partition_layout() {
14 case "${TARGET}:${TARGET_ARCH}" in
15 amd64:amd64 | i386:i386)
16 mkimg -s gpt -b /boot/pmbr \
17 -p freebsd-boot/bootfs:=/boot/gptboot \
18 -p freebsd-swap/swapfs::1G \
19 -p freebsd-ufs/rootfs:=${VMBASE} \
24 -p freebsd-boot/bootfs:=/boot/boot1.hfs \
25 -p freebsd-swap/swapfs::1G \
26 -p freebsd-ufs/rootfs:=${VMBASE} \
45 if [ ! -z "${mddev}" ]; then
46 mdconfig -d -u ${mddev}
55 # Creates the UFS root filesystem for the virtual machine disk,
56 # written to the formatted disk image with mkimg(1).
59 truncate -s ${VMSIZE} ${VMBASE}
60 mddev=$(mdconfig -f ${VMBASE})
61 newfs -j /dev/${mddev}
62 mount /dev/${mddev} ${DESTDIR}
68 # Installs the FreeBSD userland/kernel to the virtual machine disk.
71 make DESTDIR=${DESTDIR} \
72 installworld installkernel distribution || \
73 err "\n\nCannot install the base system to ${DESTDIR}."
75 echo '# Custom /etc/fstab for FreeBSD VM images' \
76 > ${DESTDIR}/etc/fstab
77 echo '/dev/gpt/rootfs / ufs rw 1 1' \
78 >> ${DESTDIR}/etc/fstab
79 echo '/dev/gpt/swapfs none swap sw 0 0' \
80 >> ${DESTDIR}/etc/fstab
82 mkdir -p ${DESTDIR}/dev
83 mount -t devfs devfs ${DESTDIR}/dev
84 chroot ${DESTDIR} /usr/bin/newaliases
85 chroot ${DESTDIR} /etc/rc.d/ldconfig forcestart
91 vm_extra_install_base() {
92 # Prototype. When overridden, runs extra post-installworld commands
93 # as needed, based on the target virtual machine image or cloud
94 # provider image target.
99 vm_extra_enable_services() {
100 if [ ! -z "${VM_RC_LIST}" ]; then
101 for _rcvar in ${VM_RC_LIST}; do
102 echo ${_rcvar}_enable="YES" >> ${DESTDIR}/etc/rc.conf
109 vm_extra_install_packages() {
110 mkdir -p ${DESTDIR}/dev
111 mount -t devfs devfs ${DESTDIR}/dev
112 chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \
113 /usr/sbin/pkg bootstrap -y
114 if [ ! -z "${VM_EXTRA_PACKAGES}" ]; then
115 chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \
116 /usr/sbin/pkg install -y ${VM_EXTRA_PACKAGES}
118 umount ${DESTDIR}/dev
123 vm_extra_install_ports() {
124 # Prototype. When overridden, installs additional ports within the
125 # virtual machine environment.
130 vm_extra_pre_umount() {
131 # Prototype. When overridden, installs additional ports within the
132 # virtual machine environment.
140 while ! umount ${DESTDIR}/dev ${DESTDIR}; do
142 if [ $i -ge 10 ]; then
143 # This should never happen. But, it has happened.
144 msg="Cannot umount(8) ${DESTDIR}\n"
145 msg="${msg}Something has gone horribly wrong."
155 echo "Creating image... Please wait."
158 write_partition_layout || return 1
163 vm_extra_create_disk() {