Properly identify the root filesystem to be used in /etc/fstab in each

slice of the flash card, ensuring that the loader will mount the root fs
from the booted slice by default.

Allow usage of FFS volume labels instead of hardcoded device names through
WITH_GEOM_VOL Makefile knob.

Approved by:	re (scottl)
This commit is contained in:
Thomas Quinot 2004-08-16 22:41:58 +00:00
parent b5c1da06a9
commit 87218f8807
2 changed files with 75 additions and 16 deletions

View File

@ -10,10 +10,19 @@
# parallism flag for make.
MAKEJ?="-j12"
.if defined(WITH_GEOM_VOL)
# Do not hardcode device names, use FFS volume labels instead.
# Requires 'options GEOM_VOL' in kernel.
PRIROOTSLICE= vol/sysflash1
ALTROOTSLICE= vol/sysflash2
CFGSLICE= vol/cfgflash
.else
# Some CF cards behave as slaves, (eg Lexar) and are assigned ad1.
DEVICE?= ad0
ROOTSLICE= ${DEVICE}s1a
CONFSLICE= ${DEVICE}s3
PRIROOTSLICE= ${DEVICE}s1a
ALTROOTSLICE= ${DEVICE}s2a
CFGSLICE= ${DEVICE}s3
.endif
# Physical disk paramters. Use diskinfo(8) on the target platform
# to find the correct numbers. We assume 512 bytes sectors.
@ -23,7 +32,7 @@ SECTS?=501760
# Number of sectors in the data slice (ad0s3). The rest of the disk
# will be split evenly between the two image slices (ad0s1/ad0s2)
DATASLICE?=10240
DATASIZE?=10240
# You probably do not need to change these.
WORLDDIR?= ${.CURDIR}/../../..
@ -62,7 +71,6 @@ all: buildworld installworld buildimage
#
Customize: _.cs
_.cs: _.iw _.di _.ik _.di
echo "/dev/${ROOTSLICE} / ufs ro 1 1" > ${WD}/etc/fstab
.if empty(CUSTOMIZE_PATH)
# useful stuff for diskless boot
sed -i "" -e /beastie/d ${WD}/boot/loader.rc
@ -144,7 +152,7 @@ _.md: _.cs
mkdir -p ${WD}/conf/base/etc
( cd ${WD}/etc && find . -print | cpio -dumpl ../conf/base/etc )
mkdir -p ${WD}/conf/default/etc
echo "mount -o ro /dev/${CONFSLICE}" > ${WD}/conf/default/etc/remount
echo "mount -o ro /dev/${CFGSLICE}" > ${WD}/conf/default/etc/remount
ln -s var/tmp ${WD}/tmp
mtree -deU -f ${WD}/etc/mtree/BSD.root.dist -p ${WD}/
mtree -deU -f ${WD}/etc/mtree/BSD.usr.dist -p ${WD}/usr
@ -157,7 +165,10 @@ _.md: _.cs
${SECTS} \
${HD} \
${SC} \
${DATASLICE} \
${DATASIZE} \
${PRIROOTSLICE} \
${ALTROOTSLICE} \
${CFGSLICE} \
${WD} ${.OBJDIR}/_.i \
${CFGMASTER_PATH} \
> _.md.tmp 2>&1

View File

@ -8,7 +8,9 @@
#
# Called as:
#
# ${.CURDIR}/i386.diskimage $SECTS $HD $SC $DATASLICE ${.OBJDIR}/_.w ${.OBJDIR}/_.i [ ${.CURDIR}/cfgmaster ]
# ${.CURDIR}/i386.diskimage $SECTS $HD $SC $DATASIZE \
# $PRIROOTSLICE $ALTROOTSLICE $CFGSLICE \
# ${.OBJDIR}/_.w ${.OBJDIR}/_.i [ ${.CURDIR}/cfgmaster ]
#
# XXX: newfs params.
@ -17,25 +19,49 @@ set -ex
SECTS=$1
HD=$2
SC=$3
DATASLICE=$4
WD=$5
IMG=$6
CFGMASTER=$7
DATASIZE=$4
PRIROOTSLICE=$5
ALTROOTSLICE=$6
CFGSLICE=$7
WD=$8
IMG=$9
CFGMASTER=$10
TMPFILE0=`mktemp -t nanobsd`
TMPFILE1=`mktemp -t nanobsd`
TMPMNT=`mktemp -d -t nanobsd`
make_fstab () {
echo "/dev/$1 / ufs ro 1 1" > ${WD}/etc/fstab
}
get_label () {
case "$1" in
vol/*)
echo -n "-L "; basename $1
;;
*)
echo ""
;;
esac
}
PRIROOTLABEL=`get_label ${PRIROOTSLICE}`
ALTROOTLABEL=`get_label ${ALTROOTSLICE}`
CFGLABEL=`get_label ${CFGSLICE}`
# Attach MD device and prepare slices
dd if=/dev/zero of=${TMPFILE0} count=${SECTS}
MD=`mdconfig -a -t vnode -f ${TMPFILE0} -x ${SC} -y ${HD}`
rm -f ${TMPFILE0}
(
sl=`expr "(" ${SECTS} - ${SC} - ${DATASLICE} ")" / 2`
sl=`expr "(" ${SECTS} - ${SC} - ${DATASIZE} ")" / 2`
cyl=`expr ${SECTS} / ${SC} / ${HD}`
echo g c${cyl} h${HD} s${SC}
echo p 1 165 ${SC} $sl
echo p 2 165 `expr ${SC} + $sl` $sl
echo p 3 165 `expr ${SC} + $sl + $sl` ${DATASLICE}
echo p 3 165 `expr ${SC} + $sl + $sl` ${DATASIZE}
) > ${TMPFILE1}
cat ${TMPFILE1}
fdisk -i -f ${TMPFILE1} ${MD}
@ -43,18 +69,40 @@ fdisk ${MD}
boot0cfg -B -b ${WD}/boot/boot0sio -s 1 -m 3 ${MD}
rm -f ${TMPFILE1}
bsdlabel -w -B ${MD}s1
newfs -O1 -U ${MD}s1a
newfs -O1 -U ${MD}s3
# Prepare primary root slice
newfs ${PRIROOTLABEL} -O1 -U ${MD}s1a
mount /dev/${MD}s1a ${TMPMNT}
(cd ${WD} && find . -print | cpio -dump ${TMPMNT}) || true
make_fstab ${PRIROOTSLICE}
df ${TMPMNT}
umount ${TMPMNT}
# Prepare alternative root slice
dd if=/dev/${MD}s1 of=/dev/${MD}s2 bs=64k
if [ -n "${ALTROOTLABEL}" ]; then
tunefs ${ALTROOTLABEL} /dev/${MD}s2a
fi
mount /dev/${MD}s2a ${TMPMNT}
make_fstab ${ALTROOTSLICE}
umount ${TMPMNT}
# Prepare configuration slice
newfs ${CFGLABEL} -O1 -U ${MD}s3
if [ -d "${CFGMASTER}" ]; then
mount /dev/${MD}s3 ${TMPMNT}
( cd ${CFGMASTER} && find . -print | cpio -dumpl ${TMPMNT} )
umount ${TMPMNT}
fi
dd if=/dev/${MD}s1 of=/dev/${MD}s2 bs=64k
# Create flash images
dd if=/dev/${MD} of=${IMG} bs=64k
dd if=/dev/${MD}s1 of=${IMG}.s1 bs=64k
# Detach MD device
mdconfig -d -u ${MD}