FreeBSD image: fix environment, mktemp disk image
This commit is contained in:
parent
0d554866c8
commit
1841857703
1 changed files with 15 additions and 10 deletions
|
@ -8,9 +8,13 @@ set -x
|
|||
|
||||
# XXX: Handle command-line arguments?
|
||||
RELEASE=12.1-RELEASE
|
||||
ARCH=amd64
|
||||
IMAGE_PATH=freebsd-$RELEASE-$(date +%+F).img.qcow2
|
||||
IMAGE_SIZE=10G
|
||||
|
||||
DIST_BASE="https://download.freebsd.org/ftp/releases/$ARCH/$RELEASE"
|
||||
PORTS_BASE="https://download.freebsd.org/ftp/snapshots/$ARCH/12.1-STABLE"
|
||||
|
||||
# TODO: find the package definition and built ourself, publish in some RPM repository.
|
||||
ONE_CONTEXT_RPM_URL="https://github.com/OpenNebula/addon-context-linux/releases/download/v5.10.0/one-context-5.10.0-1.el8.noarch.rpm"
|
||||
ONE_CONTEXT_RPM_PATH=/root/one-context.rpm
|
||||
|
@ -29,8 +33,9 @@ if [ "$(whoami)" != 'root' ]; then
|
|||
fi
|
||||
|
||||
# Allocate and partition/format disk image.
|
||||
truncate -s 6G disk.img
|
||||
mdconfig -a -t vnode -f disk.img -u md0
|
||||
disk=$(mktemp)
|
||||
truncate -s 6G $disk
|
||||
mdconfig -a -t vnode -f $disk -u md0
|
||||
gpart create -s gpt /dev/md0
|
||||
gpart add -t freebsd-boot -l bootfs -b 40 -s 512K md0
|
||||
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 md0
|
||||
|
@ -44,12 +49,12 @@ mount -t devfs devfs /mnt/dev
|
|||
|
||||
# Download and extract base system.
|
||||
dist_files="kernel.txz base.txz"
|
||||
dist_dir="/usr/freebsd-dist/$arch/$release"
|
||||
dist_dir="/usr/freebsd-dist/$ARCH/$RELEASE"
|
||||
|
||||
mkdir -p "$dist_dir"
|
||||
for f in $dist_files
|
||||
do
|
||||
fetch -m -o "$dist_dir/$f" "$dist_base/$f"
|
||||
fetch -m -o "$dist_dir/$f" "$DIST_BASE/$f"
|
||||
tar -C /mnt -xJf "$dist_dir/$f"
|
||||
done
|
||||
|
||||
|
@ -83,11 +88,11 @@ FreeBSD: {
|
|||
EOF
|
||||
|
||||
# freebsd-update is only supported for RELEASE
|
||||
if [ "${release%-RELEASE}" != "$release" ]
|
||||
if [ "${release%-RELEASE}" != "$RELEASE" ]
|
||||
then
|
||||
env PAGER=true /usr/sbin/freebsd-update \
|
||||
-b /mnt \
|
||||
--currently-running "$release" \
|
||||
--currently-running "$RELEASE" \
|
||||
--not-running-from-cron -F \
|
||||
fetch install
|
||||
fi
|
||||
|
@ -95,15 +100,15 @@ fi
|
|||
env ASSUME_ALWAYS_YES=YES pkg -c /mnt bootstrap -f
|
||||
env ASSUME_ALWAYS_YES=YES pkg -c /mnt install bash
|
||||
|
||||
fetch -m -o "$dist_dir/ports.txz" "$ports_base/ports.txz"
|
||||
fetch -m -o "$dist_dir/ports.txz" "$PORTS_BASE/ports.txz"
|
||||
tar -C /mnt -xJf "$dist_dir/ports.txz"
|
||||
|
||||
cleanup
|
||||
trap : EXIT
|
||||
|
||||
mkdir -p "$arch"
|
||||
qemu-img convert -f raw -O qcow2 disk.img "$arch"/root.img.qcow2
|
||||
rm disk.img
|
||||
mkdir -p "$ARCH"
|
||||
qemu-img convert -f raw -O qcow2 $disk "$ARCH"/root.img.qcow2
|
||||
rm $disk
|
||||
|
||||
# Filesystem will be enlarged by growfs(7) on next startup
|
||||
qemu-img resize $IMAGE_PATH $IMAGE_SIZE
|
||||
|
|
Loading…
Reference in a new issue