build/nano: complete revamp leaving NanoBSD behind

Images are clamped to just under 4G with a single slice
in a hybrid manner of vm/serial images.  This should
provide wide compatibility and fit any 4G card, and can
then be expanded to whatever we really have using growfs.

Smaller images are possible too, but not recommended due
to the fact that firmware upgrades need to be downloaded
and extracted.  We could make 2G the new default, but
future size requirements and a steady 4G image seem like
a more favourable goal in the long term.
This commit is contained in:
Franco Fichtner 2016-12-02 21:23:24 +01:00
parent 641389e31a
commit 54fa4c1dc7
4 changed files with 44 additions and 113 deletions

View File

@ -7,7 +7,6 @@ is a standard BSD 2-Clause as reproduced here for your convenience:
Copyright (c) 2014-2016 Franco Fichtner <franco@opnsense.org>
Copyright (c) 2004-2011 Scott Ullrich <sullrich@gmail.com>
Copyright (c) 2005 Poul-Henning Kamp <phk@FreeBSD.org>
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -122,7 +121,7 @@ A vga memstick image is created using:
# make vga
A flash card disk image (NanoBSD) is created using:
A flash card disk image is created using:
# make nano
@ -215,6 +214,11 @@ A verification of all available set signatures is done via:
# make verify
Nano images can be adjusted in size using an argument as follows,
with the default of 3800M:
# make nano-<size>
Virtual machine images come in varying disk formats and sizes.
The default format is vmdk with 20G and 1G swap. If you want
to change that you can manually alter the invoke using:

View File

