#!/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. # # da0 and da1 will be made part of a lvm stripe. disk0 will also contain # a small /boot UFS formatted and a swap partition on it. # # WARNING: HAMMER filesystems (and pseudo-filesystems) must be # occassionally pruned and reblocked. 'man hammer' for more information. # set disk0 = "da0" set disk1 = "da1" echo "ALL DATA IN DISKS ${disk0} ${disk1} WILL BE LOST!" echo "Press ^C to abort." foreach i ( 5 4 3 2 1 ) echo -n " $i" sleep 1 end echo "" # calculate memory set tmp = `fgrep "real memory" /var/run/dmesg.boot | awk '{print $4}'` set memtotal = `expr ${tmp} / 1024 / 1024` # kldload needed modules and start udevd /sbin/kldload dm_target_striped /sbin/kldload dm_target_linear /sbin/udevd # 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. # # disk0 # 'a' small UFS boot # 'd' type unknown to be used by lvm(8) # # disk1 # 'd' type unknown to be used by lvm(8) # # dd if=/dev/zero of=/dev/${disk0} bs=32k count=128 dd if=/dev/zero of=/dev/${disk1} bs=32k count=128 fdisk -IB ${disk0} fdisk -IB ${disk1} disklabel -r -w ${disk0}s1 auto disklabel -r -w ${disk1}s1 auto # disk0 setup disklabel -B ${disk0}s1 disklabel ${disk0}s1 > /tmp/label cat >> /tmp/label << EOF a: 768m 0 4.2BSD d: * * unknown EOF disklabel -R ${disk0}s1 /tmp/label rm /tmp/label # disk1 setup disklabel ${disk1}s1 > /tmp/label cat >> /tmp/label << EOF d: * * unknown EOF disklabel -R ${disk1}s1 /tmp/label rm /tmp/label # Prepare disks for the operation # # # LVM operations # # Both disk will be tagged as PV, afterwards # they'll be part of MAIN VG from where the # extents will be created. /sbin/pvcreate /dev/${disk0}s1d || echo Failed to create PV at ${disk0} && exit 1 /sbin/pvcreate /dev/${disk1}s1d || echo Failed to create PV at ${disk1} && exit 1 /sbin/vgcreate main /dev/${disk0}s1d /dev/${disk1}s1d || echo Failed to create VG && exit 1 /sbin/vgchange -a y main ||echo Failed to activate VG main && exit echo Settling sync sleep 5 /sbin/lvcreate -n lv_swap -L ${memtotal}M main || echo Failed to create LV && exit 1 /sbin/lvcreate -n lv_root -l 100%FREE main || echo Failed to create LV && exit 1 # Format the volumes newfs /dev/${disk0}s1a || echo Failed to newfs ${disk0}s1a && exit 1 newfs_hammer -L ROOT /dev/main/lv_root || echo Failed to newfs_hammer lv_root && exit 1 swapon /dev/main/lv_swap || echo Failed to activate swap device # Mount it # mount_hammer /dev/main/lv_root /mnt || echo Mount failed on /mnt && exit mkdir /mnt/boot mount /dev/${disk0}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/src ) if ( ! -d /mnt$i ) then mkdir /mnt$i endif end cat > /mnt/etc/fstab << EOF # Device Mountpoint FStype Options Dump Pass# /dev/main/lv_root / hammer rw 1 1 /dev/${disk0}s1a /boot ufs rw 1 1 /dev/main/lv_swap 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 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 dm_target_striped_load="YES" dm_target_linear_load="YES" initrd.img_load="YES" initrd.img_type="md_image" vfs.root.mountfrom="ufs:md0s0" vfs.root.realroot="local:hammer:/dev/main/lv_root" 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/main/lv_swap" 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 # mkinitd image /sbin/mkinitrd -b /mnt/boot # take CD out and reboot #