vmimage.subr (fbece7609573bd51080e949df03fa3d803a637ae) | vmimage.subr (89585511cc052643a774f64f6450d18e7dd51d4a) |
---|---|
1#!/bin/sh 2# 3# $FreeBSD$ 4# 5# 6# Common functions for virtual machine image build scripts. 7# 8 --- 25 unchanged lines hidden (view full) --- 34 if [ -c "${DESTDIR}/dev/null" ]; then 35 umount_loop ${DESTDIR}/dev 2>/dev/null 36 fi 37 38 return 0 39} 40 41vm_create_base() { | 1#!/bin/sh 2# 3# $FreeBSD$ 4# 5# 6# Common functions for virtual machine image build scripts. 7# 8 --- 25 unchanged lines hidden (view full) --- 34 if [ -c "${DESTDIR}/dev/null" ]; then 35 umount_loop ${DESTDIR}/dev 2>/dev/null 36 fi 37 38 return 0 39} 40 41vm_create_base() { |
42 # Creates the UFS root filesystem for the virtual machine disk, 43 # written to the formatted disk image with mkimg(1). | |
44 45 mkdir -p ${DESTDIR} 46 47 return 0 48} 49 50vm_copy_base() { 51 # Defunct --- 13 unchanged lines hidden (view full) --- 65 -M "TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}" \ 66 -s ${WORLDDIR} -d ${DESTDIR}/var/db/etcupdate 67 sh ${WORLDDIR}/release/scripts/mm-mtree.sh -m ${WORLDDIR} \ 68 -F "TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}" \ 69 -D ${DESTDIR} 70 71 echo '# Custom /etc/fstab for FreeBSD VM images' \ 72 > ${DESTDIR}/etc/fstab | 42 43 mkdir -p ${DESTDIR} 44 45 return 0 46} 47 48vm_copy_base() { 49 # Defunct --- 13 unchanged lines hidden (view full) --- 63 -M "TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}" \ 64 -s ${WORLDDIR} -d ${DESTDIR}/var/db/etcupdate 65 sh ${WORLDDIR}/release/scripts/mm-mtree.sh -m ${WORLDDIR} \ 66 -F "TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}" \ 67 -D ${DESTDIR} 68 69 echo '# Custom /etc/fstab for FreeBSD VM images' \ 70 > ${DESTDIR}/etc/fstab |
73 echo "/dev/${ROOTLABEL}/rootfs / ufs rw 1 1" \ 74 >> ${DESTDIR}/etc/fstab | 71 if [ "${VMFS}" != zfs ]; then 72 echo "/dev/${ROOTLABEL}/rootfs / ${VMFS} rw 1 1" \ 73 >> ${DESTDIR}/etc/fstab 74 fi |
75 if [ -z "${NOSWAP}" ]; then 76 echo '/dev/gpt/swapfs none swap sw 0 0' \ 77 >> ${DESTDIR}/etc/fstab 78 fi 79 80 local hostname 81 hostname="$(echo $(uname -o) | tr '[:upper:]' '[:lower:]')" 82 echo "hostname=\"${hostname}\"" >> ${DESTDIR}/etc/rc.conf | 75 if [ -z "${NOSWAP}" ]; then 76 echo '/dev/gpt/swapfs none swap sw 0 0' \ 77 >> ${DESTDIR}/etc/fstab 78 fi 79 80 local hostname 81 hostname="$(echo $(uname -o) | tr '[:upper:]' '[:lower:]')" 82 echo "hostname=\"${hostname}\"" >> ${DESTDIR}/etc/rc.conf |
83 if [ "${VMFS}" = zfs ]; then 84 echo "zfs_enable=\"YES\"" >> ${DESTDIR}/etc/rc.conf 85 echo "zpool_reguid=\"zroot\"" >> ${DESTDIR}/etc/rc.conf 86 fi |
|
83 84 if ! [ -z "${QEMUSTATIC}" ]; then 85 export EMULATOR=/qemu 86 cp ${QEMUSTATIC} ${DESTDIR}/${EMULATOR} 87 fi 88 89 mkdir -p ${DESTDIR}/dev 90 mount -t devfs devfs ${DESTDIR}/dev 91 chroot ${DESTDIR} ${EMULATOR} /usr/bin/newaliases 92 chroot ${DESTDIR} ${EMULATOR} /bin/sh /etc/rc.d/ldconfig forcestart 93 umount_loop ${DESTDIR}/dev 94 95 cp /etc/resolv.conf ${DESTDIR}/etc/resolv.conf 96 | 87 88 if ! [ -z "${QEMUSTATIC}" ]; then 89 export EMULATOR=/qemu 90 cp ${QEMUSTATIC} ${DESTDIR}/${EMULATOR} 91 fi 92 93 mkdir -p ${DESTDIR}/dev 94 mount -t devfs devfs ${DESTDIR}/dev 95 chroot ${DESTDIR} ${EMULATOR} /usr/bin/newaliases 96 chroot ${DESTDIR} ${EMULATOR} /bin/sh /etc/rc.d/ldconfig forcestart 97 umount_loop ${DESTDIR}/dev 98 99 cp /etc/resolv.conf ${DESTDIR}/etc/resolv.conf 100 |
101 if [ "${VMFS}" = zfs ]; then 102 echo "kern.geom.label.disk_ident.enable=0" >> ${DESTDIR}/boot/loader.conf 103 echo "zfs_load=YES" >> ${DESTDIR}/boot/loader.conf 104 fi 105 |
|
97 return 0 98} 99 100vm_extra_install_base() { 101 # Prototype. When overridden, runs extra post-installworld commands 102 # as needed, based on the target virtual machine image or cloud 103 # provider image target. 104 --- 59 unchanged lines hidden (view full) --- 164 if [ -e ${DESTDIR}/usr/local/sbin/pkg ]; then 165 chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \ 166 /usr/local/sbin/pkg clean -y -a 167 fi 168 169 return 0 170} 171 | 106 return 0 107} 108 109vm_extra_install_base() { 110 # Prototype. When overridden, runs extra post-installworld commands 111 # as needed, based on the target virtual machine image or cloud 112 # provider image target. 113 --- 59 unchanged lines hidden (view full) --- 173 if [ -e ${DESTDIR}/usr/local/sbin/pkg ]; then 174 chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \ 175 /usr/local/sbin/pkg clean -y -a 176 fi 177 178 return 0 179} 180 |
181buildfs() { 182 local md tmppool 183 184 case "${VMFS}" in 185 ufs) 186 makefs ${MAKEFSARGS} -o label=rootfs -o version=2 -o softupdates=1 \ 187 ${VMBASE} ${DESTDIR} 188 ;; 189 zfs) 190 makefs -t zfs ${MAKEFSARGS} \ 191 -o poolname=zroot -o bootfs=zroot/ROOT/default -o rootpath=/ \ 192 -o fs=zroot\;mountpoint=none \ 193 -o fs=zroot/ROOT\;mountpoint=none \ 194 -o fs=zroot/ROOT/default\;mountpoint=/ \ 195 -o fs=zroot/tmp\;mountpoint=/tmp\;exec=on\;setuid=off \ 196 -o fs=zroot/usr\;mountpoint=/usr\;canmount=off \ 197 -o fs=zroot/usr/home \ 198 -o fs=zroot/usr/ports\;setuid=off \ 199 -o fs=zroot/usr/src \ 200 -o fs=zroot/usr/obj \ 201 -o fs=zroot/var\;mountpoint=/var\;canmount=off \ 202 -o fs=zroot/var/audit\;setuid=off\;exec=off \ 203 -o fs=zroot/var/log\;setuid=off\;exec=off \ 204 -o fs=zroot/var/mail\;atime=on \ 205 -o fs=zroot/var/tmp\;setuid=off \ 206 ${VMBASE} ${DESTDIR} 207 ;; 208 *) 209 echo "Unexpected VMFS value '${VMFS}'" 210 exit 1 211 ;; 212 esac 213} 214 |
|
172umount_loop() { 173 DIR=$1 174 i=0 175 sync 176 while ! umount ${DIR}; do 177 i=$(( $i + 1 )) 178 if [ $i -ge 10 ]; then 179 # This should never happen. But, it has happened. 180 echo "Cannot umount(8) ${DIR}" 181 echo "Something has gone horribly wrong." 182 return 1 183 fi 184 sleep 1 185 done 186 187 return 0 188} 189 190vm_create_disk() { | 215umount_loop() { 216 DIR=$1 217 i=0 218 sync 219 while ! umount ${DIR}; do 220 i=$(( $i + 1 )) 221 if [ $i -ge 10 ]; then 222 # This should never happen. But, it has happened. 223 echo "Cannot umount(8) ${DIR}" 224 echo "Something has gone horribly wrong." 225 return 1 226 fi 227 sleep 1 228 done 229 230 return 0 231} 232 233vm_create_disk() { |
191 echo "Creating image... Please wait." 192 echo | 234 local BOOTFILES BOOTPARTSOFFSET FSPARTTYPE X86GPTBOOTFILE |
193 194 if [ -z "${NOSWAP}" ]; then 195 SWAPOPT="-p freebsd-swap/swapfs::${SWAPSIZE}" 196 fi 197 198 if [ -n "${VM_BOOTPARTSOFFSET}" ]; then 199 BOOTPARTSOFFSET=":${VM_BOOTPARTSOFFSET}" 200 fi 201 | 235 236 if [ -z "${NOSWAP}" ]; then 237 SWAPOPT="-p freebsd-swap/swapfs::${SWAPSIZE}" 238 fi 239 240 if [ -n "${VM_BOOTPARTSOFFSET}" ]; then 241 BOOTPARTSOFFSET=":${VM_BOOTPARTSOFFSET}" 242 fi 243 |
244 case "${VMFS}" in 245 ufs) 246 FSPARTTYPE=freebsd-ufs 247 X86GPTBOOTFILE=i386/gptboot/gptboot 248 ;; 249 zfs) 250 FSPARTTYPE=freebsd-zfs 251 X86GPTBOOTFILE=i386/gptzfsboot/gptzfsboot 252 ;; 253 *) 254 echo "Unexpected VMFS value '${VMFS}'" 255 return 1 256 ;; 257 esac |
|
202 | 258 |
259 echo "Creating image... Please wait." 260 echo 261 |
|
203 BOOTFILES="$(env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \ 204 WITH_UNIFIED_OBJDIR=yes \ 205 make -C ${WORLDDIR}/stand -V .OBJDIR)" 206 BOOTFILES="$(realpath ${BOOTFILES})" | 262 BOOTFILES="$(env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \ 263 WITH_UNIFIED_OBJDIR=yes \ 264 make -C ${WORLDDIR}/stand -V .OBJDIR)" 265 BOOTFILES="$(realpath ${BOOTFILES})" |
266 MAKEFSARGS="-s ${VMSIZE}" |
|
207 208 case "${TARGET}:${TARGET_ARCH}" in 209 amd64:amd64 | i386:i386) 210 ESP=yes 211 BOOTPARTS="-b ${BOOTFILES}/i386/pmbr/pmbr \ | 267 268 case "${TARGET}:${TARGET_ARCH}" in 269 amd64:amd64 | i386:i386) 270 ESP=yes 271 BOOTPARTS="-b ${BOOTFILES}/i386/pmbr/pmbr \ |
212 -p freebsd-boot/bootfs:=${BOOTFILES}/i386/gptboot/gptboot${BOOTPARTSOFFSET}" 213 ROOTFSPART="-p freebsd-ufs/rootfs:=${VMBASE}" 214 MAKEFSARGS="-B little" | 272 -p freebsd-boot/bootfs:=${BOOTFILES}/${X86GPTBOOTFILE}${BOOTPARTSOFFSET}" 273 ROOTFSPART="-p ${FSPARTTYPE}/rootfs:=${VMBASE}" 274 MAKEFSARGS="$MAKEFSARGS -B little" |
215 ;; 216 arm64:aarch64 | riscv:riscv64*) 217 ESP=yes 218 BOOTPARTS= | 275 ;; 276 arm64:aarch64 | riscv:riscv64*) 277 ESP=yes 278 BOOTPARTS= |
219 ROOTFSPART="-p freebsd-ufs/rootfs:=${VMBASE}" 220 MAKEFSARGS="-B little" | 279 ROOTFSPART="-p ${FSPARTTYPE}/rootfs:=${VMBASE}" 280 MAKEFSARGS="$MAKEFSARGS -B little" |
221 ;; 222 powerpc:powerpc*) 223 ESP=no 224 BOOTPARTS="-p prepboot:=${BOOTFILES}/powerpc/boot1.chrp/boot1.elf -a 1" 225 ROOTFSPART="-p freebsd:=${VMBASE}" 226 if [ ${TARGET_ARCH} = powerpc64le ]; then | 281 ;; 282 powerpc:powerpc*) 283 ESP=no 284 BOOTPARTS="-p prepboot:=${BOOTFILES}/powerpc/boot1.chrp/boot1.elf -a 1" 285 ROOTFSPART="-p freebsd:=${VMBASE}" 286 if [ ${TARGET_ARCH} = powerpc64le ]; then |
227 MAKEFSARGS="-B little" | 287 MAKEFSARGS="$MAKEFSARGS -B little" |
228 else | 288 else |
229 MAKEFSARGS="-B big" | 289 MAKEFSARGS="$MAKEFSARGS -B big" |
230 fi 231 ;; 232 *) 233 echo "vmimage.subr: unsupported target '${TARGET}:${TARGET_ARCH}'" >&2 234 exit 1 235 ;; 236 esac 237 --- 5 unchanged lines hidden (view full) --- 243 244 # Add this to fstab 245 mkdir -p ${DESTDIR}/boot/efi 246 echo "/dev/${ROOTLABEL}/efiesp /boot/efi msdosfs rw 2 2" \ 247 >> ${DESTDIR}/etc/fstab 248 fi 249 250 echo "Building filesystem... Please wait." | 290 fi 291 ;; 292 *) 293 echo "vmimage.subr: unsupported target '${TARGET}:${TARGET_ARCH}'" >&2 294 exit 1 295 ;; 296 esac 297 --- 5 unchanged lines hidden (view full) --- 303 304 # Add this to fstab 305 mkdir -p ${DESTDIR}/boot/efi 306 echo "/dev/${ROOTLABEL}/efiesp /boot/efi msdosfs rw 2 2" \ 307 >> ${DESTDIR}/etc/fstab 308 fi 309 310 echo "Building filesystem... Please wait." |
251 makefs ${MAKEFSARGS} -o label=rootfs -o version=2 -o softupdates=1 \ 252 -s ${VMSIZE} ${VMBASE} ${DESTDIR} | 311 buildfs |
253 254 echo "Building final disk image... Please wait." 255 mkimg -s ${PARTSCHEME} -f ${VMFORMAT} \ 256 ${BOOTPARTS} \ 257 ${SWAPOPT} \ 258 ${ROOTFSPART} \ 259 -o ${VMIMAGE} 260 --- 12 unchanged lines hidden --- | 312 313 echo "Building final disk image... Please wait." 314 mkimg -s ${PARTSCHEME} -f ${VMFORMAT} \ 315 ${BOOTPARTS} \ 316 ${SWAPOPT} \ 317 ${ROOTFSPART} \ 318 -o ${VMIMAGE} 319 --- 12 unchanged lines hidden --- |