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