1187371Sphk$FreeBSD$
2187371Sphk
3187371SphkAbout sysbuild.sh
4187371Sphk=================
5187371Sphk
6187371SphkI have been running -current on my laptop since before FreeBSD 2.0 was
7187371Sphkreleased and along the way developed this little trick to making the
8187371Sphktask easier.
9187371Sphk
10187371Sphksysbuild.sh is a way to build a new FreeBSD system on a computer from
11187371Sphka specification, while leaving the current installation intact.
12187371Sphk
13187371Sphksysbuild.sh assume you have two partitions that can hold your rootfs
14187371Sphkand can be booted, and roughly speaking, all it does is build a new
15187371Sphksystem into the one you don't use, from the one you do use.
16187371Sphk
17187371SphkA partition named /freebsd is assumed to be part of your layout, and
18187371Sphkthat is where the sources and ports will be found.
19187371Sphk
20187371SphkIf you know how nanobsd works, you will find a lot of similarity.
21187371Sphk
22187371SphkHOWTO
23187371Sphk=====
24187371Sphk
25228975SuqsIn all likelihood, it is easier if we imagine you start with a blank
26187371Sphkcomputer.
27187371Sphk
28187371SphkGrab a FreeBSD install ISO and boot it.
29187371Sphk
30187371SphkCreate four disk slices:
31187371Sphk
32187371Sphk	ad0s1 = 5GB
33187371Sphk	ad0s2 = 5GB
34187371Sphk	ad0s3 = 5GB
35187371Sphk	ad0s4 = the rest
36187371Sphk
37187371SphkCreate a root filesystem in s1a filling the entire ad0s1 slice.
38187371Sphk
39187371SphkCreate a swap partition, if you want one, in ad0s4b.
40187371Sphk
41187371SphkInstall the boot0 bootmanager.
42187371Sphk
43187371SphkInstall the "Minimal" FreeBSD system into ad0s1a.
44187371Sphk
45187371SphkReboot from the newly installed system.
46187371Sphk
47187371SphkRun these commands to set up the other partitions sysbuild.sh cares about:
48187371Sphk
49187371Sphk	# /freebsd filesystem
50187371Sphk	newfs -b 4096 -f 512 -O2 -U /dev/ad0s3
51187371Sphk	echo "/dev/ad0s3 /freebsd ufs rw 2 2" >> /etc/fstab
52187371Sphk	mkdir /freebsd
53187371Sphk	mount /freebsd
54187371Sphk
55187371Sphk	# deputy rootfilesystem
56187371Sphk	bsdlabel -B -w /dev/ad0s2
57187371Sphk	newfs -O2 -U /dev/ad0s2a
58187371Sphk
59187371SphkNext, install ports and sources:
60187371Sphk
61187371Sphk	cd /usr
62187371Sphk	rm -rf ports src
63187371Sphk	ln -s /freebsd/src
64187371Sphk	ln -s /freebsd/ports
65187371Sphk	cd /freebsd
66187371Sphk	mkdir ports src packages
67187371Sphk
68187371Sphk	# Or use svn if you prefer
69187371Sphk	csup -h cvsup.???.freebsd.org /usr/share/examples/cvsup/ports-supfile
70187371Sphk	csup -h cvsup.???.freebsd.org /usr/share/examples/cvsup/stable-supfile
71187371Sphk
72187371SphkAnd we should be ready to try a shot:
73187371Sphk
74187371Sphk	cd /root
75187372Sphk	cp /usr/src/tools/tools/sysbuild/sysbuild.sh .
76187371Sphk	sh sysbuild.sh |& tee _.sb
77187371Sphk
78187371SphkIf it succeeds, you should be able to:
79187371Sphk
80187371Sphk	boot0cfg -s 2 -v /dev/ad0
81187371Sphk	reboot
82187371Sphk
83187371SphkAnd come up with your newly built system.
84187371Sphk
85187371Sphk	Next time you want a new system, you just run sysbuild.sh again
86187371Sphk	and boot slice 1 when it's done.
87187371Sphk
88187371SphkTWEAKS
89187371Sphk======
90187371Sphk
91187371SphkThe sysbuild.sh script takes various parameters:
92187371Sphk
93187371Sphk	-c specfile	# configure stuff, see below.
94187371Sphk	-w		# skip buildworld, assume it was done earlier.
95187371Sphk	-k		# skip buildkernel, ---//---
96187371Sphk	-b		# skip both buildworld & buildkernel
97187371Sphk	-p		# install cached packacges if found.
98187371Sphk
99187371SphkThe specfile is a shellscript where you can override or set a number of
100187371Sphkshell variables and functions.
101187371Sphk
102187371SphkA partial example:
103187371Sphk
104187371Sphk	# use a kernel different from GENERIC
105187371Sphk	KERNCONF=SMP
106187371Sphk
107187371Sphk	# Cache built packages, so we can use -p
108187371Sphk	PKG_DIR=/freebsd/packages
109187371Sphk
110187371Sphk	# Mount ports distfiles from another machine
111187371Sphk	REMOTEDISTFILES=fs:/rdonly/distfiles
112187371Sphk
113187371Sphk	# Fetch distfiles through a proxy
114187371Sphk	FTP_PROXY=http://127.0.0.1:3128/
115187371Sphk	HTTP_PROXY=http://127.0.0.1:3128/
116187371Sphk	export FTP_PROXY HTTP_PROXY
117187371Sphk
118187371Sphk	# We want these ports
119187371Sphk	PORTS_WE_WANT='
120187371Sphk		/usr/ports/archivers/unzip
121187371Sphk		/usr/ports/archivers/zip
122187371Sphk		/usr/ports/cad/linux-eagle
123187371Sphk		/usr/ports/comms/lrzsz
124187371Sphk		/usr/ports/databases/rrdtool 
125187371Sphk		/usr/ports/devel/subversion-freebsd
126187371Sphk	'
127187371Sphk
128187371Sphk	# Files to move over
129187371Sphk	CONFIGFILES='
130187371Sphk		/root/.ssh
131187371Sphk		/etc/X11/xorg.conf
132187371Sphk		/etc/ssh/ssh_host*
133187371Sphk		/etc/rc.conf
134187371Sphk		/etc/rc.local
135187371Sphk	'
136187371Sphk
137187371Sphk	# Shell functions to tweak things
138187371Sphk	# (This makes commits to /etc mostly painless)
139187371Sphk	final_chroot() (
140187371Sphk		chpass -p "\$1\$IgMjWs2L\$Nu12OCsjfiwHHj0I7TmUN1" root
141187371Sphk
142187371Sphk		pw useradd phk -u 488 -d /home/phk -c "Poul-Henning Kamp" \
143187371Sphk		    -G "wheel,operator,dialer" -s /bin/csh -w none
144187371Sphk
145187371Sphk		chpass -p "\$1\$VcM.9Ow8\$IcXHs0h9jsk27b8N64lOm/" phk
146187371Sphk
147187371Sphk		sed -i "" -e 's/^DS/DSorigo.freebsd.dk/' /etc/mail/sendmail.cf
148187371Sphk		sed -i "" -e '/console/s/^/#/' /etc/syslog.conf
149187371Sphk		echo "beastie_disable=YES" >> /boot/loader.conf
150187371Sphk		touch /root/.hushlogin
151187371Sphk	)
152187371Sphk
153187371Sphk
154