xref: /dragonfly/share/examples/rconfig/hammer.sh (revision 0a319615)
1#!/bin/csh
2#
3# This will format a new machine with a BOOT+HAMMER setup and install
4# the live CD.  You would boot the live CD, dhclient your network up,
5# then run 'rconfig :hammer', assuming you have a rconfig server on the
6# LAN.  Alternately fetch the script from a known location and just run it.
7#
8# ad6s1a will be setup as a small UFS /boot.  ad6s1d will be setup as
9# HAMMER with all remaining disk space.  Pseudo file-systems will be
10# created for /var, /usr, etc (giving them separate inode spaces and
11# backup domains).
12#
13# WARNING: HAMMER filesystems (and pseudo-filesystems) must be
14# occassionally pruned and reblocked.  'man hammer' for more information.
15
16set disk = "ad6"
17
18# For safety this only runs on a CD- or PXE-booted machine
19#
20df / | egrep -q '^(.*cd|.+:)'
21if ( $status > 0 ) then
22    echo "This program formats your disk and you didn't run it from"
23    echo "a CD or NFS boot!"
24    exit 1
25endif
26
27echo "This program formats disk ${disk}!  Hit ^C now or its gone."
28foreach i ( 10 9 8 7 6 5 4 3 2 1 )
29    echo -n " $i"
30    sleep 1
31end
32echo ""
33
34# Unmount any prior mounts on /mnt, reverse order to unwind
35# sub-directory mounts.
36#
37foreach i ( `df | fgrep /mnt | awk '{ print $6; }' | tail -r` )
38    echo "UMOUNT $i"
39    umount $i
40end
41
42# Set our disk here
43#
44sleep 1
45set echo
46
47# Format and label the disk.
48#
49#	'a' small UFS boot
50#	'd' HAMMER filesystem
51#
52#	Use PFSs for backup domain separation
53#
54dd if=/dev/zero of=/dev/${disk} bs=32k count=16
55fdisk -IB ${disk}
56disklabel64 -r -w ${disk}s1
57disklabel64 -B ${disk}s1
58disklabel64 ${disk}s1 > /tmp/label
59
60cat >> /tmp/label << EOF
61  a: 768m 0 4.2BSD
62  b: 2g * swap
63  d: * * HAMMER
64EOF
65disklabel64 -R ${disk}s1 /tmp/label
66
67# Create file systems
68newfs /dev/${disk}s1a
69newfs_hammer -f -L ROOT /dev/${disk}s1d
70
71# Mount it
72#
73mount_hammer /dev/${disk}s1d /mnt
74mkdir /mnt/boot
75mount /dev/${disk}s1a /mnt/boot
76
77# Create PFS mount points for nullfs.
78#
79# Do the mounts manually so we can install the system, setup
80# the fstab later on.
81mkdir /mnt/pfs
82
83hammer pfs-master /mnt/pfs/usr
84hammer pfs-master /mnt/pfs/usr.obj
85hammer pfs-master /mnt/pfs/var
86hammer pfs-master /mnt/pfs/var.crash
87hammer pfs-master /mnt/pfs/var.tmp
88hammer pfs-master /mnt/pfs/tmp
89hammer pfs-master /mnt/pfs/home
90
91mkdir /mnt/usr
92mkdir /mnt/var
93mkdir /mnt/tmp
94mkdir /mnt/home
95
96mount_null /mnt/pfs/usr /mnt/usr
97mount_null /mnt/pfs/var /mnt/var
98mount_null /mnt/pfs/tmp /mnt/tmp
99mount_null /mnt/pfs/home /mnt/home
100
101mkdir /mnt/usr/obj
102mkdir /mnt/var/tmp
103mkdir /mnt/var/crash
104
105mount_null /mnt/pfs/var.tmp /mnt/var/tmp
106mount_null /mnt/pfs/var.crash /mnt/var/crash
107mount_null /mnt/pfs/usr.obj /mnt/usr/obj
108
109chmod 1777 /mnt/tmp
110chmod 1777 /mnt/var/tmp
111
112# Install the system from the live CD
113#
114cpdup -o / /mnt
115cpdup -o /boot /mnt/boot
116cpdup -o /usr /mnt/usr
117cpdup -o /var /mnt/var
118cpdup -i0 /etc.hdd /mnt/etc
119
120chflags -R nohistory /mnt/tmp
121chflags -R nohistory /mnt/var/tmp
122chflags -R nohistory /mnt/var/crash
123chflags -R nohistory /mnt/usr/obj
124
125# Create some directories to be used for NFS mounts later on.
126# Edit as desired.
127#
128foreach i ( /proc /usr/doc /usr/src /repository /ftp /archive )
129    if ( ! -d /mnt$i ) then
130	mkdir /mnt$i
131    endif
132end
133
134cat > /mnt/etc/fstab << EOF
135# Device		Mountpoint	FStype	Options		Dump	Pass#
136/dev/${disk}s1d		/		hammer	rw		1	1
137/dev/${disk}s1a		/boot		ufs	rw		1	1
138/dev/${disk}s1b		none		swap	sw		0	0
139/pfs/usr		/usr		null	rw		0	0
140/pfs/var		/var		null	rw		0	0
141/pfs/tmp		/tmp		null	rw		0	0
142/pfs/home		/home		null	rw		0	0
143/pfs/var.tmp		/var/tmp	null	rw		0	0
144/pfs/usr.obj		/usr/obj	null	rw		0	0
145/pfs/var.crash		/var/crash	null	rw		0	0
146proc			/proc		procfs	rw		0	0
147# misc NFS mounts to get your test box access to 'stuff'
148#crater:/repository	/repository	nfs	ro,intr,bg	0	0
149#crater:/usr/doc	/usr/doc	nfs	ro,intr,bg	0	0
150#crater:/ftp		/ftp		nfs	ro,intr,bg	0	0
151#crater:/sources/HEAD	/usr/src	nfs	ro,intr,bg	0	0
152#pkgbox:/archive	/archive	nfs	ro,intr,bg	0	0
153EOF
154
155# Because root is not on the boot partition we have to tell the loader
156# to tell the kernel where root is.
157#
158cat > /mnt/boot/loader.conf << EOF
159vfs.root.mountfrom="hammer:${disk}s1d"
160EOF
161
162# Setup interface, configuration, sshd
163#
164set ifc = `route -n get default | fgrep interface | awk '{ print $2; }'`
165set ip = `ifconfig $ifc | fgrep inet | fgrep -v inet6 | awk '{ print $2; }'`
166set lip = `echo $ip | awk -F . '{ print $4; }'`
167
168echo -n "ifconfig_$ifc=" >> /mnt/etc/rc.conf
169echo '"DHCP"' >> /mnt/etc/rc.conf
170cat >> /mnt/etc/rc.conf << EOF
171sshd_enable="YES"
172dntpd_enable="YES"
173hostname="test$lip.MYDOMAIN.XXX"
174dumpdev="/dev/${disk}s1b"
175EOF
176
177# Misc sysctls
178#
179cat >> /mnt/etc/sysctl.conf << EOF
180#net.inet.ip.portrange.first=4000
181EOF
182
183# Allow sshd root logins via dsa key only
184#
185fgrep 'PermitRootLogin without-password' /mnt/etc/ssh/sshd_config >& /dev/null
186if ( $?status ) then
187    echo "PermitRootLogin without-password" >> /mnt/etc/ssh/sshd_config
188endif
189
190# additional loader.conf stuff
191#cat >> /mnt/boot/loader.conf << EOF
192#if_nfe_load="YES"
193#EOF
194
195# Get sshd working - auto install my key so I can login.
196#
197#mkdir -p /mnt/root/.ssh
198#cat > /mnt/root/.ssh/authorized_keys << EOF
199#ssh-dss ...
200#EOF
201
202if ( ! -f /mnt/etc/ssh/ssh_host_dsa_key ) then
203    cd /mnt/etc/ssh
204    ssh-keygen -t dsa -f ssh_host_dsa_key -N ""
205endif
206
207# Misc cleanups
208#
209rm -R /mnt/README* /mnt/autorun* /mnt/index.html /mnt/dflybsd.ico
210rm /mnt/boot.catalog
211
212# take CD out and reboot
213#
214