Changeset View
Changeset View
Standalone View
Standalone View
tools/tools/nanobsd/defaults.sh
Show First 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | |||||
# boot2 flags/options | # boot2 flags/options | ||||
# default force serial console | # default force serial console | ||||
NANO_BOOT2CFG="-h" | NANO_BOOT2CFG="-h" | ||||
# Backing type of md(4) device | # Backing type of md(4) device | ||||
# Can be "file" or "swap" | # Can be "file" or "swap" | ||||
NANO_MD_BACKING="file" | NANO_MD_BACKING="file" | ||||
# for swap type md(4) backing, write out the mbr only | # For swap type md(4) backing, write out the mbr only | ||||
NANO_IMAGE_MBRONLY=true | NANO_IMAGE_MBRONLY=true | ||||
# Partitioning scheme: MBR or GPT | |||||
NANO_PART_SCHEME=MBR | |||||
# Progress Print level | # Progress Print level | ||||
PPLEVEL=3 | PPLEVEL=3 | ||||
# Set NANO_LABEL to non-blank to form the basis for using /dev/ufs/label | # Set NANO_LABEL to non-blank to form the basis for using /dev/ufs/label | ||||
# in preference to /dev/${NANO_DRIVE} | # in preference to /dev/${NANO_DRIVE} | ||||
# Root partition will be ${NANO_LABEL}s{1,2} | # Root partition will be ${NANO_LABEL}s{1,2} | ||||
# /cfg partition will be ${NANO_LABEL}s3 | # /cfg partition will be ${NANO_LABEL}s3 | ||||
# /data partition will be ${NANO_LABEL}s4 | # /data partition will be ${NANO_LABEL}s4 | ||||
▲ Show 20 Lines • Show All 260 Lines • ▼ Show 20 Lines | do | ||||
mkdir -p conf/base/$d conf/default/$d | mkdir -p conf/base/$d conf/default/$d | ||||
find $d -print | cpio -dumpl conf/base/ | find $d -print | cpio -dumpl conf/base/ | ||||
done | done | ||||
echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size | echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size | ||||
echo "$NANO_RAM_TMPVARSIZE" > conf/base/var/md_size | echo "$NANO_RAM_TMPVARSIZE" > conf/base/var/md_size | ||||
# pick up config files from the special partition | # pick up config files from the special partition | ||||
echo "mount -o ro /dev/${NANO_DRIVE}s3" > conf/default/etc/remount | echo "mount -o ro /dev/${NANO_DRIVE}${SLICE}3" > conf/default/etc/remount | ||||
imp: Why not have
CFG_PART=s3 # for MBR
or
CFG_PART=p3 # for GPT
CFG_DEV=${NANO_DRIVE}${CFG_PART}… | |||||
# Put /tmp on the /var ramdisk (could be symlink already) | # Put /tmp on the /var ramdisk (could be symlink already) | ||||
nano_rm -rf tmp | nano_rm -rf tmp | ||||
ln -s var/tmp tmp | ln -s var/tmp tmp | ||||
) > ${NANO_OBJ}/_.dl 2>&1 | ) > ${NANO_OBJ}/_.dl 2>&1 | ||||
) | ) | ||||
setup_nanobsd_etc ( ) ( | setup_nanobsd_etc ( ) ( | ||||
pprint 2 "configure nanobsd /etc" | pprint 2 "configure nanobsd /etc" | ||||
( | ( | ||||
cd ${NANO_WORLDDIR} | cd ${NANO_WORLDDIR} | ||||
# create diskless marker file | # create diskless marker file | ||||
touch etc/diskless | touch etc/diskless | ||||
# Make root filesystem R/O by default | # Make root filesystem R/O by default | ||||
echo "root_rw_mount=NO" >> etc/defaults/rc.conf | echo "root_rw_mount=NO" >> etc/defaults/rc.conf | ||||
# save config file for scripts | # save config file for scripts | ||||
echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf | echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf | ||||
echo "/dev/${NANO_DRIVE}s1a / ufs ro 1 1" > etc/fstab | echo "/dev/${NANO_DRIVE}${SYS1_SLICE} / ufs ro 1 1" > etc/fstab | ||||
echo "/dev/${NANO_DRIVE}s3 /cfg ufs rw,noauto 2 2" >> etc/fstab | echo "/dev/${NANO_DRIVE}${SLICE}3 /cfg ufs rw,noauto 2 2" >> etc/fstab | ||||
mkdir -p cfg | mkdir -p cfg | ||||
) | ) | ||||
) | ) | ||||
prune_usr() ( | prune_usr() ( | ||||
# Remove all empty directories in /usr | # Remove all empty directories in /usr | ||||
find ${NANO_WORLDDIR}/usr -type d -depth -print | | find ${NANO_WORLDDIR}/usr -type d -depth -print | | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | populate_data_slice ( ) ( | ||||
populate_slice "$1" "$2" "$3" "$4" | populate_slice "$1" "$2" "$3" "$4" | ||||
) | ) | ||||
create_diskimage ( ) ( | create_diskimage ( ) ( | ||||
pprint 2 "build diskimage" | pprint 2 "build diskimage" | ||||
pprint 3 "log: ${NANO_OBJ}/_.di" | pprint 3 "log: ${NANO_OBJ}/_.di" | ||||
( | ( | ||||
echo $NANO_MEDIASIZE $NANO_IMAGES \ | case $NANO_PART_SCHEME in | ||||
MBR) | |||||
unset GPART_LABEL | |||||
GPART_BOOTFL="active" | |||||
GPART_UFS="freebsd" | |||||
NANO_GPART_MEDIASIZE=${NANO_MEDIASIZE} | |||||
;; | |||||
GPT) | |||||
GPART_LABEL="-l ${NANO_LABEL}" | |||||
GPART_BOOTFL="bootme" | |||||
GPART_UFS="freebsd-ufs" | |||||
NANO_GPART_MEDIASIZE=$((${NANO_MEDIASIZE} - 256)) | |||||
# Reserve 256 sectors for boot partition | |||||
;; | |||||
esac | |||||
echo $NANO_GPART_MEDIASIZE $NANO_IMAGES \ | |||||
$NANO_SECTS $NANO_HEADS \ | $NANO_SECTS $NANO_HEADS \ | ||||
$NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE | | $NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE | | ||||
awk ' | awk ' | ||||
impUnsubmitted Not Done Inline ActionsWon't gpart do all this math now so we don't need to? And can't we just call gpart directly to do it? imp: Won't gpart do all this math now so we don't need to? And can't we just call gpart directly to… | |||||
{ | { | ||||
printf "# %s\n", $0 | printf "# %s\n", $0 | ||||
print "create -s '$NANO_PART_SCHEME'" | |||||
# size of cylinder in sectors | # size of cylinder in sectors | ||||
cs = $3 * $4 | cs = $3 * $4 | ||||
# number of full cylinders on media | # number of full cylinders on media | ||||
cyl = int ($1 / cs) | 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) { | if ($7 > 0) { | ||||
# size of data partition in full cylinders | # size of data partition in full cylinders | ||||
dsl = int (($7 + cs - 1) / cs) | dsl = int (($7 + cs - 1) / cs) | ||||
} else { | } else { | ||||
dsl = 0; | dsl = 0; | ||||
} | } | ||||
# size of config partition in full cylinders | # size of config partition in full cylinders | ||||
csl = int (($6 + cs - 1) / cs) | csl = int (($6 + cs - 1) / cs) | ||||
if ($5 == 0) { | if ($5 == 0) { | ||||
# size of image partition(s) in full cylinders | # size of image partition(s) in full cylinders | ||||
isl = int ((cyl - dsl - csl) / $2) | isl = int ((cyl - dsl - csl) / $2) | ||||
} else { | } else { | ||||
isl = int (($5 + cs - 1) / cs) | isl = int (($5 + cs - 1) / cs) | ||||
} | } | ||||
# First image partition start at second track | # First image partition start at second track | ||||
print "p 1 165 " $3, isl * cs - $3 | print "add -t ${GPART_UFS} -b " $3 " -s " isl * cs - $3 " -i 1 ${GPART_LABEL+${GPART_LABEL}${SLICE}1}" | ||||
print "set -i 1 -a ${GPART_BOOTFL}" | |||||
c = isl * cs; | c = isl * cs; | ||||
# Second image partition (if any) also starts offset one | # Second image partition (if any) also starts offset one | ||||
# track to keep them identical. | # track to keep them identical. | ||||
if ($2 > 1) { | if ($2 > 1) { | ||||
print "p 2 165 " $3 + c, isl * cs - $3 | print "add -t ${GPART_UFS} -b " $3 + c " -s " isl * cs - $3 " -i 2 ${GPART_LABEL+${GPART_LABEL}${SLICE}2}" | ||||
c += isl * cs; | c += isl * cs; | ||||
} | } | ||||
# Config partition starts at cylinder boundary. | # Config partition starts at cylinder boundary. | ||||
print "p 3 165 " c, csl * cs | print "add -t ${GPART_UFS} -b " c " -s " csl * cs " -i 3 ${GPART_LABEL+${GPART_LABEL}${SLICE}3}" | ||||
c += csl * cs | c += csl * cs | ||||
# Data partition (if any) starts at cylinder boundary. | # Data partition (if any) starts at cylinder boundary. | ||||
if ($7 > 0) { | if ($7 > 0) { | ||||
print "p 4 165 " c, dsl * cs | print "add -t ${GPART_UFS} -b " c " -s " dsl * cs " -i 4 ${GPART_LABEL+${GPART_LABEL}${SLICE}4}" | ||||
} else if ($7 < 0 && $1 > c) { | } else if ($7 < 0 && $1 > c) { | ||||
print "p 4 165 " c, $1 - c | print "add -t ${GPART_UFS} -b " c " -s " $1 - c " -i 4 ${GPART_LABEL+${GPART_LABEL}${SLICE}4}" | ||||
} else if ($1 < c) { | } else if ($1 < c) { | ||||
print "Disk space overcommitted by", \ | print "Disk space overcommitted by", \ | ||||
c - $1, "sectors" > "/dev/stderr" | c - $1, "sectors" > "/dev/stderr" | ||||
exit 2 | exit 2 | ||||
} | } | ||||
print "commit!" | |||||
# Force slice 1 to be marked active. This is necessary | print "show!" | ||||
# for booting the image from a USB device to work. | |||||
print "a 1" | |||||
} | } | ||||
' > ${NANO_OBJ}/_.fdisk | ' | sed -e 's/^[^#]/gpart &/' -e 's/[^!]$/& -f x!/' -e 's/!$/ ${MD}/' > ${NANO_OBJ}/_.gpart | ||||
IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME} | IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME} | ||||
MNT=${NANO_OBJ}/_.mnt | MNT=${NANO_OBJ}/_.mnt | ||||
mkdir -p ${MNT} | mkdir -p ${MNT} | ||||
if [ "${NANO_MD_BACKING}" = "swap" ] ; then | if [ "${NANO_MD_BACKING}" = "swap" ] ; then | ||||
MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \ | MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \ | ||||
-y ${NANO_HEADS}` | -y ${NANO_HEADS}` | ||||
else | else | ||||
echo "Creating md backing file..." | echo "Creating md backing file..." | ||||
nano_rm -f ${IMG} | nano_rm -f ${IMG} | ||||
dd if=/dev/zero of=${IMG} seek=${NANO_MEDIASIZE} count=0 | dd if=/dev/zero of=${IMG} seek=${NANO_MEDIASIZE} count=0 | ||||
MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \ | MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \ | ||||
-y ${NANO_HEADS}` | -y ${NANO_HEADS}` | ||||
fi | fi | ||||
trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT | trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT | ||||
fdisk -i -f ${NANO_OBJ}/_.fdisk ${MD} | (set -x; . ${NANO_OBJ}/_.gpart) | ||||
fdisk ${MD} | |||||
# XXX: params | # XXX: params | ||||
# XXX: pick up cached boot* files, they may not be in image anymore. | # XXX: pick up cached boot* files, they may not be in image anymore. | ||||
case $NANO_PART_SCHEME in | |||||
MBR) | |||||
# For MBR, we need to create a disklabel in the system slice to hold the | |||||
# boot blocks. | |||||
if [ -f ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ]; then | if [ -f ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ]; then | ||||
boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD} | boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD} | ||||
fi | fi | ||||
if [ -f ${NANO_WORLDDIR}/boot/boot ]; then | if [ -f ${NANO_WORLDDIR}/boot/boot ]; then | ||||
bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}s1 | bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}s1 | ||||
else | else | ||||
bsdlabel -w ${MD}s1 | bsdlabel -w ${MD}s1 | ||||
fi | fi | ||||
bsdlabel ${MD}s1 | bsdlabel ${MD}s1 | ||||
impUnsubmitted Not Done Inline ActionsI thought gpart was able to do this too, w/o needing to resort to bsdlabel at all. imp: I thought gpart was able to do this too, w/o needing to resort to bsdlabel at all.
| |||||
;; | |||||
GPT) | |||||
# For GPT, no bsdlabel is required, since the boot blocks live in their | |||||
# own freebsd-boot partition, and in any case gptboot expects freebsd-ufs | |||||
# partitions to contain an UFS filesystem, *not* a bsdlabel. | |||||
gpart add -t freebsd-boot -s 256 -i 15 ${GPART_LABEL}boot -f x ${MD} | |||||
if [ -f ${NANO_WORLDDIR}/boot/pmbr -a -f ${NANO_WORLDDIR}/boot/gptboot ]; then | |||||
gpart bootcode -b ${NANO_WORLDDIR}/boot/pmbr -p ${NANO_WORLDDIR}/boot/gptboot -i 15 -f x ${MD} | |||||
fi | |||||
gpart commit ${MD} | |||||
;; | |||||
esac | |||||
# Create first image | # Create first image | ||||
populate_slice /dev/${MD}s1a ${NANO_WORLDDIR} ${MNT} "s1a" | populate_slice /dev/${MD}${SYS1_SLICE} ${NANO_WORLDDIR} ${MNT} "${SYS1_SLICE}" | ||||
mount /dev/${MD}s1a ${MNT} | mount /dev/${MD}${SYS1_SLICE} ${MNT} | ||||
echo "Generating mtree..." | echo "Generating mtree..." | ||||
( cd ${MNT} && mtree -c ) > ${NANO_OBJ}/_.mtree | ( cd ${MNT} && mtree -c ) > ${NANO_OBJ}/_.mtree | ||||
( cd ${MNT} && du -k ) > ${NANO_OBJ}/_.du | ( cd ${MNT} && du -k ) > ${NANO_OBJ}/_.du | ||||
nano_umount ${MNT} | nano_umount ${MNT} | ||||
if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then | if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then | ||||
# Duplicate to second image (if present) | # Duplicate to second image (if present) | ||||
echo "Duplicating to second image..." | echo "Duplicating to second image..." | ||||
dd conv=sparse if=/dev/${MD}s1 of=/dev/${MD}s2 bs=64k | dd conv=sparse if=/dev/${MD}${SLICE}1 of=/dev/${MD}${SLICE}2 bs=64k | ||||
mount /dev/${MD}s2a ${MNT} | mount /dev/${MD}${SYS2_SLICE} ${MNT} | ||||
for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab | for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab | ||||
do | do | ||||
sed -i "" "s=${NANO_DRIVE}s1=${NANO_DRIVE}s2=g" $f | sed -i "" "s=${NANO_DRIVE}${SLICE}1=${NANO_DRIVE}${SLICE}2=g" $f | ||||
done | done | ||||
nano_umount ${MNT} | nano_umount ${MNT} | ||||
# Override the label from the first partition so we | # Override the label from the first partition so we | ||||
# don't confuse glabel with duplicates. | # don't confuse glabel with duplicates. | ||||
if [ ! -z ${NANO_LABEL} ]; then | if [ ! -z ${NANO_LABEL} ]; then | ||||
tunefs -L ${NANO_LABEL}"s2a" /dev/${MD}s2a | tunefs -L ${NANO_LABEL}"${SYS2_SLICE}" /dev/${MD}${SYS2_SLICE} | ||||
fi | fi | ||||
fi | fi | ||||
# Create Config slice | # Create Config slice | ||||
populate_cfg_slice /dev/${MD}s3 "${NANO_CFGDIR}" ${MNT} "s3" | populate_cfg_slice /dev/${MD}${SLICE}3 "${NANO_CFGDIR}" ${MNT} "${SLICE}3" | ||||
# Create Data slice, if any. | # Create Data slice, if any. | ||||
if [ $NANO_DATASIZE -ne 0 ] ; then | if [ $NANO_DATASIZE -ne 0 ] ; then | ||||
populate_data_slice /dev/${MD}s4 "${NANO_DATADIR}" ${MNT} "s4" | populate_data_slice /dev/${MD}${SLICE}4 "${NANO_DATADIR}" ${MNT} "${SLICE}4" | ||||
fi | fi | ||||
if [ "${NANO_MD_BACKING}" = "swap" ] ; then | if [ "${NANO_MD_BACKING}" = "swap" ] ; then | ||||
if [ ${NANO_IMAGE_MBRONLY} ]; then | if [ ${NANO_IMAGE_MBRONLY} ]; then | ||||
echo "Writing out _.disk.mbr..." | echo "Writing out _.disk.mbr..." | ||||
dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 count=1 | dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 count=1 | ||||
else | else | ||||
echo "Writing out ${NANO_IMGNAME}..." | echo "Writing out ${NANO_IMGNAME}..." | ||||
dd if=/dev/${MD} of=${IMG} bs=64k | dd if=/dev/${MD} of=${IMG} bs=64k | ||||
fi | fi | ||||
echo "Writing out ${NANO_IMGNAME}..." | echo "Writing out ${NANO_IMGNAME}..." | ||||
dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k | dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k | ||||
fi | fi | ||||
if ${do_copyout_partition} ; then | if ${do_copyout_partition} ; then | ||||
echo "Writing out _.disk.image..." | echo "Writing out _.disk.image..." | ||||
dd conv=sparse if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k | dd conv=sparse if=/dev/${MD}${SLICE}1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k | ||||
fi | fi | ||||
mdconfig -d -u $MD | mdconfig -d -u $MD | ||||
trap - 1 2 15 | trap - 1 2 15 | ||||
trap nano_cleanup EXIT | trap nano_cleanup EXIT | ||||
) > ${NANO_OBJ}/_.di 2>&1 | ) > ${NANO_OBJ}/_.di 2>&1 | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | set_defaults_and_export() { | ||||
test -n "${MAKEOBJDIRPREFIX}" || MAKEOBJDIRPREFIX=${NANO_OBJ} | test -n "${MAKEOBJDIRPREFIX}" || MAKEOBJDIRPREFIX=${NANO_OBJ} | ||||
test -n "${NANO_DISKIMGDIR}" || NANO_DISKIMGDIR=${NANO_OBJ} | test -n "${NANO_DISKIMGDIR}" || NANO_DISKIMGDIR=${NANO_OBJ} | ||||
NANO_WORLDDIR=${NANO_OBJ}/_.w | NANO_WORLDDIR=${NANO_OBJ}/_.w | ||||
NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build | NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build | ||||
NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install | NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install | ||||
# Override user's NANO_DRIVE if they specified a NANO_LABEL | # Override user's NANO_DRIVE if they specified a NANO_LABEL | ||||
[ ! -z "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}" | [ ! -z "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}" | ||||
# Set SLICE prefix character according to partitioning scheme | |||||
case ${NANO_PART_SCHEME} in | |||||
MBR) | |||||
SLICE=s | |||||
SYS1_SLICE=${SLICE}1a | |||||
SYS2_SLICE=${SLICE}2a | |||||
;; | |||||
GPT) | |||||
SLICE=p | |||||
SYS1_SLICE=${SLICE}1 | |||||
SYS2_SLICE=${SLICE}2 | |||||
;; | |||||
esac | |||||
# Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists. | # Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists. | ||||
[ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \ | [ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \ | ||||
NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}" | NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}" | ||||
NANO_STARTTIME=`date +%s` | NANO_STARTTIME=`date +%s` | ||||
pprint 3 "Exporting NanoBSD variables" | pprint 3 "Exporting NanoBSD variables" | ||||
export_var MAKEOBJDIRPREFIX | export_var MAKEOBJDIRPREFIX | ||||
Show All 26 Lines |
Why not have
CFG_PART=s3 # for MBR
or
CFG_PART=p3 # for GPT
CFG_DEV=${NANO_DRIVE}${CFG_PART}
and use that here:
echo "mount -o ro /dev/${CFG_DEV}" > conf/default/etc/remount
With similar for the other partitions / slices we used to use...