2014-11-05 14:22:19 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Common functions for virtual machine image build scripts.
|
|
|
|
#
|
|
|
|
|
2018-12-20 20:39:37 +01:00
|
|
|
scriptdir=$(dirname $(realpath $0))
|
|
|
|
. ${scriptdir}/../../tools/boot/install-boot.sh
|
|
|
|
|
2014-11-05 14:22:19 +01:00
|
|
|
export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
|
|
|
|
trap "cleanup" INT QUIT TRAP ABRT TERM
|
|
|
|
|
2021-02-25 03:16:56 +01:00
|
|
|
# Platform-specific large-scale setup
|
|
|
|
# Most platforms use GPT, so put that as default, then special cases
|
|
|
|
PARTSCHEME=gpt
|
|
|
|
ROOTLABEL="gpt"
|
|
|
|
case "${TARGET}:${TARGET_ARCH}" in
|
|
|
|
powerpc:powerpc*)
|
|
|
|
PARTSCHEME=mbr
|
|
|
|
ROOTLABEL="ufs"
|
|
|
|
NOSWAP=yes # Can't label swap partition with MBR, so no swap
|
|
|
|
;;
|
|
|
|
esac
|
2014-11-05 14:22:19 +01:00
|
|
|
|
|
|
|
err() {
|
|
|
|
printf "${@}\n"
|
|
|
|
cleanup
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup() {
|
2015-03-30 11:08:24 +02:00
|
|
|
if [ -c "${DESTDIR}/dev/null" ]; then
|
2015-03-30 10:33:19 +02:00
|
|
|
umount_loop ${DESTDIR}/dev 2>/dev/null
|
|
|
|
fi
|
2014-11-05 14:22:19 +01:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
vm_create_base() {
|
|
|
|
|
|
|
|
mkdir -p ${DESTDIR}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2015-03-20 20:40:19 +01:00
|
|
|
vm_copy_base() {
|
2021-02-25 03:16:56 +01:00
|
|
|
# Defunct
|
2015-03-20 20:40:19 +01:00
|
|
|
}
|
|
|
|
|
2014-11-05 14:22:19 +01:00
|
|
|
vm_install_base() {
|
|
|
|
# Installs the FreeBSD userland/kernel to the virtual machine disk.
|
|
|
|
|
|
|
|
cd ${WORLDDIR} && \
|
2024-09-01 01:38:02 +02:00
|
|
|
make DESTDIR=${DESTDIR} ${INSTALLOPTS} \
|
2014-11-05 14:22:19 +01:00
|
|
|
installworld installkernel distribution || \
|
|
|
|
err "\n\nCannot install the base system to ${DESTDIR}."
|
|
|
|
|
2023-09-09 15:19:11 +02:00
|
|
|
# Bootstrap etcupdate(8) database.
|
2017-09-20 17:49:12 +02:00
|
|
|
mkdir -p ${DESTDIR}/var/db/etcupdate
|
|
|
|
etcupdate extract -B \
|
|
|
|
-M "TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}" \
|
|
|
|
-s ${WORLDDIR} -d ${DESTDIR}/var/db/etcupdate
|
|
|
|
|
2014-11-05 14:22:19 +01:00
|
|
|
echo '# Custom /etc/fstab for FreeBSD VM images' \
|
|
|
|
> ${DESTDIR}/etc/fstab
|
2022-10-28 22:53:36 +02:00
|
|
|
if [ "${VMFS}" != zfs ]; then
|
|
|
|
echo "/dev/${ROOTLABEL}/rootfs / ${VMFS} rw 1 1" \
|
|
|
|
>> ${DESTDIR}/etc/fstab
|
|
|
|
fi
|
2014-11-21 02:53:40 +01:00
|
|
|
if [ -z "${NOSWAP}" ]; then
|
|
|
|
echo '/dev/gpt/swapfs none swap sw 0 0' \
|
|
|
|
>> ${DESTDIR}/etc/fstab
|
|
|
|
fi
|
2014-11-05 14:22:19 +01:00
|
|
|
|
2017-10-30 14:54:54 +01:00
|
|
|
local hostname
|
|
|
|
hostname="$(echo $(uname -o) | tr '[:upper:]' '[:lower:]')"
|
|
|
|
echo "hostname=\"${hostname}\"" >> ${DESTDIR}/etc/rc.conf
|
2022-10-28 22:53:36 +02:00
|
|
|
if [ "${VMFS}" = zfs ]; then
|
|
|
|
echo "zfs_enable=\"YES\"" >> ${DESTDIR}/etc/rc.conf
|
|
|
|
echo "zpool_reguid=\"zroot\"" >> ${DESTDIR}/etc/rc.conf
|
2022-11-07 04:47:33 +01:00
|
|
|
echo "zpool_upgrade=\"zroot\"" >> ${DESTDIR}/etc/rc.conf
|
2024-05-06 22:26:52 +02:00
|
|
|
echo "kern.geom.label.disk_ident.enable=0" >> ${DESTDIR}/boot/loader.conf
|
|
|
|
echo "zfs_load=YES" >> ${DESTDIR}/boot/loader.conf
|
2022-10-28 22:53:36 +02:00
|
|
|
fi
|
2017-10-30 14:54:54 +01:00
|
|
|
|
2024-05-06 22:26:52 +02:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
vm_emulation_setup() {
|
2019-04-03 23:54:47 +02:00
|
|
|
if ! [ -z "${QEMUSTATIC}" ]; then
|
|
|
|
export EMULATOR=/qemu
|
|
|
|
cp ${QEMUSTATIC} ${DESTDIR}/${EMULATOR}
|
|
|
|
fi
|
|
|
|
|
2014-11-08 17:26:17 +01:00
|
|
|
mkdir -p ${DESTDIR}/dev
|
|
|
|
mount -t devfs devfs ${DESTDIR}/dev
|
2019-04-03 23:54:47 +02:00
|
|
|
chroot ${DESTDIR} ${EMULATOR} /usr/bin/newaliases
|
|
|
|
chroot ${DESTDIR} ${EMULATOR} /bin/sh /etc/rc.d/ldconfig forcestart
|
2014-11-21 03:30:37 +01:00
|
|
|
cp /etc/resolv.conf ${DESTDIR}/etc/resolv.conf
|
|
|
|
|
2014-11-05 14:22:19 +01:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
vm_extra_install_base() {
|
|
|
|
# Prototype. When overridden, runs extra post-installworld commands
|
|
|
|
# as needed, based on the target virtual machine image or cloud
|
|
|
|
# provider image target.
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
vm_extra_enable_services() {
|
|
|
|
if [ ! -z "${VM_RC_LIST}" ]; then
|
|
|
|
for _rcvar in ${VM_RC_LIST}; do
|
|
|
|
echo ${_rcvar}_enable="YES" >> ${DESTDIR}/etc/rc.conf
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2017-05-25 14:53:49 +02:00
|
|
|
if [ -z "${VMCONFIG}" -o -c "${VMCONFIG}" ]; then
|
|
|
|
echo 'ifconfig_DEFAULT="DHCP inet6 accept_rtadv"' >> \
|
|
|
|
${DESTDIR}/etc/rc.conf
|
2019-04-30 16:29:09 +02:00
|
|
|
# Expand the filesystem to fill the disk.
|
|
|
|
echo 'growfs_enable="YES"' >> ${DESTDIR}/etc/rc.conf
|
|
|
|
touch ${DESTDIR}/firstboot
|
2017-05-25 14:53:49 +02:00
|
|
|
fi
|
|
|
|
|
2014-11-05 14:22:19 +01:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
vm_extra_install_packages() {
|
2014-11-24 03:34:01 +01:00
|
|
|
if [ -z "${VM_EXTRA_PACKAGES}" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
2019-04-03 23:54:47 +02:00
|
|
|
chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \
|
2014-11-21 03:30:37 +01:00
|
|
|
/usr/sbin/pkg bootstrap -y
|
2021-08-09 18:23:18 +02:00
|
|
|
for p in ${VM_EXTRA_PACKAGES}; do
|
2021-08-09 17:47:03 +02:00
|
|
|
chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \
|
|
|
|
/usr/sbin/pkg install -y ${p}
|
|
|
|
done
|
2014-11-05 14:22:19 +01:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
vm_extra_install_ports() {
|
|
|
|
# Prototype. When overridden, installs additional ports within the
|
|
|
|
# virtual machine environment.
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2014-11-08 13:45:02 +01:00
|
|
|
vm_extra_pre_umount() {
|
2015-04-27 21:49:50 +02:00
|
|
|
# Prototype. When overridden, performs additional tasks within the
|
|
|
|
# virtual machine environment prior to unmounting the filesystem.
|
2014-11-08 13:45:02 +01:00
|
|
|
|
2024-05-06 22:26:52 +02:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
vm_emulation_cleanup() {
|
2019-04-03 23:54:47 +02:00
|
|
|
if ! [ -z "${QEMUSTATIC}" ]; then
|
|
|
|
rm -f ${DESTDIR}/${EMULATOR}
|
|
|
|
fi
|
Merge the following revisions from ^/projects/release-vmimage:
r273823-r273826, r273833, r273836, r273944, r274069-r274071,
r274134, r274211, r274280-r274285, r274287-r274288, r274292,
r274296-r274297, r274356, r274533, r274725, r274726, r274729,
r274734, r274771, r274945-r274946, r277180, r277183-r277184,
r277186-r277187, r277250-r277253, r277263-r277264, r277383-r277384,
r277393-r277395, r277438-r277439, r277447, r277455:
r273823:
Move virtual machine / cloud provider targets and
options from release/Makefile to their own Makefile.
r273824:
Add glue to allow enabling building cloud provider VM images
by default.
When WITH_CLOUDWARE is not empty, add CLOUDTARGETS to the
release/Makefile 'release' target.
r273825:
Avoid hard-coding the Azure image file format. While here,
avoid using OSRELEASE for the output file name.
r273826:
Remove a few vestiges of passing an exit code to panic().
r273833:
Initial commit providing a mechanism to create openstack images
as part of the release build.
r273836:
Fix output file name for openstack images. No further conversion
is necessary for this VM file target, so there is no need to append
the '.raw' suffix here.
r273944:
Uncomment the cloudinit rc.conf(5) line.
r274069:
Add line continuation so OPENSTACKCONF is actually included in the env(1).
r274070:
Add a 'vm-cloudware' target, used to drive all targets in CLOUDTARGETS.
r274071:
Add examples for WITH_CLOUDWARE to release.conf.sample.
Add WITH_CLOUDWARE evaluation to RELEASE_RMAKEFLAGS.
r274134:
Initial rewrite to consolidate VM image build scripts into one.
r274211:
Add write_partition_layout() used to populate the final image.
Fix duplicated mkimg(1) call in vm_create_disk().
Add primitive (untested) PowerPC/PowerPC64 VM image support.
Note: As it is currently written, the /boot/pmbr and
/boot/{gptboot,boot1.hfs} use the build host and not the target
build. Fixing this is likely going to be a hack in itself.
r274280:
Return if vm_create_disk() is unsuccessful.
r274281:
Add CLEANFILES entry for VM targets
r274282:
Add vm_extra_pre_umount() prototype to vmimage.subr.
r274283:
Fix DESTDIR for installworld, and make sure it is created before use.
r274284:
Move usage() from vmimage.subr to mk-vmimage.sh, in case vmimage.subr
has not been sourced.
r274285:
Spell 'OPTARG' correctly. Actually call vm_create_base().
r274287:
Fix line continuation in write_partition_layout().
Remove variable test that is no longer needed.
r274288:
Fix scheme flag to mkimg(1).
r274292:
mount(8) and umount(8) devfs(5) as needed.
r274296:
Change path for mk-vmimage.sh from ${TARGET}/ to scripts/ now that
it is consolidated into one file.
Fix paths for the base image and output disk image files.
r274297:
Call cleanup() after everything is done.
r274356:
Remove a stray directory from CLEANFILES.
r274533:
Set the boot partition type to 'apple-boot' for powerpc.
r274725:
In vm_install_base(), copy the host resolv.conf into
the build chroot before attempting to do anything that
requires working DNS (i.e., pkg bootstrap).
In vm_extra_pre_umount(), remove the resolv.conf before
the disk image is unmounted from the backing md(4).
r274726 (cperciva):
Silence errors when umounting the chroot's /dev, since it
probably doesn't exist when we're running this.
Unmount filesystems before attempting to destroy the md which
holds them.
r274729 (cperciva):
Unmount filesystem and destroy md before we read the vnode from
disk and package it into a disk image. Otherwise we end up
packaging an unclean filesystem.
r274734 (cperciva):
Merge duplicative vm-CLOUDTYPE targets before additional duplication
gets added by the impending arrival of ec2 and gcloud.
r274771 (cperciva):
Add NOSWAP option which can be set by a vmimage.conf file to specify
that no swap space should be created in the image. This will be used
by EC2 builds, since FreeBSD/EC2 allocates swap space on "ephemeral"
disks which are physically attached to the Xen host node.
r274945:
In vm_extra_install_packages(), only bootstrap pkg(8) if
VM_EXTRA_PACKAGES is empty.
In vm_extra_pre_umount(), cleanup downloaded packages if pkg(8) was
bootstrapped earlier.
r274946:
Fix indentation nit.
r277180:
In vm_extra_install_base(), do not install waagent in the openstack
image, because it is not used. This appears to be a copy mistake.
Remove vm_extra_install_base() from the openstack.conf entirely,
since it does not need to be overridden.
r277183:
Enable the textmode console by default for VM images, since there is
no way to tell if the environment will be able to use the
graphics-mode console.
r277184:
Enable password-less sudo for openstack images.
r277186:
Update the VM_EXTRA_PACKAGES list for the openstack images.
The documentation suggests doing a "just fetch this and run it"-style
bootstrap, from which the list of dependencies was obtained (in
github, at: pellaeon/bsd-cloudinit-installer)
There is one Python dependency unmet, oslo.config, which is not in
the Ports Collection.
r277187:
Add a comment to note that setting hw.vga.textmode=1 is temporary.
r277250:
Remove vm_extra_install_base() for the Azure image, now that the
waagent exists in the ports tree.
Add sysutils/azure-agent to the VM_EXTRA_PACKAGES list.
In vm_extra_pre_umount(), remove the explicit pkg(8) install
list, as dependencies are resolved by sysutils/azure-agent.
r277251:
Add a 'list-cloudware' target to print the list of supported CLOUDWARE
values and a description.
Add the AZURE_DESC and OPENSTACK_DESC descriptions.
r277252:
Update release(7)
r277253:
Add 'list-vmtargets' target, which produces a list of all supported
VM and cloud provider images.
Add VHD_DESC, VMDK_DESC, QCOW2_DESC, RAW_DESC image descriptions.
Format the output to make a bit more readable.
Update release(7) to document the list-vmtargets target.
r277263:
Add initial support for the GCE (Google Compute Engine) cloud hosting
provider image.
r277264:
Style and line length cleanup.
r277383:
Remove the console setting from rc.conf(5), which is not used there.
While here, set console to include vidconsole in the loader.conf(5).
r277384:
Fix an indentation nit.
No functional changes.
r277393:
Remove the pkg-clean(8) call from vm_extra_pre_umount() since the
function is often overridden.
Add vm_extra_pkg_rmcache() to call pkg-clean(8) to avoid duplicated
code.
r277394:
Move resolv.conf(5) removal back to vm_extra_pre_umount() where it
belongs.
The GCE image needs resolv.conf(5) to exist (created as part of the
image setup), so it cannot be removed.
r277395:
Comment the line that configures ttys(5) to 'off', which makes it
impossible to test that the image boots.
Add a note explaining why the line is commented, and not (yet) removed
entirely.
r277438:
Move the 'install' bits that are specific to virtual machine images
from the Makefile to Makefile.vm.
Rename the 'install' target to 'release-install', and add a new
'vm-install' target.
Add a new 'install' target that invokes the new targets.
r277439:
Add WITH_CLOUDWARE to the list of make(1) variables for the release
build.
r277447:
Remove hw.vga.textmode=1 from the VM image loader.conf, which was
included during test builds and not intended to be included when
merging this project branch back to head.
r277455:
Remove mk-azure.sh, which is no longer needed.
MFC after: 1 month
X-MFC-To: stable/10 (requires mkimg(1))
Help from: cperciva, swills
Relnotes: yes
Sponsored by: The FreeBSD Foundation
2015-01-21 00:56:04 +01:00
|
|
|
rm -f ${DESTDIR}/etc/resolv.conf
|
2024-05-06 22:26:52 +02:00
|
|
|
umount_loop ${DESTDIR}/dev
|
Merge the following revisions from ^/projects/release-vmimage:
r273823-r273826, r273833, r273836, r273944, r274069-r274071,
r274134, r274211, r274280-r274285, r274287-r274288, r274292,
r274296-r274297, r274356, r274533, r274725, r274726, r274729,
r274734, r274771, r274945-r274946, r277180, r277183-r277184,
r277186-r277187, r277250-r277253, r277263-r277264, r277383-r277384,
r277393-r277395, r277438-r277439, r277447, r277455:
r273823:
Move virtual machine / cloud provider targets and
options from release/Makefile to their own Makefile.
r273824:
Add glue to allow enabling building cloud provider VM images
by default.
When WITH_CLOUDWARE is not empty, add CLOUDTARGETS to the
release/Makefile 'release' target.
r273825:
Avoid hard-coding the Azure image file format. While here,
avoid using OSRELEASE for the output file name.
r273826:
Remove a few vestiges of passing an exit code to panic().
r273833:
Initial commit providing a mechanism to create openstack images
as part of the release build.
r273836:
Fix output file name for openstack images. No further conversion
is necessary for this VM file target, so there is no need to append
the '.raw' suffix here.
r273944:
Uncomment the cloudinit rc.conf(5) line.
r274069:
Add line continuation so OPENSTACKCONF is actually included in the env(1).
r274070:
Add a 'vm-cloudware' target, used to drive all targets in CLOUDTARGETS.
r274071:
Add examples for WITH_CLOUDWARE to release.conf.sample.
Add WITH_CLOUDWARE evaluation to RELEASE_RMAKEFLAGS.
r274134:
Initial rewrite to consolidate VM image build scripts into one.
r274211:
Add write_partition_layout() used to populate the final image.
Fix duplicated mkimg(1) call in vm_create_disk().
Add primitive (untested) PowerPC/PowerPC64 VM image support.
Note: As it is currently written, the /boot/pmbr and
/boot/{gptboot,boot1.hfs} use the build host and not the target
build. Fixing this is likely going to be a hack in itself.
r274280:
Return if vm_create_disk() is unsuccessful.
r274281:
Add CLEANFILES entry for VM targets
r274282:
Add vm_extra_pre_umount() prototype to vmimage.subr.
r274283:
Fix DESTDIR for installworld, and make sure it is created before use.
r274284:
Move usage() from vmimage.subr to mk-vmimage.sh, in case vmimage.subr
has not been sourced.
r274285:
Spell 'OPTARG' correctly. Actually call vm_create_base().
r274287:
Fix line continuation in write_partition_layout().
Remove variable test that is no longer needed.
r274288:
Fix scheme flag to mkimg(1).
r274292:
mount(8) and umount(8) devfs(5) as needed.
r274296:
Change path for mk-vmimage.sh from ${TARGET}/ to scripts/ now that
it is consolidated into one file.
Fix paths for the base image and output disk image files.
r274297:
Call cleanup() after everything is done.
r274356:
Remove a stray directory from CLEANFILES.
r274533:
Set the boot partition type to 'apple-boot' for powerpc.
r274725:
In vm_install_base(), copy the host resolv.conf into
the build chroot before attempting to do anything that
requires working DNS (i.e., pkg bootstrap).
In vm_extra_pre_umount(), remove the resolv.conf before
the disk image is unmounted from the backing md(4).
r274726 (cperciva):
Silence errors when umounting the chroot's /dev, since it
probably doesn't exist when we're running this.
Unmount filesystems before attempting to destroy the md which
holds them.
r274729 (cperciva):
Unmount filesystem and destroy md before we read the vnode from
disk and package it into a disk image. Otherwise we end up
packaging an unclean filesystem.
r274734 (cperciva):
Merge duplicative vm-CLOUDTYPE targets before additional duplication
gets added by the impending arrival of ec2 and gcloud.
r274771 (cperciva):
Add NOSWAP option which can be set by a vmimage.conf file to specify
that no swap space should be created in the image. This will be used
by EC2 builds, since FreeBSD/EC2 allocates swap space on "ephemeral"
disks which are physically attached to the Xen host node.
r274945:
In vm_extra_install_packages(), only bootstrap pkg(8) if
VM_EXTRA_PACKAGES is empty.
In vm_extra_pre_umount(), cleanup downloaded packages if pkg(8) was
bootstrapped earlier.
r274946:
Fix indentation nit.
r277180:
In vm_extra_install_base(), do not install waagent in the openstack
image, because it is not used. This appears to be a copy mistake.
Remove vm_extra_install_base() from the openstack.conf entirely,
since it does not need to be overridden.
r277183:
Enable the textmode console by default for VM images, since there is
no way to tell if the environment will be able to use the
graphics-mode console.
r277184:
Enable password-less sudo for openstack images.
r277186:
Update the VM_EXTRA_PACKAGES list for the openstack images.
The documentation suggests doing a "just fetch this and run it"-style
bootstrap, from which the list of dependencies was obtained (in
github, at: pellaeon/bsd-cloudinit-installer)
There is one Python dependency unmet, oslo.config, which is not in
the Ports Collection.
r277187:
Add a comment to note that setting hw.vga.textmode=1 is temporary.
r277250:
Remove vm_extra_install_base() for the Azure image, now that the
waagent exists in the ports tree.
Add sysutils/azure-agent to the VM_EXTRA_PACKAGES list.
In vm_extra_pre_umount(), remove the explicit pkg(8) install
list, as dependencies are resolved by sysutils/azure-agent.
r277251:
Add a 'list-cloudware' target to print the list of supported CLOUDWARE
values and a description.
Add the AZURE_DESC and OPENSTACK_DESC descriptions.
r277252:
Update release(7)
r277253:
Add 'list-vmtargets' target, which produces a list of all supported
VM and cloud provider images.
Add VHD_DESC, VMDK_DESC, QCOW2_DESC, RAW_DESC image descriptions.
Format the output to make a bit more readable.
Update release(7) to document the list-vmtargets target.
r277263:
Add initial support for the GCE (Google Compute Engine) cloud hosting
provider image.
r277264:
Style and line length cleanup.
r277383:
Remove the console setting from rc.conf(5), which is not used there.
While here, set console to include vidconsole in the loader.conf(5).
r277384:
Fix an indentation nit.
No functional changes.
r277393:
Remove the pkg-clean(8) call from vm_extra_pre_umount() since the
function is often overridden.
Add vm_extra_pkg_rmcache() to call pkg-clean(8) to avoid duplicated
code.
r277394:
Move resolv.conf(5) removal back to vm_extra_pre_umount() where it
belongs.
The GCE image needs resolv.conf(5) to exist (created as part of the
image setup), so it cannot be removed.
r277395:
Comment the line that configures ttys(5) to 'off', which makes it
impossible to test that the image boots.
Add a note explaining why the line is commented, and not (yet) removed
entirely.
r277438:
Move the 'install' bits that are specific to virtual machine images
from the Makefile to Makefile.vm.
Rename the 'install' target to 'release-install', and add a new
'vm-install' target.
Add a new 'install' target that invokes the new targets.
r277439:
Add WITH_CLOUDWARE to the list of make(1) variables for the release
build.
r277447:
Remove hw.vga.textmode=1 from the VM image loader.conf, which was
included during test builds and not intended to be included when
merging this project branch back to head.
r277455:
Remove mk-azure.sh, which is no longer needed.
MFC after: 1 month
X-MFC-To: stable/10 (requires mkimg(1))
Help from: cperciva, swills
Relnotes: yes
Sponsored by: The FreeBSD Foundation
2015-01-21 00:56:04 +01:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
vm_extra_pkg_rmcache() {
|
2014-11-24 03:34:01 +01:00
|
|
|
if [ -e ${DESTDIR}/usr/local/sbin/pkg ]; then
|
2019-04-03 23:54:47 +02:00
|
|
|
chroot ${DESTDIR} ${EMULATOR} env ASSUME_ALWAYS_YES=yes \
|
2014-11-24 03:34:01 +01:00
|
|
|
/usr/local/sbin/pkg clean -y -a
|
|
|
|
fi
|
2014-11-21 03:30:37 +01:00
|
|
|
|
2014-11-08 13:45:02 +01:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-10-28 22:53:36 +02:00
|
|
|
buildfs() {
|
|
|
|
local md tmppool
|
|
|
|
|
|
|
|
case "${VMFS}" in
|
|
|
|
ufs)
|
|
|
|
makefs ${MAKEFSARGS} -o label=rootfs -o version=2 -o softupdates=1 \
|
|
|
|
${VMBASE} ${DESTDIR}
|
|
|
|
;;
|
|
|
|
zfs)
|
|
|
|
makefs -t zfs ${MAKEFSARGS} \
|
|
|
|
-o poolname=zroot -o bootfs=zroot/ROOT/default -o rootpath=/ \
|
|
|
|
-o fs=zroot\;mountpoint=none \
|
|
|
|
-o fs=zroot/ROOT\;mountpoint=none \
|
|
|
|
-o fs=zroot/ROOT/default\;mountpoint=/ \
|
2023-05-23 14:18:58 +02:00
|
|
|
-o fs=zroot/home\;mountpoint=/home \
|
2022-10-28 22:53:36 +02:00
|
|
|
-o fs=zroot/tmp\;mountpoint=/tmp\;exec=on\;setuid=off \
|
|
|
|
-o fs=zroot/usr\;mountpoint=/usr\;canmount=off \
|
|
|
|
-o fs=zroot/usr/ports\;setuid=off \
|
|
|
|
-o fs=zroot/usr/src \
|
|
|
|
-o fs=zroot/usr/obj \
|
|
|
|
-o fs=zroot/var\;mountpoint=/var\;canmount=off \
|
|
|
|
-o fs=zroot/var/audit\;setuid=off\;exec=off \
|
2024-01-02 18:38:55 +01:00
|
|
|
-o fs=zroot/var/crash\;setuid=off\;exec=off \
|
2022-10-28 22:53:36 +02:00
|
|
|
-o fs=zroot/var/log\;setuid=off\;exec=off \
|
|
|
|
-o fs=zroot/var/mail\;atime=on \
|
|
|
|
-o fs=zroot/var/tmp\;setuid=off \
|
|
|
|
${VMBASE} ${DESTDIR}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unexpected VMFS value '${VMFS}'"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2015-03-30 10:33:19 +02:00
|
|
|
umount_loop() {
|
|
|
|
DIR=$1
|
2014-11-05 14:22:19 +01:00
|
|
|
i=0
|
|
|
|
sync
|
2015-03-30 10:33:19 +02:00
|
|
|
while ! umount ${DIR}; do
|
2014-11-05 14:22:19 +01:00
|
|
|
i=$(( $i + 1 ))
|
|
|
|
if [ $i -ge 10 ]; then
|
|
|
|
# This should never happen. But, it has happened.
|
2015-03-30 10:33:19 +02:00
|
|
|
echo "Cannot umount(8) ${DIR}"
|
|
|
|
echo "Something has gone horribly wrong."
|
|
|
|
return 1
|
2014-11-05 14:22:19 +01:00
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
vm_create_disk() {
|
2022-10-28 22:53:36 +02:00
|
|
|
local BOOTFILES BOOTPARTSOFFSET FSPARTTYPE X86GPTBOOTFILE
|
2014-11-07 02:48:12 +01:00
|
|
|
|
2021-02-25 03:16:56 +01:00
|
|
|
if [ -z "${NOSWAP}" ]; then
|
|
|
|
SWAPOPT="-p freebsd-swap/swapfs::${SWAPSIZE}"
|
|
|
|
fi
|
|
|
|
|
2021-10-01 22:59:10 +02:00
|
|
|
if [ -n "${VM_BOOTPARTSOFFSET}" ]; then
|
|
|
|
BOOTPARTSOFFSET=":${VM_BOOTPARTSOFFSET}"
|
|
|
|
fi
|
|
|
|
|
2024-03-15 09:43:20 +01:00
|
|
|
if [ -n "${CONFIG_DRIVE}" ]; then
|
|
|
|
CONFIG_DRIVE="-p freebsd/config-drive::${CONFIG_DRIVE_SIZE}"
|
|
|
|
fi
|
|
|
|
|
2022-10-28 22:53:36 +02:00
|
|
|
case "${VMFS}" in
|
|
|
|
ufs)
|
|
|
|
FSPARTTYPE=freebsd-ufs
|
|
|
|
X86GPTBOOTFILE=i386/gptboot/gptboot
|
|
|
|
;;
|
|
|
|
zfs)
|
|
|
|
FSPARTTYPE=freebsd-zfs
|
|
|
|
X86GPTBOOTFILE=i386/gptzfsboot/gptzfsboot
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unexpected VMFS value '${VMFS}'"
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
echo "Creating image... Please wait."
|
|
|
|
echo
|
2021-10-01 22:59:10 +02:00
|
|
|
|
2021-02-25 03:16:56 +01:00
|
|
|
BOOTFILES="$(env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
|
|
|
|
WITH_UNIFIED_OBJDIR=yes \
|
|
|
|
make -C ${WORLDDIR}/stand -V .OBJDIR)"
|
|
|
|
BOOTFILES="$(realpath ${BOOTFILES})"
|
2022-10-28 22:53:36 +02:00
|
|
|
MAKEFSARGS="-s ${VMSIZE}"
|
2021-02-25 03:16:56 +01:00
|
|
|
|
|
|
|
case "${TARGET}:${TARGET_ARCH}" in
|
|
|
|
amd64:amd64 | i386:i386)
|
|
|
|
ESP=yes
|
|
|
|
BOOTPARTS="-b ${BOOTFILES}/i386/pmbr/pmbr \
|
2022-10-28 22:53:36 +02:00
|
|
|
-p freebsd-boot/bootfs:=${BOOTFILES}/${X86GPTBOOTFILE}${BOOTPARTSOFFSET}"
|
|
|
|
ROOTFSPART="-p ${FSPARTTYPE}/rootfs:=${VMBASE}"
|
|
|
|
MAKEFSARGS="$MAKEFSARGS -B little"
|
2021-02-25 03:16:56 +01:00
|
|
|
;;
|
2024-02-19 00:49:52 +01:00
|
|
|
arm:armv7 | arm64:aarch64 | riscv:riscv64*)
|
2021-02-25 03:16:56 +01:00
|
|
|
ESP=yes
|
|
|
|
BOOTPARTS=
|
2022-10-28 22:53:36 +02:00
|
|
|
ROOTFSPART="-p ${FSPARTTYPE}/rootfs:=${VMBASE}"
|
|
|
|
MAKEFSARGS="$MAKEFSARGS -B little"
|
2021-02-25 03:16:56 +01:00
|
|
|
;;
|
|
|
|
powerpc:powerpc*)
|
|
|
|
ESP=no
|
|
|
|
BOOTPARTS="-p prepboot:=${BOOTFILES}/powerpc/boot1.chrp/boot1.elf -a 1"
|
|
|
|
ROOTFSPART="-p freebsd:=${VMBASE}"
|
|
|
|
if [ ${TARGET_ARCH} = powerpc64le ]; then
|
2022-10-28 22:53:36 +02:00
|
|
|
MAKEFSARGS="$MAKEFSARGS -B little"
|
2021-02-25 03:16:56 +01:00
|
|
|
else
|
2022-10-28 22:53:36 +02:00
|
|
|
MAKEFSARGS="$MAKEFSARGS -B big"
|
2021-02-25 03:16:56 +01:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "vmimage.subr: unsupported target '${TARGET}:${TARGET_ARCH}'" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ ${ESP} = "yes" ]; then
|
|
|
|
# Create an ESP
|
|
|
|
espfilename=$(mktemp /tmp/efiboot.XXXXXX)
|
|
|
|
make_esp_file ${espfilename} ${fat32min} ${BOOTFILES}/efi/loader_lua/loader_lua.efi
|
2024-04-23 23:12:30 +02:00
|
|
|
BOOTPARTS="${BOOTPARTS} -p efi/efiboot0:=${espfilename}"
|
2021-02-25 03:16:56 +01:00
|
|
|
|
|
|
|
# Add this to fstab
|
|
|
|
mkdir -p ${DESTDIR}/boot/efi
|
2024-04-23 23:12:30 +02:00
|
|
|
echo "/dev/${ROOTLABEL}/efiboot0 /boot/efi msdosfs rw 2 2" \
|
2021-02-25 03:16:56 +01:00
|
|
|
>> ${DESTDIR}/etc/fstab
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Building filesystem... Please wait."
|
2022-10-28 22:53:36 +02:00
|
|
|
buildfs
|
2021-02-25 03:16:56 +01:00
|
|
|
|
|
|
|
echo "Building final disk image... Please wait."
|
|
|
|
mkimg -s ${PARTSCHEME} -f ${VMFORMAT} \
|
|
|
|
${BOOTPARTS} \
|
|
|
|
${SWAPOPT} \
|
2024-03-15 09:43:20 +01:00
|
|
|
${CONFIG_DRIVE} \
|
2021-02-25 03:16:56 +01:00
|
|
|
${ROOTFSPART} \
|
|
|
|
-o ${VMIMAGE}
|
|
|
|
|
2022-05-16 20:37:21 +02:00
|
|
|
echo "Disk image ${VMIMAGE} created."
|
|
|
|
|
2021-02-25 03:16:56 +01:00
|
|
|
if [ ${ESP} = "yes" ]; then
|
|
|
|
rm ${espfilename}
|
|
|
|
fi
|
2014-11-05 14:22:19 +01:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
vm_extra_create_disk() {
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|