xref: /dragonfly/share/examples/rconfig/hammer.sh (revision 0a319615)
162421adcSMatthew Dillon#!/bin/csh
262421adcSMatthew Dillon#
362421adcSMatthew Dillon# This will format a new machine with a BOOT+HAMMER setup and install
462421adcSMatthew Dillon# the live CD.  You would boot the live CD, dhclient your network up,
562421adcSMatthew Dillon# then run 'rconfig :hammer', assuming you have a rconfig server on the
662421adcSMatthew Dillon# LAN.  Alternately fetch the script from a known location and just run it.
762421adcSMatthew Dillon#
862421adcSMatthew Dillon# ad6s1a will be setup as a small UFS /boot.  ad6s1d will be setup as
962421adcSMatthew Dillon# HAMMER with all remaining disk space.  Pseudo file-systems will be
1062421adcSMatthew Dillon# created for /var, /usr, etc (giving them separate inode spaces and
1162421adcSMatthew Dillon# backup domains).
1262421adcSMatthew Dillon#
1362421adcSMatthew Dillon# WARNING: HAMMER filesystems (and pseudo-filesystems) must be
1462421adcSMatthew Dillon# occassionally pruned and reblocked.  'man hammer' for more information.
1562421adcSMatthew Dillon
1662421adcSMatthew Dillonset disk = "ad6"
1762421adcSMatthew Dillon
186a2fca96SSascha Wildner# For safety this only runs on a CD- or PXE-booted machine
1962421adcSMatthew Dillon#
20d98aab42SSascha Wildnerdf / | egrep -q '^(.*cd|.+:)'
2162421adcSMatthew Dillonif ( $status > 0 ) then
2262421adcSMatthew Dillon    echo "This program formats your disk and you didn't run it from"
236a2fca96SSascha Wildner    echo "a CD or NFS boot!"
2462421adcSMatthew Dillon    exit 1
2562421adcSMatthew Dillonendif
2662421adcSMatthew Dillon
2762421adcSMatthew Dillonecho "This program formats disk ${disk}!  Hit ^C now or its gone."
2862421adcSMatthew Dillonforeach i ( 10 9 8 7 6 5 4 3 2 1 )
2962421adcSMatthew Dillon    echo -n " $i"
302eca69e6SMatthew Dillon    sleep 1
3162421adcSMatthew Dillonend
3262421adcSMatthew Dillonecho ""
3362421adcSMatthew Dillon
3462421adcSMatthew Dillon# Unmount any prior mounts on /mnt, reverse order to unwind
3562421adcSMatthew Dillon# sub-directory mounts.
3662421adcSMatthew Dillon#
3762421adcSMatthew Dillonforeach i ( `df | fgrep /mnt | awk '{ print $6; }' | tail -r` )
3862421adcSMatthew Dillon    echo "UMOUNT $i"
3962421adcSMatthew Dillon    umount $i
4062421adcSMatthew Dillonend
4162421adcSMatthew Dillon
4262421adcSMatthew Dillon# Set our disk here
4362421adcSMatthew Dillon#
4462421adcSMatthew Dillonsleep 1
4562421adcSMatthew Dillonset echo
4662421adcSMatthew Dillon
4762421adcSMatthew Dillon# Format and label the disk.
4862421adcSMatthew Dillon#
4962421adcSMatthew Dillon#	'a' small UFS boot
5062421adcSMatthew Dillon#	'd' HAMMER filesystem
5162421adcSMatthew Dillon#
5262421adcSMatthew Dillon#	Use PFSs for backup domain separation
5362421adcSMatthew Dillon#
5491604a1eSSascha Wildnerdd if=/dev/zero of=/dev/${disk} bs=32k count=16
5562421adcSMatthew Dillonfdisk -IB ${disk}
56*0a319615SMatthew Dillondisklabel64 -r -w ${disk}s1
57fb422ccaSSascha Wildnerdisklabel64 -B ${disk}s1
58fb422ccaSSascha Wildnerdisklabel64 ${disk}s1 > /tmp/label
596a2fca96SSascha Wildner
6062421adcSMatthew Dilloncat >> /tmp/label << EOF
616a2fca96SSascha Wildner  a: 768m 0 4.2BSD
6262421adcSMatthew Dillon  b: 2g * swap
63b034d49eSSascha Wildner  d: * * HAMMER
6462421adcSMatthew DillonEOF
65fb422ccaSSascha Wildnerdisklabel64 -R ${disk}s1 /tmp/label
6662421adcSMatthew Dillon
676a2fca96SSascha Wildner# Create file systems
6862421adcSMatthew Dillonnewfs /dev/${disk}s1a
696c13d3bdSAntonio Huete Jimeneznewfs_hammer -f -L ROOT /dev/${disk}s1d
7062421adcSMatthew Dillon
7162421adcSMatthew Dillon# Mount it
7262421adcSMatthew Dillon#
7362421adcSMatthew Dillonmount_hammer /dev/${disk}s1d /mnt
7462421adcSMatthew Dillonmkdir /mnt/boot
7562421adcSMatthew Dillonmount /dev/${disk}s1a /mnt/boot
7662421adcSMatthew Dillon
7762421adcSMatthew Dillon# Create PFS mount points for nullfs.
7862421adcSMatthew Dillon#
7962421adcSMatthew Dillon# Do the mounts manually so we can install the system, setup
8062421adcSMatthew Dillon# the fstab later on.
8162421adcSMatthew Dillonmkdir /mnt/pfs
8262421adcSMatthew Dillon
8362421adcSMatthew Dillonhammer pfs-master /mnt/pfs/usr
8462421adcSMatthew Dillonhammer pfs-master /mnt/pfs/usr.obj
8562421adcSMatthew Dillonhammer pfs-master /mnt/pfs/var
8662421adcSMatthew Dillonhammer pfs-master /mnt/pfs/var.crash
8762421adcSMatthew Dillonhammer pfs-master /mnt/pfs/var.tmp
8862421adcSMatthew Dillonhammer pfs-master /mnt/pfs/tmp
8962421adcSMatthew Dillonhammer pfs-master /mnt/pfs/home
9062421adcSMatthew Dillon
9162421adcSMatthew Dillonmkdir /mnt/usr
9262421adcSMatthew Dillonmkdir /mnt/var
9362421adcSMatthew Dillonmkdir /mnt/tmp
9462421adcSMatthew Dillonmkdir /mnt/home
9562421adcSMatthew Dillon
9662421adcSMatthew Dillonmount_null /mnt/pfs/usr /mnt/usr
9762421adcSMatthew Dillonmount_null /mnt/pfs/var /mnt/var
9862421adcSMatthew Dillonmount_null /mnt/pfs/tmp /mnt/tmp
9962421adcSMatthew Dillonmount_null /mnt/pfs/home /mnt/home
10062421adcSMatthew Dillon
10162421adcSMatthew Dillonmkdir /mnt/usr/obj
10262421adcSMatthew Dillonmkdir /mnt/var/tmp
10362421adcSMatthew Dillonmkdir /mnt/var/crash
10462421adcSMatthew Dillon
10562421adcSMatthew Dillonmount_null /mnt/pfs/var.tmp /mnt/var/tmp
10662421adcSMatthew Dillonmount_null /mnt/pfs/var.crash /mnt/var/crash
10762421adcSMatthew Dillonmount_null /mnt/pfs/usr.obj /mnt/usr/obj
10862421adcSMatthew Dillon
10962421adcSMatthew Dillonchmod 1777 /mnt/tmp
11062421adcSMatthew Dillonchmod 1777 /mnt/var/tmp
11162421adcSMatthew Dillon
11262421adcSMatthew Dillon# Install the system from the live CD
11362421adcSMatthew Dillon#
11462421adcSMatthew Dilloncpdup -o / /mnt
1153875f5b0SMatthew Dilloncpdup -o /boot /mnt/boot
1163875f5b0SMatthew Dilloncpdup -o /usr /mnt/usr
11762421adcSMatthew Dilloncpdup -o /var /mnt/var
11862421adcSMatthew Dilloncpdup -i0 /etc.hdd /mnt/etc
11962421adcSMatthew Dillon
120fb422ccaSSascha Wildnerchflags -R nohistory /mnt/tmp
121fb422ccaSSascha Wildnerchflags -R nohistory /mnt/var/tmp
122fb422ccaSSascha Wildnerchflags -R nohistory /mnt/var/crash
123fb422ccaSSascha Wildnerchflags -R nohistory /mnt/usr/obj
124fb422ccaSSascha Wildner
12562421adcSMatthew Dillon# Create some directories to be used for NFS mounts later on.
12662421adcSMatthew Dillon# Edit as desired.
12762421adcSMatthew Dillon#
12862421adcSMatthew Dillonforeach i ( /proc /usr/doc /usr/src /repository /ftp /archive )
12962421adcSMatthew Dillon    if ( ! -d /mnt$i ) then
13062421adcSMatthew Dillon	mkdir /mnt$i
13162421adcSMatthew Dillon    endif
13262421adcSMatthew Dillonend
13362421adcSMatthew Dillon
13462421adcSMatthew Dilloncat > /mnt/etc/fstab << EOF
13562421adcSMatthew Dillon# Device		Mountpoint	FStype	Options		Dump	Pass#
13662421adcSMatthew Dillon/dev/${disk}s1d		/		hammer	rw		1	1
13762421adcSMatthew Dillon/dev/${disk}s1a		/boot		ufs	rw		1	1
13831927be5SSascha Wildner/dev/${disk}s1b		none		swap	sw		0	0
13962421adcSMatthew Dillon/pfs/usr		/usr		null	rw		0	0
14062421adcSMatthew Dillon/pfs/var		/var		null	rw		0	0
14162421adcSMatthew Dillon/pfs/tmp		/tmp		null	rw		0	0
14262421adcSMatthew Dillon/pfs/home		/home		null	rw		0	0
14362421adcSMatthew Dillon/pfs/var.tmp		/var/tmp	null	rw		0	0
14462421adcSMatthew Dillon/pfs/usr.obj		/usr/obj	null	rw		0	0
14562421adcSMatthew Dillon/pfs/var.crash		/var/crash	null	rw		0	0
14662421adcSMatthew Dillonproc			/proc		procfs	rw		0	0
14762421adcSMatthew Dillon# misc NFS mounts to get your test box access to 'stuff'
14862421adcSMatthew Dillon#crater:/repository	/repository	nfs	ro,intr,bg	0	0
14962421adcSMatthew Dillon#crater:/usr/doc	/usr/doc	nfs	ro,intr,bg	0	0
15062421adcSMatthew Dillon#crater:/ftp		/ftp		nfs	ro,intr,bg	0	0
15162421adcSMatthew Dillon#crater:/sources/HEAD	/usr/src	nfs	ro,intr,bg	0	0
15262421adcSMatthew Dillon#pkgbox:/archive	/archive	nfs	ro,intr,bg	0	0
15362421adcSMatthew DillonEOF
15462421adcSMatthew Dillon
15562421adcSMatthew Dillon# Because root is not on the boot partition we have to tell the loader
15662421adcSMatthew Dillon# to tell the kernel where root is.
15762421adcSMatthew Dillon#
15862421adcSMatthew Dilloncat > /mnt/boot/loader.conf << EOF
15962421adcSMatthew Dillonvfs.root.mountfrom="hammer:${disk}s1d"
16062421adcSMatthew DillonEOF
16162421adcSMatthew Dillon
16262421adcSMatthew Dillon# Setup interface, configuration, sshd
16362421adcSMatthew Dillon#
16462421adcSMatthew Dillonset ifc = `route -n get default | fgrep interface | awk '{ print $2; }'`
16562421adcSMatthew Dillonset ip = `ifconfig $ifc | fgrep inet | fgrep -v inet6 | awk '{ print $2; }'`
16662421adcSMatthew Dillonset lip = `echo $ip | awk -F . '{ print $4; }'`
16762421adcSMatthew Dillon
16862421adcSMatthew Dillonecho -n "ifconfig_$ifc=" >> /mnt/etc/rc.conf
16962421adcSMatthew Dillonecho '"DHCP"' >> /mnt/etc/rc.conf
17062421adcSMatthew Dilloncat >> /mnt/etc/rc.conf << EOF
17162421adcSMatthew Dillonsshd_enable="YES"
17262421adcSMatthew Dillondntpd_enable="YES"
17362421adcSMatthew Dillonhostname="test$lip.MYDOMAIN.XXX"
17462421adcSMatthew Dillondumpdev="/dev/${disk}s1b"
17562421adcSMatthew DillonEOF
17662421adcSMatthew Dillon
17762421adcSMatthew Dillon# Misc sysctls
17862421adcSMatthew Dillon#
17962421adcSMatthew Dilloncat >> /mnt/etc/sysctl.conf << EOF
18062421adcSMatthew Dillon#net.inet.ip.portrange.first=4000
18162421adcSMatthew DillonEOF
18262421adcSMatthew Dillon
18362421adcSMatthew Dillon# Allow sshd root logins via dsa key only
18462421adcSMatthew Dillon#
18562421adcSMatthew Dillonfgrep 'PermitRootLogin without-password' /mnt/etc/ssh/sshd_config >& /dev/null
18662421adcSMatthew Dillonif ( $?status ) then
18762421adcSMatthew Dillon    echo "PermitRootLogin without-password" >> /mnt/etc/ssh/sshd_config
18862421adcSMatthew Dillonendif
18962421adcSMatthew Dillon
19062421adcSMatthew Dillon# additional loader.conf stuff
19162421adcSMatthew Dillon#cat >> /mnt/boot/loader.conf << EOF
19262421adcSMatthew Dillon#if_nfe_load="YES"
19362421adcSMatthew Dillon#EOF
19462421adcSMatthew Dillon
19562421adcSMatthew Dillon# Get sshd working - auto install my key so I can login.
19662421adcSMatthew Dillon#
19762421adcSMatthew Dillon#mkdir -p /mnt/root/.ssh
19862421adcSMatthew Dillon#cat > /mnt/root/.ssh/authorized_keys << EOF
19962421adcSMatthew Dillon#ssh-dss ...
20062421adcSMatthew Dillon#EOF
20162421adcSMatthew Dillon
20262421adcSMatthew Dillonif ( ! -f /mnt/etc/ssh/ssh_host_dsa_key ) then
20362421adcSMatthew Dillon    cd /mnt/etc/ssh
20462421adcSMatthew Dillon    ssh-keygen -t dsa -f ssh_host_dsa_key -N ""
20562421adcSMatthew Dillonendif
20662421adcSMatthew Dillon
2076c13d3bdSAntonio Huete Jimenez# Misc cleanups
2086c13d3bdSAntonio Huete Jimenez#
2096c13d3bdSAntonio Huete Jimenezrm -R /mnt/README* /mnt/autorun* /mnt/index.html /mnt/dflybsd.ico
2106c13d3bdSAntonio Huete Jimenezrm /mnt/boot.catalog
2116c13d3bdSAntonio Huete Jimenez
21262421adcSMatthew Dillon# take CD out and reboot
21362421adcSMatthew Dillon#
214