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