@ -2,7 +2,6 @@
# Copyright (c) 2015-2016 Franco Fichtner <franco@opnsense.org>
# Copyright (c) 2004-2009 Scott Ullrich <sullrich@gmail.com>
# Copyright (c) 2005 Poul-Henning Kamp <phk@FreeBSD.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@ -35,124 +34,48 @@ SELF=nano
check_images ${SELF} ${@}
NANOSIZE="3800M"
if [ -n "${1}" ]; then
NANOSIZE=${1}
fi
NANOIMG="${IMAGESDIR}/${PRODUCT_RELEASE}-nano-${PRODUCT_ARCH}.img"
NANOBASE="${STAGEDIR}/nanobase"
sh ./clean.sh ${SELF}
. ${SRCDIR}/tools/tools/nanobsd/FlashDevice.sub
sub_FlashDevice generic 4g
setup_stage ${STAGEDIR} mnt
# chop off excess bytes that do not align to 8 byte boundary
NANO_MEDIASIZE=$(expr ${NANO_MEDIASIZE} - \( ${NANO_MEDIASIZE} % 8 \))
truncate -s ${NANOSIZE} ${NANOBASE}
MD=$(mdconfig -f ${NANOBASE})
newfs /dev/${MD}
mount /dev/${MD} ${STAGEDIR}/mnt
setup_stage ${STAGEDIR} mnt work
setup_base ${STAGEDIR}/work
setup_kernel ${STAGEDIR}/work
setup_packages ${STAGEDIR}/work
setup_extras ${STAGEDIR}/work ${SELF}
setup_base ${STAGEDIR}/mnt
MD=$(mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} -y ${NANO_HEADS})
# need these again later
cp -r ${STAGEDIR}/mnt/boot ${STAGEDIR}
# NanoBSD knobs; do not change lightly
NANO_IMAGES=2
NANO_CODESIZE=0
NANO_DATASIZE=0
NANO_CONFSIZE=102400
setup_kernel ${STAGEDIR}/mnt
setup_packages ${STAGEDIR}/mnt
setup_extras ${STAGEDIR}/mnt ${SELF}
setup_entropy ${STAGEDIR}/mnt
echo $NANO_MEDIASIZE $NANO_IMAGES \
$NANO_SECTS $NANO_HEADS \
$NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE |
awk '
{
printf "# %s\n", $0
echo "/dev/ufs/${LABEL} / ufs rw,async,noatime 1 1" > ${STAGEDIR}/mnt/etc/fstab
# size of cylinder in sectors
cs = $3 * $4
# number of full cylinders on media
cyl = int ($1 / cs)
# output fdisk geometry spec, truncate cyls to 1023
if (cyl <= 1023)
print "g c" cyl " h" $4 " s" $3
else
print "g c" 1023 " h" $4 " s" $3
if ($7 > 0) {
# size of data partition in full cylinders
dsl = int (($7 + cs - 1) / cs)
} else {
dsl = 0;
}
# size of config partition in full cylinders
csl = int (($6 + cs - 1) / cs)
if ($5 == 0) {
# size of image partition(s) in full cylinders
isl = int ((cyl - dsl - csl) / $2)
} else {
isl = int (($5 + cs - 1) / cs)
}
# First image partition start at second track
print "p 1 165 " $3, isl * cs - $3
c = isl * cs;
# Second image partition (if any) also starts offset one
# track to keep them identical.
if ($2 > 1) {
print "p 2 165 " $3 + c, isl * cs - $3
c += isl * cs;
}
# Config partition starts at cylinder boundary.
print "p 3 165 " c, csl * cs
c += csl * cs
# Data partition (if any) starts at cylinder boundary.
if ($7 > 0) {
print "p 4 165 " c, dsl * cs
} else if ($7 < 0 && $1 > c) {
print "p 4 165 " c, $1 - c
} else if ($1 < c) {
print "Disk space overcommitted by", \
c - $1, "sectors" > "/dev/stderr"
exit 2
}
# Force slice 1 to be marked active. This is necessary
# for booting the image from a USB device to work.
print "a 1"
}
' | fdisk -i -f - ${MD}
boot0cfg -B -b ${STAGEDIR}/work/boot/boot0sio -o packet -s 1 -m 3 ${MD}
setup_partition()
{
# args 1:slice 2:label 3:mount 4:root
echo "/dev/ufs/${2} / ufs rw,async,noatime 1 1" > ${4}/etc/fstab
bsdlabel -w -B -b ${4}/boot/boot ${1}
newfs -b 4096 -f 512 -i 8192 -O1 -U ${1}a
tunefs -L ${2} ${1}a
mount -o async ${1}a ${3}
df -i ${3}
(cd ${4}; find . -print | cpio -dump ${3})
df -i ${3}
umount ${3}
}
setup_entropy ${STAGEDIR}/work
setup_partition /dev/${MD}s1 ${LABEL}0 ${STAGEDIR}/mnt ${STAGEDIR}/work
if [ ${NANO_IMAGES} -gt 1 ]; then
setup_entropy ${STAGEDIR}/work
setup_partition /dev/${MD}s2 ${LABEL}1 ${STAGEDIR}/mnt ${STAGEDIR}/work
fi
# move image from RAM to output file
dd if=/dev/${MD} of=${NANOIMG} bs=64k
umount ${STAGEDIR}/mnt
mdconfig -d -u ${MD}
echo -n ">>> Building nano image... "
mkimg -s bsd -f raw -o ${NANOIMG} \
-b ${STAGEDIR}/boot/boot \
-p freebsd-ufs:=${NANOBASE}
# mkimg does not support BSD label yet
MD=$(mdconfig -f ${NANOIMG})
tunefs -L ${LABEL} /dev/${MD}a
mdconfig -d -u ${MD}
echo "done"

View File

@ -39,6 +39,8 @@ kern.cam.boot_delay="10000"
boot_multicons="YES"
boot_serial="YES"
EOF
touch ${1}/.probe.for.growfs.nano
}
serial_hook()

View File

@ -39,6 +39,8 @@ kern.cam.boot_delay="10000"
boot_multicons="YES"
boot_serial="YES"
EOF
touch ${1}/.probe.for.growfs.nano
}
serial_hook()