mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-27 15:45:21 +00:00
f3e8c4299d
r281783, r281809, r281832: r280299 (cperciva): When creating VM images, copy the contents of the created filesystem into a new filesystem before packaging it into a disk image. This prevents "remnants" of deleted files from showing up in the VM images, and reduces their compressed size (by about 10% for the cloudware images) as a result. r280840 (cperciva): Clean up filesystem unmounting in vmimage builds: - Remove vm_umount_base function which is currently unused. - Add umount_loop function which loops attempting to unmount one filesystem. - Replace calls to umount with calls to umount_loop. - Don't attempt to unmount ${DESTDIR}/dev if it isn't mounted. The looping is necessary because sometimes umount fails due to filesystems being busy. The most common cause of such busyness is periodic(8) jobs running `find / ...`. r280846 (cperciva): Improve check for whether ${DESTDIR}/dev is mounted. r280879 (cperciva): Add bits for building EC2 disk images. r280881 (cperciva): Partially revert r278118 now that the required logic for deciding whether freebsd-update can be useful has moved into the firstboot_freebsd_update script. r280884 (cperciva): Fix pkg(8) command line in vm_extra_pre_umount(). r280928 (cperciva): Add code for creating an EC2 AMI. r281783: When building VM disk images, vm_copy_base() uses tar(1) to copy the userland from one md(4)-mounted filesystem to a clean filesystem to prevent remnants of files that were added and removed from resulting in an unclean filesystem. When newfs(8) creates the first filesystem with journaled soft-updates enabled, the /.sujournal file in the new filesystem cannot be overwritten by the /.sujournal in the original filesystem. To avoid this particular error case, do not enable journaled soft-updates when creating the md(4)-backed filesystems, and instead use tunefs(8) to enable journaled soft-updates after the new filesystem is populated in vm_copy_base(). While here, fix a long standing bug where the build environment /boot files were used by mkimg(1) when creating the VM disk images by using the files in .OBJDIR. r281809: Simplify variable expansion in attempt to fix the vm-image build. r281832: Fix locating the /boot files. Sponsored by: The FreeBSD Foundation
157 lines
4.3 KiB
Makefile
157 lines
4.3 KiB
Makefile
#
|
|
# $FreeBSD$
|
|
#
|
|
#
|
|
# Makefile for building virtual machine and cloud provider disk images.
|
|
#
|
|
|
|
VMTARGETS= vm-image
|
|
VMFORMATS?= vhd vmdk qcow2 raw
|
|
VMSIZE?= 20G
|
|
VMBASE?= vm
|
|
|
|
VHD_DESC= Azure, VirtualPC, Hyper-V, Xen disk image
|
|
VMDK_DESC= VMWare, VirtualBox disk image
|
|
QCOW2_DESC= Qemu, KVM disk image
|
|
RAW_DESC= Unformatted raw disk image
|
|
|
|
CLOUDWARE?= AZURE \
|
|
EC2 \
|
|
GCE \
|
|
OPENSTACK
|
|
AZURE_FORMAT= vhdf
|
|
AZURE_DESC= Microsoft Azure platform image
|
|
AZURE_DISK= ${OSRELEASE}.${AZURE_FORMAT}
|
|
EC2_FORMAT= raw
|
|
EC2_DESC= Amazon EC2 image
|
|
EC2_DISK= ${OSRELEASE}.${EC2_FORMAT}
|
|
GCE_FORMAT= raw
|
|
GCE_DESC= Google Compute Engine image
|
|
GCE_DISK= disk.${GCE_FORMAT}
|
|
OPENSTACK_FORMAT=qcow2
|
|
OPENSTACK_DESC= OpenStack platform image
|
|
OPENSTACK_DISK= ${OSRELEASE}.${OPENSTACK_FORMAT}
|
|
|
|
.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
|
|
. for _CW in ${CLOUDWARE}
|
|
CLOUDTARGETS+= cw-${_CW:tl}
|
|
CLEANDIRS+= cw-${_CW:tl}
|
|
CLEANFILES+= ${_CW:tl}.img \
|
|
${_CW:tl}.${${_CW:tu}_FORMAT} \
|
|
${_CW:tl}.${${_CW:tu}_FORMAT}.raw \
|
|
cw${_CW:tl}-package
|
|
CLOUDINSTALL+= cw${_CW:tl}-install
|
|
CLOUDPACKAGE+= cw${_CW:tl}-package
|
|
${_CW:tu}IMAGE= ${_CW:tl}.${${_CW:tu}_FORMAT}
|
|
. if exists(${.CURDIR}/tools/${_CW:tl}.conf) && !defined(${_CW:tu}CONF)
|
|
${_CW:tu}CONF?= ${.CURDIR}/tools/${_CW:tl}.conf
|
|
. endif
|
|
|
|
cw-${_CW:tl}:
|
|
mkdir -p ${.OBJDIR}/${.TARGET}
|
|
env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
|
|
${.CURDIR}/scripts/mk-vmimage.sh \
|
|
-C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} \
|
|
-i ${.OBJDIR}/${_CW:tl}.img -s ${VMSIZE} -f ${${_CW}_FORMAT} \
|
|
-S ${WORLDDIR} -o ${.OBJDIR}/${${_CW}IMAGE} -c ${${_CW}CONF}
|
|
touch ${.TARGET}
|
|
|
|
cw${_CW:tl}-install:
|
|
mkdir -p ${DESTDIR}/${_CW:tl}
|
|
cp -p ${${_CW}IMAGE} \
|
|
${DESTDIR}/${_CW:tl}/${${_CW}_DISK}
|
|
cd ${DESTDIR}/${_CW:tl} && sha256 ${${_CW}_DISK}* > \
|
|
${DESTDIR}/${_CW:tl}/CHECKSUM.SHA256
|
|
cd ${DESTDIR}/${_CW:tl} && md5 ${${_CW}_DISK}* > \
|
|
${DESTDIR}/${_CW:tl}/CHECKSUM.MD5
|
|
|
|
cw${_CW:tl}-package:
|
|
@# Special target to handle packaging cloud images in the formats
|
|
@# specific to each hosting provider.
|
|
.if exists(${.CURDIR}/tools/${_CW:tl}-package.sh)
|
|
env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
|
|
${.CURDIR}/tools/${_CW:tl}-package.sh \
|
|
-D ${DESTDIR} -I ${${_CW}_DISK} -S ${WORLDDIR}
|
|
.endif
|
|
touch ${.TARGET}
|
|
|
|
. endfor
|
|
.endif
|
|
|
|
.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
|
|
CLEANDIRS+= ${VMTARGETS}
|
|
. for FORMAT in ${VMFORMATS}
|
|
CLEANFILES+= ${FORMAT}.img
|
|
CLEANFILES+= ${VMBASE}.${FORMAT}
|
|
. endfor
|
|
.endif
|
|
|
|
vm-base: vm-image
|
|
|
|
vm-image:
|
|
.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
|
|
. for FORMAT in ${VMFORMATS}
|
|
mkdir -p ${.OBJDIR}/${.TARGET}
|
|
env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
|
|
${.CURDIR}/scripts/mk-vmimage.sh \
|
|
-C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} \
|
|
-i ${.OBJDIR}/${FORMAT}.img -s ${VMSIZE} -f ${FORMAT} \
|
|
-S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FORMAT}
|
|
. endfor
|
|
.endif
|
|
touch ${.TARGET}
|
|
|
|
vm-cloudware: ${CLOUDTARGETS}
|
|
|
|
list-vmtargets: list-cloudware
|
|
@${ECHO}
|
|
@${ECHO} "Supported virtual machine disk image formats:"
|
|
.for FORMAT in ${VMFORMATS:tu}
|
|
@${ECHO} " ${FORMAT:tl}: ${${FORMAT}_DESC}"
|
|
.endfor
|
|
|
|
list-cloudware:
|
|
.if !empty(CLOUDWARE)
|
|
@${ECHO}
|
|
@${ECHO} "Supported cloud hosting provider images:"
|
|
. for _CW in ${CLOUDWARE}
|
|
@${ECHO} " ${_CW:tu}: ${${_CW:tu}_DESC}"
|
|
. endfor
|
|
.endif
|
|
|
|
vm-install:
|
|
.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
|
|
mkdir -p ${DESTDIR}/vmimages
|
|
. for FORMAT in ${VMFORMATS}
|
|
cp -p ${VMBASE}.${FORMAT} \
|
|
${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}
|
|
. endfor
|
|
. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES)
|
|
. for FORMAT in ${VMFORMATS}
|
|
# Don't keep the originals. There is a copy in ${.OBJDIR} if needed.
|
|
${XZCMD} ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}
|
|
. endfor
|
|
. endif
|
|
cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \
|
|
${DESTDIR}/vmimages/CHECKSUM.SHA256
|
|
cd ${DESTDIR}/vmimages && md5 ${OSRELEASE}* > \
|
|
${DESTDIR}/vmimages/CHECKSUM.MD5
|
|
.endif
|
|
|
|
vm-release:
|
|
.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
|
|
${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${VMTARGETS}
|
|
.endif
|
|
|
|
cloudware-release:
|
|
.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
|
|
${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${CLOUDTARGETS}
|
|
.endif
|
|
|
|
cloudware-install:
|
|
.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
|
|
${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${CLOUDINSTALL}
|
|
.endif
|
|
|
|
.include "${.CURDIR}/Makefile.ec2"
|