"nanobsd" prototype

From: Poul-Henning Kamp <phk_at_phk.freebsd.dk>
Date: Wed, 10 Mar 2004 00:16:37 +0100
This patch contains my "nanobsd" prototype which I have been mumbling
about.

What this does is build a CF friendly image with three slices, two
"image" slices and an "etc" slice.

The two image slices can be booted as read-only root filesystems
and when one is used, the other can be updated with a new image.

Boot0 is used so you can select which of the two you want to boot
from.

If you update the image in slice2 you need to change /etc/fstab
to match (sed -i "" -e s/ad0s1/ad0s2/ /mnt/etc/fstab)

The etc slice (ad0s3) is where all the machine specific files
for /etc should go.

To try this out you need a -current system which has the
etc/rc.d/initdiskless commit I made a minute ago and then:

	mkdir /usr/src/nanobsd
	cd /usr/src/nanobsd
	patch < this_file
	# possibly edit Makefile and make.conf
	make obj
	make
	dd if=/usr/obj/`pwd`/_.i of=/dev/$CFDEVICE bs=64k
	mount /dev/${CFDEVICE}s3 /mnt
	cp /the/stuff/I/want/in/etc/* /mnt
	umount /mnt
	# move CF device to embedded platform and try it.

Feedback of all sorts most welcome!  And more documentation
to arrive as it gets written.

Poul-Henning


--- /dev/null	Wed Mar 10 00:02:50 2004
+++ Makefile	Tue Mar  9 23:54:53 2004
_at__at_ -0,0 +1,121 _at__at_
+# $FreeBSD$
+
+MAKEJ="-j12"
+
+HD=16
+SC=32
+SECTS=501760
+DATASLICE=2048
+
+KERNCONF?= GENERIC
+WORLDDIR?= ${.CURDIR}/..
+WD?=	${.OBJDIR}/_.w
+
+all:	buildworld installworld buildimage
+
+
+#
+# This is where you customizations to the image can be performed
+# Please make sure to do everything relative to ${WD} here.
+#
+Customize:	_.cs
+_.cs:	_.iw _.di _.ik _.di
+	echo "/dev/ad0s1a / ufs ro 1 1" >  ${WD}/etc/fstab
+	sed -i "" -e /beastie/d ${WD}/boot/loader.rc
+	sed -i "" -e /ttyd0/s/off/on/ ${WD}/etc/ttys
+	echo " -h" > ${WD}/boot.config
+	touch _.cs
+
+###########################################################################
+#
+# The rest is pretty (or ugly if you prefer) magic, and should generally
+# not need to be fiddled with.  Good luck if you need to venture past this
+# point.
+#
+
+# Run a buildworld with our private make.conf
+buildworld:	_.bw
+_.bw:
+	(cd ${WORLDDIR} && \
+		make ${MAKEJ} -s buildworld __MAKE_CONF=${.CURDIR}/make.conf \
+		) > _.bw.tmp 2>&1
+	mv _.bw.tmp _.bw
+
+# Run installworld and install into our object directory
+installworld:	_.iw
+_.iw:	_.bw
+	-rm -rf ${WD} > /dev/null 2>&1
+	-chflags -R noschg ${WD} > /dev/null 2>&1
+	rm -rf ${WD}
+	mkdir -p ${WD}
+	(cd ${WORLDDIR} && \
+		make ${MAKEJ} -s installworld \
+		DESTDIR=${WD} \
+		__MAKE_CONF=${.CURDIR}/make.conf \
+		) > _.iw.tmp 2>&1
+	mv _.iw.tmp _.iw
+
+# Run distribution target in /etc.
+_.di:	_.iw
+	mkdir -p ${WD}
+	(cd ${WORLDDIR}/etc && \
+		make ${MAKEJ} -s distribution \
+		DESTDIR=${WD} \
+		__MAKE_CONF=${.CURDIR}/make.conf \
+		) > _.di.tmp 2>&1
+	mv _.di.tmp _.di
+
+# Build kernel
+_.bk:	${WORLDDIR}/sys/i386/conf/${KERNCONF}
+	(cd ${WORLDDIR} && \
+		make ${MAKEJ} -s buildkernel \
+		KERNCONF=${KERNCONF} \
+		__MAKE_CONF=${.CURDIR}/make.conf \
+		) > _.bk.tmp 2>&1
+	mv _.bk.tmp _.bk
+
+# Install kernel and hints file
+_.ik:	_.bk _.di
+	cp ${WORLDDIR}/sys/i386/conf/GENERIC.hints ${WD}/boot/device.hints
+	(cd ${WORLDDIR} && \
+		make ${MAKEJ} installkernel \
+		KERNCONF=${KERNCONF} \
+		DESTDIR=${WD} \
+		__MAKE_CONF=${.CURDIR}/make.conf \
+		) > _.ik.tmp 2>&1
+	mv _.ik.tmp _.ik
+
+
+# Create a disk image from the installed image
+buildimage:	_.md
+_.md:	_.cs
+	-umount ${WD}/dev > /dev/null 2>&1
+	chflags -R noschg ${WD} > /dev/null 2>&1
+	rm -rf ${WD}/var/* ${WD}/dev/* ${WD}/tmp
+	# create trigger file for etc/rc.d/initdiskless
+	touch ${WD}/etc/diskless
+	mkdir -p ${WD}/conf/base/var
+	mtree -deU -f ${WD}/etc/mtree/BSD.var.dist -p ${WD}/conf/base/var
+	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/ad0s3" > ${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
+	mtree -deU -f ${WD}/etc/mtree/BSD.include.dist -p ${WD}/usr/include
+.if exists(${WD}/etc/mtree/BSD.sendmail.dist)
+	mtree -deU -f ${WD}/etc/mtree/BSD.sendmail.dist -p ${WD}/
+.endif
+	(cd ${WD} && mtree -c -Kmd5digest ) > _.mtree.tmp
+	${.CURDIR}/i386.diskimage \
+		${SECTS} \
+		${HD} \
+		${SC} \
+		${DATASLICE} \
+		${WD} ${.OBJDIR}/_.i \
+		> _.md.tmp 2>&1
+	mv _.mtree.tmp _.mtree
+	mv _.md.tmp _.md
+
+.include <bsd.obj.mk>
--- /dev/null	Wed Mar 10 00:02:50 2004
+++ i386.diskimage	Tue Mar  9 22:52:49 2004
_at__at_ -0,0 +1,31 _at__at_
+#!/bin/sh
+# ${.CURDIR}/i386.diskimage $SECTS $HD $SC $DATASLICE ${.OBJDIR}/_.w ${.OBJDIR}/_.i
+# XXX: newfs params.
+
+set -ex
+
+dd if=/dev/zero of=/tmp/$$.d count=$1
+MD=`mdconfig -a -t vnode -f /tmp/$$.d -x $3 -y $2`
+rm -f /tmp/$$.d
+(
+sl=`expr "(" $1 - $3 - $4 ")" / 2`
+echo p 1 165 $3 $sl
+echo p 2 165 `expr $3 + $sl` $sl
+echo p 3 165 `expr $3 + $sl + $sl` $4
+) > /tmp/$$
+cat /tmp/$$
+fdisk -i -f /tmp/$$ $MD
+fdisk $MD
+boot0cfg -B -b /boot/boot0sio -s 1 -m 3 $MD 
+rm -f /tmp/$$
+bsdlabel -w -B ${MD}s1
+newfs -O1 -U ${MD}s1a
+newfs -O1 -U ${MD}s3
+mount /dev/${MD}s1a /mnt
+(cd $5 && find . -print | cpio -dump /mnt) || true
+df /mnt
+umount /mnt
+dd if=/dev/${MD}s1 of=/dev/${MD}s2 bs=64k
+dd if=/dev/${MD} of=$6 bs=64k
+dd if=/dev/${MD}s1 of=${6}.s1 bs=64k
+mdconfig -d -u ${MD}
--- /dev/null	Wed Mar 10 00:02:50 2004
+++ make.conf	Tue Mar  9 22:50:34 2004
_at__at_ -0,0 +1,31 _at__at_
+NO_SENDMAIL=yes
+NO_KERBEROS=yes
+NO_IPFILTER=yes
+NO_LPR=yes
+NO_I4B=yes
+NO_CXX=yes
+NO_FORTRAN=yes
+NO_OBJC=yes
+NOHTML=yes
+NO_GDB=yes
+NO_GCOV=yes
+NOINET6=yes
+NORADIUS=yes
+NOPROFILE=yes
+NOLIBPTHREAD=yes
+NOLIBTHR=yes
+#NO_YP_LIBC=yes
+NO_HESIOD_LIBC=yes
+NO_SHAREDOCS=yes
+NO_CVS=yes
+NOMAN=yes
+NOATM=yes
+NO_USB=yes
+NO_VINUM=yes
+NO_TOOLCHAIN=yes
+NO_ACPI=yes
+NO_RESCUE=yes
+NOGAMES=yes
+NOINFO=yes
+NO_MODULES=yes
+NO_PF=YES
-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk_at_FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
Received on Tue Mar 09 2004 - 14:16:40 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:46 UTC