Adjust hammer.sh for the new "fixbootfile" rc script.
[dragonfly.git] / share / examples / rconfig / hammer.sh
CommitLineData
62421adc
MD
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#
31927be5 16# $DragonFly: src/share/examples/rconfig/hammer.sh,v 1.4 2008/10/21 14:02:48 swildner Exp $
62421adc
MD
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"
2eca69e6 32 sleep 1
62421adc
MD
33end
34echo ""
62421adc
MD
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#
91604a1e 56dd if=/dev/zero of=/dev/${disk} bs=32k count=16
62421adc
MD
57fdisk -IB ${disk}
58disklabel -r -w ${disk}s1 auto
59disklabel -B ${disk}s1
60disklabel ${disk}s1 > /tmp/label
61cat >> /tmp/label << EOF
746e387a 62 a: 256m 32 4.2BSD
62421adc 63 b: 2g * swap
b034d49e 64 d: * * HAMMER
62421adc
MD
65EOF
66disklabel -R ${disk}s1 /tmp/label
62421adc
MD
67
68newfs /dev/${disk}s1a
69newfs_hammer -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
112chflags nohistory /mnt/tmp
113chflags nohistory /mnt/var/tmp
114chflags nohistory /mnt/var/crash
115chflags nohistory /mnt/usr/obj
116
117# Install the system from the live CD
118#
119cpdup -o / /mnt
3875f5b0
MD
120cpdup -o /boot /mnt/boot
121cpdup -o /usr /mnt/usr
62421adc
MD
122cpdup -o /var /mnt/var
123cpdup -o /dev /mnt/dev
124cpdup -i0 /etc.hdd /mnt/etc
125
126# Create some directories to be used for NFS mounts later on.
127# Edit as desired.
128#
129foreach i ( /proc /usr/doc /usr/src /repository /ftp /archive )
130 if ( ! -d /mnt$i ) then
131 mkdir /mnt$i
132 endif
133end
134
135cat > /mnt/etc/fstab << EOF
136# Device Mountpoint FStype Options Dump Pass#
137/dev/${disk}s1d / hammer rw 1 1
138/dev/${disk}s1a /boot ufs rw 1 1
31927be5 139/dev/${disk}s1b none swap sw 0 0
62421adc
MD
140/pfs/usr /usr null rw 0 0
141/pfs/var /var null rw 0 0
142/pfs/tmp /tmp null rw 0 0
143/pfs/home /home null rw 0 0
144/pfs/var.tmp /var/tmp null rw 0 0
145/pfs/usr.obj /usr/obj null rw 0 0
146/pfs/var.crash /var/crash null rw 0 0
147proc /proc procfs rw 0 0
148# misc NFS mounts to get your test box access to 'stuff'
149#crater:/repository /repository nfs ro,intr,bg 0 0
150#crater:/usr/doc /usr/doc nfs ro,intr,bg 0 0
151#crater:/ftp /ftp nfs ro,intr,bg 0 0
152#crater:/sources/HEAD /usr/src nfs ro,intr,bg 0 0
153#pkgbox:/archive /archive nfs ro,intr,bg 0 0
154EOF
155
156# Because root is not on the boot partition we have to tell the loader
157# to tell the kernel where root is.
158#
159cat > /mnt/boot/loader.conf << EOF
160vfs.root.mountfrom="hammer:${disk}s1d"
161EOF
162
163# Setup interface, configuration, sshd
164#
165set ifc = `route -n get default | fgrep interface | awk '{ print $2; }'`
166set ip = `ifconfig $ifc | fgrep inet | fgrep -v inet6 | awk '{ print $2; }'`
167set lip = `echo $ip | awk -F . '{ print $4; }'`
168
169echo -n "ifconfig_$ifc=" >> /mnt/etc/rc.conf
170echo '"DHCP"' >> /mnt/etc/rc.conf
171cat >> /mnt/etc/rc.conf << EOF
172sshd_enable="YES"
173dntpd_enable="YES"
174hostname="test$lip.MYDOMAIN.XXX"
175dumpdev="/dev/${disk}s1b"
176EOF
177
178# Misc sysctls
179#
180cat >> /mnt/etc/sysctl.conf << EOF
181#net.inet.ip.portrange.first=4000
182EOF
183
184# adjust work directory for pkgsrc in case we want
185# to mount /usr/pkgsrc read-only.
186#
187cat >> /mnt/usr/pkg/etc/mk.conf << EOF
188.ifdef BSD_PKG_MK # begin pkgsrc settings
189WRKOBJDIR= /usr/obj/pkgsrc
190.endif # end pkgsrc settings
191EOF
192
62421adc
MD
193# Allow sshd root logins via dsa key only
194#
195fgrep 'PermitRootLogin without-password' /mnt/etc/ssh/sshd_config >& /dev/null
196if ( $?status ) then
197 echo "PermitRootLogin without-password" >> /mnt/etc/ssh/sshd_config
198endif
199
200# additional loader.conf stuff
201#cat >> /mnt/boot/loader.conf << EOF
202#if_nfe_load="YES"
203#EOF
204
205# Get sshd working - auto install my key so I can login.
206#
207#mkdir -p /mnt/root/.ssh
208#cat > /mnt/root/.ssh/authorized_keys << EOF
209#ssh-dss ...
210#EOF
211
212if ( ! -f /mnt/etc/ssh/ssh_host_dsa_key ) then
213 cd /mnt/etc/ssh
214 ssh-keygen -t dsa -f ssh_host_dsa_key -N ""
215endif
216
217# take CD out and reboot
218#