3 # HAMMER INSTALLATION on a CCD disk (mirror)
5 # You should modify disklist to match the disks you want to use.
6 # Please BE CAREFUL when doing so.
13 logfile="/tmp/hammer_ccd_mirror.log"
14 contents_dir="/tmp/contents"
18 # Display an error and exit
25 echo 1>&2 "$0: ERROR: $*"
32 # Checks whether /tmp is writeable.
37 mktemp "/tmp/XXX" >> ${logfile} 2>&1
40 err 1 "/tmp directory must be writeable"
50 # No pre-install checks
61 if [ ${status} -eq 0 ]; then
67 echo "ccd operations were not sucessfully performed,"
68 echo "it is highly probably you have to reboot this computer now."
73 # ckstatus status progname
75 # Checks exit status of programs and if it fails
76 # it exists with a message
83 if [ ${st} -ne 0 ]; then
84 err 1 "Failed to run $2. Check ${logfile}"
91 # Checks if a module is loaded, if not
92 # it tries to load it. In case of failure
99 if ! kldstat -q -m ${mod}; then
100 kldload $1 >> ${logfile} 2>&1
102 if [ $? -ne 0 ]; then
103 err 1 "Could not load ${mod}"
111 # Clears the first sectors of the disk
112 # and then prepares the disk for disklabel.
113 # It also installs bootblocks in the first
120 # Hey don't shoot yourself in the foot
121 if [ ! "$disk" = "" ]; then
122 mount | fgrep ${disk} >> ${logfile} 2>&1
124 if [ $? -ne 1 ]; then
125 err 1 "${disk} is already being used, aborting"
129 if [ "${bootdisk}" = "" ]; then
133 dd if=/dev/zero of=/dev/${disk} bs=32k count=16 >> ${logfile} 2>&1
136 fdisk -IB ${disk} >> ${logfile} 2>&1
139 disklabel -r -w ${disk}s1 >> ${logfile} 2>&1
140 ckstatus $? "disklabel"
142 if [ ! "${bootdisk}" = "" ]; then
143 disklabel -B ${disk}s1 >> ${logfile} 2>&1
144 ckstatus $? "disklabel"
151 # Create same labels for every disk
152 # except for the disk that will contain
160 disklabel ${disk}s1 > /tmp/label
161 ckstatus $? "disklabel"
164 tmp=`sysctl hw.physmem | cut -w -f 2`
165 memtotal=`expr ${tmp} / 1024 / 1024`
167 if [ "${param}" = "root" ]; then
168 cat >> /tmp/label <<EOF
169 b: ${memtotal}m * swap
173 cat >> /tmp/label <<EOF
178 disklabel -R ${disk}s1 /tmp/label >> ${logfile} 2>&1
179 ckstatus $? "disklabel"
190 for disk in ${disklist}
193 lst="${tmp} /dev/${disk}s1d"
196 ccdconfig ccd0 128 CCDF_MIRROR ${lst}
197 ckstatus $? "ccdconfig"
198 sleep 3 # Try to settle ops
209 for disk in ${disklist}
212 lst="${tmp} /dev/${disk}s1d"
216 ccdconfig -g > ${contents_dir}/etc/ccd.conf
217 ckstatus $? "ccdconfig"
219 cat >> ${contents_dir}/etc/rc.ccd << EOF
220 # call ccdconfig to restore the configuration
221 ccdconfig -C -f /etc/ccd.conf
224 # Make sure it can be executed by initrd rc
225 chmod +x ${contents_dir}/etc/rc.ccd
229 echo "ALL DATA IN DISKS ${disklist} WILL BE LOST!"
230 echo "Press ^C to abort."
231 for n in 10 9 8 7 6 5 4 3 2 1
238 # /tmp has to be writeable
239 echo "* Checking /tmp is writeable"
242 rm "${logfile}" >> ${logfile} 2>&1
243 echo "* Output to ${logfile}"
245 # kldload needed modules and start udevd
246 echo "* Loading modules"
247 ckloadmod ccd >> ${logfile} 2>&1
249 # check previous installations
252 # Unmount any prior mounts on /mnt, reverse order to unwind
253 # sub-directory mounts.
255 for mount in `df | fgrep /mnt | awk '{ print $6; }' | tail -r`
257 echo " Umounting ${mount}"
258 umount ${mount} >> ${logfile} 2>&1
261 # Prepare the disks in the list
262 for disk in ${disklist}
264 echo "* Preparing disk ${disk}"
269 # ccdconfig operations in the disks
270 echo "* Performing CCD operations"
273 # prepare the concatenated disk
279 echo "* Formatting ccd0"
280 newfs /dev/${bootdisk}s1a >> ${logfile} 2>&1
283 newfs_hammer -f -L ROOT /dev/ccd0s1d >> ${logfile} 2>&1
288 echo "* Mounting everything"
289 mount_hammer /dev/ccd0s1d /mnt >> ${logfile} 2>&1
294 mount /dev/${bootdisk}s1a /mnt/boot >> ${logfile} 2>&1
297 # Create PFS mount points for nullfs.
298 pfslist="usr usr.obj var var.crash var.tmp tmp home"
302 for pfs in ${pfslist}
304 hammer pfs-master /mnt/pfs/$pfs >> ${logfile} 2>&1
308 # Mount /usr and /var so that you can add subdirs
309 mkdir /mnt/usr >> ${logfile} 2>&1
310 mkdir /mnt/var >> ${logfile} 2>&1
311 mount_null /mnt/pfs/usr /mnt/usr >> ${logfile} 2>&1
314 mount_null /mnt/pfs/var /mnt/var >> ${logfile} 2>&1
317 mkdir /mnt/usr/obj >> ${logfile} 2>&1
318 mkdir /mnt/var/tmp >> ${logfile} 2>&1
319 mkdir /mnt/var/crash >> ${logfile} 2>&1
321 mkdir /mnt/tmp >> ${logfile} 2>&1
322 mkdir /mnt/home >> ${logfile} 2>&1
324 mount_null /mnt/pfs/tmp /mnt/tmp >> ${logfile} 2>&1
327 mount_null /mnt/pfs/home /mnt/home >> ${logfile} 2>&1
330 mount_null /mnt/pfs/var.tmp /mnt/var/tmp >> ${logfile} 2>&1
333 mount_null /mnt/pfs/var.crash /mnt/var/crash >> ${logfile} 2>&1
336 mount_null /mnt/pfs/usr.obj /mnt/usr/obj >> ${logfile} 2>&1
339 chmod 1777 /mnt/tmp >> ${logfile} 2>&1
340 chmod 1777 /mnt/var/tmp >> ${logfile} 2>&1
342 # Install the system from the live CD
344 echo "* Starting file copy"
345 cpdup -vv -o / /mnt >> ${logfile} 2>&1
348 cpdup -vv -o /boot /mnt/boot >> ${logfile} 2>&1
351 cpdup -vv -o /usr /mnt/usr >> ${logfile} 2>&1
354 cpdup -vv -o /var /mnt/var >> ${logfile} 2>&1
357 cpdup -vv -i0 /etc.hdd /mnt/etc >> ${logfile} 2>&1
360 chflags -R nohistory /mnt/tmp >> ${logfile} 2>&1
361 chflags -R nohistory /mnt/var/tmp >> ${logfile} 2>&1
362 chflags -R nohistory /mnt/var/crash >> ${logfile} 2>&1
363 chflags -R nohistory /mnt/usr/obj >> ${logfile} 2>&1
365 echo "* Adapting fstab and loader.conf"
366 cat > /mnt/etc/fstab << EOF
367 # Device Mountpoint FStype Options Dump Pass#
368 /dev/ccd0s1d / hammer rw 1 1
369 /dev/${bootdisk}s1a /boot ufs rw 1 1
370 /dev/ccd0s1b none swap sw 0 0
371 /pfs/usr /usr null rw 0 0
372 /pfs/var /var null rw 0 0
373 /pfs/tmp /tmp null rw 0 0
374 /pfs/home /home null rw 0 0
375 /pfs/var.tmp /var/tmp null rw 0 0
376 /pfs/usr.obj /usr/obj null rw 0 0
377 /pfs/var.crash /var/crash null rw 0 0
378 proc /proc procfs rw 0 0
381 # Because root is not on the boot partition we have to tell the loader
382 # to tell the kernel where root is.
384 cat > /mnt/boot/loader.conf << EOF
386 initrd.img_load="YES"
387 initrd.img_type="md_image"
388 vfs.root.mountfrom="ufs:md0s0"
389 vfs.root.realroot="local:hammer:/dev/ccd0s1d"
392 # Setup interface, configuration, sshd
395 ifc=`route -n get default | fgrep interface | awk '{ print $2; }'`
396 ip=`ifconfig $ifc | fgrep inet | fgrep -v inet6 | awk '{ print $2; }'`
397 lip=`echo $ip | awk -F . '{ print $4; }'`
399 echo -n "ifconfig_$ifc=" >> /mnt/etc/rc.conf
400 echo '"DHCP"' >> /mnt/etc/rc.conf
401 cat >> /mnt/etc/rc.conf << EOF
404 hostname="test$lip.MYDOMAIN.XXX"
405 dumpdev="/dev/ccd0s1b"
410 cat >> /mnt/etc/sysctl.conf << EOF
411 #net.inet.ip.portrange.first=4000
415 echo "* Preparing initrd image"
416 cp /etc/defaults/mkinitrd.conf /etc/mkinitrd.conf
417 cpdup /usr/share/initrd ${contents_dir}
419 sed -i.bak '/^BIN_TOOLS/ s/\"$/ sleep\"/' /etc/mkinitrd.conf
420 sed -i.bak '/^SBIN_TOOLS/ s/\\/ccdconfig \\/' /etc/mkinitrd.conf
422 # Need to escape the directory so that sed doesn't take the var literally
423 escaped_var=$(printf '%s\n' "${contents_dir}" | sed 's/[\&/]/\\&/g')
424 sed -i.bak "s/^CONTENT_DIRS=.*/CONTENT_DIRS=\"${escaped_var}\"/" /etc/mkinitrd.conf
428 /sbin/mkinitrd -b /mnt/boot >> ${logfile} 2>&1
430 # copy installation log
431 echo "* Saving up installation log"
432 cp ${logfile} /mnt/tmp/
437 echo "chroot now to /mnt and change root password and also edit"
438 echo "/mnt/etc/ssh/sshd_config to allow root login and authentication"
439 echo "using passwords. Alternatively, you can also just copy your"
440 echo "~/.ssh/authorized_keys file to allow login using your ssh keys."
442 echo "Installation finished successfully."
445 # take CD out and reboot