Add support for cross-building cloudware images.
If MACHINE_ARCH doesn't match TARGET_ARCH, and we're not in the special case of building i386 images on an amd64 host, we need to pull in the qemu-user-static package; this allows us to run some commands inside the VM disk image chroot, most notably to install packages. Reviewed by: gjb MFC after: 2 weeks Sponsored by: FreeBSD/EC2 patreon (https://www.patreon.com/cperciva)
This commit is contained in:
parent
2ef79738b1
commit
b37e550602
@ -39,6 +39,24 @@ VAGRANT-VMWARE_FORMAT= vmdk
|
||||
VAGRANT-VMWARE_DESC= Vagrant Image for VMWare
|
||||
VAGRANT-VMWARE_DISK= ${OSRELEASE}.vmware.${VAGRANT_FORMAT}
|
||||
|
||||
emulator-portinstall:
|
||||
.if ${TARGET_ARCH} != ${MACHINE_ARCH}
|
||||
.if ( ${TARGET_ARCH} != "i386" ) || ( ${MACHINE_ARCH} != "amd64" )
|
||||
.if !exists(/usr/local/bin/qemu-${TARGET_ARCH}-static)
|
||||
.if exists(${PORTSDIR}/emulators/qemu-user-static/Makefile)
|
||||
env - PATH=$$PATH make -C ${PORTSDIR}/emulators/qemu-user-static BATCH=1 all install clean
|
||||
.else
|
||||
.if !exists(/usr/local/sbin/pkg-static)
|
||||
env ASSUME_ALWAYS_YES=yes pkg bootstrap -y
|
||||
.endif
|
||||
env ASSUME_ALWAYS_YES=yes pkg install -y emulators/qemu-user-static
|
||||
.endif
|
||||
.endif
|
||||
|
||||
QEMUSTATIC=/usr/local/bin/qemu-${TARGET_ARCH}-static
|
||||
.endif
|
||||
.endif
|
||||
|
||||
.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
|
||||
. for _CW in ${CLOUDWARE}
|
||||
CLOUDTARGETS+= cw-${_CW:tl}
|
||||
@ -53,9 +71,10 @@ ${_CW:tu}IMAGE= ${_CW:tl}.${${_CW:tu}_FORMAT}
|
||||
${_CW:tu}CONF?= ${.CURDIR}/tools/${_CW:tl}.conf
|
||||
. endif
|
||||
|
||||
cw-${_CW:tl}:
|
||||
cw-${_CW:tl}: emulator-portinstall
|
||||
mkdir -p ${.OBJDIR}/${.TARGET}
|
||||
env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
|
||||
QEMUSTATIC=${QEMUSTATIC} \
|
||||
${.CURDIR}/scripts/mk-vmimage.sh \
|
||||
-C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} \
|
||||
-i ${.OBJDIR}/${_CW:tl}.img -s ${VMSIZE} -f ${${_CW:tu}_FORMAT} \
|
||||
|
@ -40,7 +40,7 @@ vm_extra_pre_umount() {
|
||||
# catalogue and install or update pkg when the instance first
|
||||
# launches, so these files would just be replaced anyway; removing
|
||||
# them from the image allows it to boot faster.
|
||||
chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \
|
||||
chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \
|
||||
/usr/sbin/pkg delete -f -y pkg
|
||||
rm ${DESTDIR}/var/db/pkg/repo-*.sqlite
|
||||
|
||||
|
@ -148,10 +148,15 @@ vm_install_base() {
|
||||
hostname="$(echo $(uname -o) | tr '[:upper:]' '[:lower:]')"
|
||||
echo "hostname=\"${hostname}\"" >> ${DESTDIR}/etc/rc.conf
|
||||
|
||||
if ! [ -z "${QEMUSTATIC}" ]; then
|
||||
export EMULATOR=/qemu
|
||||
cp ${QEMUSTATIC} ${DESTDIR}/${EMULATOR}
|
||||
fi
|
||||
|
||||
mkdir -p ${DESTDIR}/dev
|
||||
mount -t devfs devfs ${DESTDIR}/dev
|
||||
chroot ${DESTDIR} /usr/bin/newaliases
|
||||
chroot ${DESTDIR} /etc/rc.d/ldconfig forcestart
|
||||
chroot ${DESTDIR} ${EMULATOR} /usr/bin/newaliases
|
||||
chroot ${DESTDIR} ${EMULATOR} /bin/sh /etc/rc.d/ldconfig forcestart
|
||||
umount_loop ${DESTDIR}/dev
|
||||
|
||||
cp /etc/resolv.conf ${DESTDIR}/etc/resolv.conf
|
||||
@ -188,9 +193,9 @@ vm_extra_install_packages() {
|
||||
fi
|
||||
mkdir -p ${DESTDIR}/dev
|
||||
mount -t devfs devfs ${DESTDIR}/dev
|
||||
chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \
|
||||
chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \
|
||||
/usr/sbin/pkg bootstrap -y
|
||||
chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \
|
||||
chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \
|
||||
/usr/sbin/pkg install -y ${VM_EXTRA_PACKAGES}
|
||||
umount_loop ${DESTDIR}/dev
|
||||
|
||||
@ -210,13 +215,16 @@ vm_extra_pre_umount() {
|
||||
# Note: When overriding this function, removing resolv.conf in the
|
||||
# disk image must be included.
|
||||
|
||||
if ! [ -z "${QEMUSTATIC}" ]; then
|
||||
rm -f ${DESTDIR}/${EMULATOR}
|
||||
fi
|
||||
rm -f ${DESTDIR}/etc/resolv.conf
|
||||
return 0
|
||||
}
|
||||
|
||||
vm_extra_pkg_rmcache() {
|
||||
if [ -e ${DESTDIR}/usr/local/sbin/pkg ]; then
|
||||
chroot ${DESTDIR} env ASSUME_ALWAYS_YES=yes \
|
||||
chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \
|
||||
/usr/local/sbin/pkg clean -y -a
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user