Unattended installation of FreeBSD 8.2-RELEASE on ZFS

    We all know that from time to timevery rarely, almost never, but a situation arises in which an unscheduled reset or power failure of the FreeBSD server leads to a stop of the download with the insistent requirement to start fsck by hand. It happens that the server is bored, the admin has not visited him for a long time, and maybe there is a full moon, but this phenomenon occurs in nature. The time has come, I think, to move to ZFS - people recommend that the beta test stage has passed a long time ago, the disk space is not wasted, and ... in ZFS there is no need for the fsck utility to check the integrity of the file system (!). Having studied mana, wiki, fox, I came to the conclusion that it is necessary to grind, comb, lacquer and go to the masses in some places. Indeed, the process, compared to the standard sysinstall, is somewhat complicated, but faster than ever - 2 minutes and the server with the root partition on ZFS is ready.

    Yes, of course, we won’t run with our hands the whole bunch of commands that it is recommended to run, and we won’t mess with sysinstall, but we will make an unattended installation script that will be launched from Fixit mode . To do this, you need a DVD or USBstick installation option, the server where the script is stored (accessible via ssh).
    The installation process looks like this: boot, select the Fixit mode - CD / DVD , hang up IP on the network card and run the script:
    Fixit # ifconfig em0 192.168.1.100/24
    Fixit # ssh user@192.168.1.1 'cat / opt / script / zfs-init' | sh

    Now let's look at the contents of the script, it should do the following:
    1. Partition the disk (GPT - boot, swap0, disk0)
    2. Create a ZFS pool (/ root, / tmp, / usr, / var, / opt) - the / root partition did separately, it can also be limited to a size of
    3. Throw a flask on ZFS with minimal configs to start.

    Script on the shell, just a list of commands in a certain sequence. At the beginning of the script, change the variables dev (disk), iface (network card), tank (name of the ZFS pool), hostname (host name), tz (timezone). Here he is:
    1. #! / bin / sh
    2.  
    3. # Vars
    4. dev = da0
    5. tank = tank
    6. iface = em0
    7. hostname = core.domain.com
    8. tz = "Europe / Kiev"
    9.  
    10. # gpart
    11. gpart create -s GPT $ dev
    12. gpart add -s 64K -t freebsd-boot $ dev
    13. gpart add -s 2G -t freebsd-swap -l swap0 $ dev
    14. gpart add -t freebsd-zfs -l disk0 $ dev
    15.  
    16. gpart bootcode -b / mnt2 / boot / pmbr -p / mnt2 / boot / gptzfsboot -i 1 $ dev
    17.  
    18. sysctl kern.geom.debugflags = 0x10
    19.  
    20. # install ZFS
    21. kldload /mnt2/boot/kernel/opensolaris.ko
    22. kldload /mnt2/boot/kernel/zfs.ko
    23.  
    24. mkdir / boot / zfs
    25. #reate ZFS pool
    26. zpool create -f $ tank / dev / gpt / disk0
    27. zfs set mountpoint = none $ tank
    28.  
    29. zfs set atime = off $ tank
    30. zfs set checksum = fletcher4 $ tank
    31. zfs create -o compression = off -o exec = on $ tank / root
    32. zfs set mountpoint = / $ tank $ tank / root
    33. zpool set bootfs = $ tank / root $ tank
    34. zfs create -o compression = on -o exec = on -o setuid = off $ tank / tmp
    35. zfs set mountpoint = / $ tank / tmp $ tank / tmp
    36. zfs create $ tank / usr
    37. zfs set mountpoint = / $ tank / usr $ tank / usr
    38. zfs create $ tank / var
    39. zfs set mountpoint = / $ tank / var $ tank / var
    40. zfs create -o compression = off -o setuid = off $ tank / opt
    41. zfs set mountpoint = / $ tank / opt $ tank / opt
    42.  
    43. cd / $ tank; ln -s / usr / home home && cd -
    44. mkdir / $ tank / var / tmp 
    45. chmod 1777 / $ tank / var / tmp / $ tank / tmp
    46.  
    47. # install base system
    48. cd /dist/8.2-*
    49. export DESTDIR = / $ tank
    50. for dir in base catpages dict doc info lib32 manpages; do (cd $ dir; echo "y" | ./install.sh); done
    51. cd src; ./install.sh all
    52. cd ../kernels; ./install.sh generic
    53. cd / $ tank / boot; cp -Rlp GENERIC / * / $ tank / boot / kernel /
    54.  
    55. # install base configs
    56. cat << EOF> /$tank/etc/rc.conf
    57. zfs_enable = "YES"
    58. hostname = "$ hostname"
    59. ifconfig_ $ iface = "DHCP"
    60. sshd_enable = "YES"
    61. ntpd_enable = "YES"               
    62. ntpd_program = "/ usr / sbin / ntpd"   
    63. ntpd_flags = "- p /var/run/ntpd.pid -f /var/db/ntpd.drift"
    64. Eof
    65.  
    66. cat << EOF> /$tank/etc/ntp.conf
    67. server 82.207.71.6 iburst maxpoll 9
    68. server 91.198.10.4 iburst maxpoll 9
    69. server 79.142.192.4 iburst maxpoll 9
    70. server 193.193.193.107 iburst maxpoll 9
    71. Eof
    72.  
    73. echo 'zfs_load = "YES"'> /$tank/boot/loader.conf
    74. echo "vfs.root.mountfrom = \" zfs: $ tank / root \ "" >> /$tank/boot/loader.conf
    75.  
    76. cp / mnt2 / usr / share / zoneinfo / $ tz / $ tank / etc / localtime
    77. cp /boot/zfs/zpool.cache /$tank/boot/zfs/zpool.cache
    78.  
    79. cat << EOF> / $ tank / etc / fstab
    80. # Device Mountpoint FStype Options Dump Pass #
    81. / dev / gpt / swap0 none swap sw 0 0
    82. procfs / proc procfs rw 0 0
    83. Eof
    84.  
    85. export LD_LIBRARY_PATH = / mnt2 / lib 
    86.  
    87. cd /
    88.  
    89. # correct ZFS mount points and quotas
    90. zfs unmount -a
    91. zfs set mountpoint = / opt $ tank / opt
    92. zfs set quota = 1G $ tank / tmp && zfs set mountpoint = / tmp $ tank / tmp
    93. zfs set quota = 5G $ tank / usr && zfs set mountpoint = / usr $ tank / usr
    94. zfs set quota = 10G $ tank / var && zfs set mountpoint = / var $ tank / var
    95. zfs set quota = 512m $ tank / root && zfs set mountpoint = legacy $ tank / root

    While the script is running, you don’t need to touch the keyboard, after finishing just reboot the server, and log in as root without a password. Related

    materials: RootOnZFS / GPTZFSBoot , Installing FreeBSD using ZFS as the main one .

    Good luck

    Also popular now: