Adjust kern.bootfile to make savecore(8) work.
[dragonfly.git] / share / examples / rconfig / hammer.sh
blob826e6063107f90fadbc1f5af409ec147e7fc0168
1 #!/bin/csh
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.
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).
13 # WARNING: HAMMER filesystems (and pseudo-filesystems) must be
14 # occassionally pruned and reblocked. 'man hammer' for more information.
16 # $DragonFly: src/share/examples/rconfig/hammer.sh,v 1.4 2008/10/21 14:02:48 swildner Exp $
18 set disk = "ad6"
20 # For safety this only runs on a CD-booted machine
22 df / | awk '{ print $1; }' | fgrep cd
23 if ( $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
27 endif
29 echo "This program formats disk ${disk}! Hit ^C now or its gone."
30 foreach i ( 10 9 8 7 6 5 4 3 2 1 )
31 echo -n " $i"
32 sleep 1
33 end
34 echo ""
36 # Unmount any prior mounts on /mnt, reverse order to unwind
37 # sub-directory mounts.
39 foreach i ( `df | fgrep /mnt | awk '{ print $6; }' | tail -r` )
40 echo "UMOUNT $i"
41 umount $i
42 end
44 # Set our disk here
46 sleep 1
47 set echo
49 # Format and label the disk.
51 # 'a' small UFS boot
52 # 'd' HAMMER filesystem
54 # Use PFSs for backup domain separation
56 fdisk -IB ${disk}
57 disklabel -r -w ${disk}s1 auto
58 disklabel -B ${disk}s1
59 disklabel ${disk}s1 > /tmp/label
60 cat >> /tmp/label << EOF
61 a: 256m 32 4.2BSD
62 b: 2g * swap
63 d: 123456 * HAMMER
64 EOF
65 disklabel -R ${disk}s1 /tmp/label
66 disklabel ${disk}s1 | sed -e 's/123456/*/g' > /tmp/label
67 disklabel -R ${disk}s1 /tmp/label
69 newfs /dev/${disk}s1a
70 newfs_hammer -L ROOT /dev/${disk}s1d
72 # Mount it
74 mount_hammer /dev/${disk}s1d /mnt
75 mkdir /mnt/boot
76 mount /dev/${disk}s1a /mnt/boot
78 # Create PFS mount points for nullfs.
80 # Do the mounts manually so we can install the system, setup
81 # the fstab later on.
82 mkdir /mnt/pfs
84 hammer pfs-master /mnt/pfs/usr
85 hammer pfs-master /mnt/pfs/usr.obj
86 hammer pfs-master /mnt/pfs/var
87 hammer pfs-master /mnt/pfs/var.crash
88 hammer pfs-master /mnt/pfs/var.tmp
89 hammer pfs-master /mnt/pfs/tmp
90 hammer pfs-master /mnt/pfs/home
92 mkdir /mnt/usr
93 mkdir /mnt/var
94 mkdir /mnt/tmp
95 mkdir /mnt/home
97 mount_null /mnt/pfs/usr /mnt/usr
98 mount_null /mnt/pfs/var /mnt/var
99 mount_null /mnt/pfs/tmp /mnt/tmp
100 mount_null /mnt/pfs/home /mnt/home
102 mkdir /mnt/usr/obj
103 mkdir /mnt/var/tmp
104 mkdir /mnt/var/crash
106 mount_null /mnt/pfs/var.tmp /mnt/var/tmp
107 mount_null /mnt/pfs/var.crash /mnt/var/crash
108 mount_null /mnt/pfs/usr.obj /mnt/usr/obj
110 chmod 1777 /mnt/tmp
111 chmod 1777 /mnt/var/tmp
113 chflags nohistory /mnt/tmp
114 chflags nohistory /mnt/var/tmp
115 chflags nohistory /mnt/var/crash
116 chflags nohistory /mnt/usr/obj
118 # Install the system from the live CD
120 cpdup -o / /mnt
121 cpdup -o /var /mnt/var
122 cpdup -o /dev /mnt/dev
123 cpdup -i0 /etc.hdd /mnt/etc
125 # Create some directories to be used for NFS mounts later on.
126 # Edit as desired.
128 foreach i ( /proc /usr/doc /usr/src /repository /ftp /archive )
129 if ( ! -d /mnt$i ) then
130 mkdir /mnt$i
131 endif
134 cat > /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
146 proc /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
155 # Since /boot is a separate partition we need to adjust kern.bootfile
156 # to make savecore work properly upon boot.
158 cat >> /mnt/etc/sysctl.conf << EOF
159 kern.bootfile=/boot/kernel
162 # Because root is not on the boot partition we have to tell the loader
163 # to tell the kernel where root is.
165 cat > /mnt/boot/loader.conf << EOF
166 vfs.root.mountfrom="hammer:${disk}s1d"
169 # Setup interface, configuration, sshd
171 set ifc = `route -n get default | fgrep interface | awk '{ print $2; }'`
172 set ip = `ifconfig $ifc | fgrep inet | fgrep -v inet6 | awk '{ print $2; }'`
173 set lip = `echo $ip | awk -F . '{ print $4; }'`
175 echo -n "ifconfig_$ifc=" >> /mnt/etc/rc.conf
176 echo '"DHCP"' >> /mnt/etc/rc.conf
177 cat >> /mnt/etc/rc.conf << EOF
178 sshd_enable="YES"
179 dntpd_enable="YES"
180 hostname="test$lip.MYDOMAIN.XXX"
181 dumpdev="/dev/${disk}s1b"
184 # Misc sysctls
186 cat >> /mnt/etc/sysctl.conf << EOF
187 #net.inet.ip.portrange.first=4000
190 # adjust work directory for pkgsrc in case we want
191 # to mount /usr/pkgsrc read-only.
193 cat >> /mnt/usr/pkg/etc/mk.conf << EOF
194 .ifdef BSD_PKG_MK # begin pkgsrc settings
195 WRKOBJDIR= /usr/obj/pkgsrc
196 .endif # end pkgsrc settings
199 # Allow sshd root logins via dsa key only
201 fgrep 'PermitRootLogin without-password' /mnt/etc/ssh/sshd_config >& /dev/null
202 if ( $?status ) then
203 echo "PermitRootLogin without-password" >> /mnt/etc/ssh/sshd_config
204 endif
206 # additional loader.conf stuff
207 #cat >> /mnt/boot/loader.conf << EOF
208 #if_nfe_load="YES"
209 #EOF
211 # Get sshd working - auto install my key so I can login.
213 #mkdir -p /mnt/root/.ssh
214 #cat > /mnt/root/.ssh/authorized_keys << EOF
215 #ssh-dss ...
216 #EOF
218 if ( ! -f /mnt/etc/ssh/ssh_host_dsa_key ) then
219 cd /mnt/etc/ssh
220 ssh-keygen -t dsa -f ssh_host_dsa_key -N ""
221 endif
223 # take CD out and reboot