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