Annotation of src/share/examples/rconfig/hammer.sh, revision 1.3

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