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:
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:
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
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:
- #! / bin / sh
- # Vars
- dev = da0
- tank = tank
- iface = em0
- hostname = core.domain.com
- tz = "Europe / Kiev"
- # gpart
- gpart create -s GPT $ dev
- gpart add -s 64K -t freebsd-boot $ dev
- gpart add -s 2G -t freebsd-swap -l swap0 $ dev
- gpart add -t freebsd-zfs -l disk0 $ dev
- gpart bootcode -b / mnt2 / boot / pmbr -p / mnt2 / boot / gptzfsboot -i 1 $ dev
- sysctl kern.geom.debugflags = 0x10
- # install ZFS
- kldload /mnt2/boot/kernel/opensolaris.ko
- kldload /mnt2/boot/kernel/zfs.ko
- mkdir / boot / zfs
- #reate ZFS pool
- zpool create -f $ tank / dev / gpt / disk0
- zfs set mountpoint = none $ tank
- zfs set atime = off $ tank
- zfs set checksum = fletcher4 $ tank
- zfs create -o compression = off -o exec = on $ tank / root
- zfs set mountpoint = / $ tank $ tank / root
- zpool set bootfs = $ tank / root $ tank
- zfs create -o compression = on -o exec = on -o setuid = off $ tank / tmp
- zfs set mountpoint = / $ tank / tmp $ tank / tmp
- zfs create $ tank / usr
- zfs set mountpoint = / $ tank / usr $ tank / usr
- zfs create $ tank / var
- zfs set mountpoint = / $ tank / var $ tank / var
- zfs create -o compression = off -o setuid = off $ tank / opt
- zfs set mountpoint = / $ tank / opt $ tank / opt
- cd / $ tank; ln -s / usr / home home && cd -
- mkdir / $ tank / var / tmp
- chmod 1777 / $ tank / var / tmp / $ tank / tmp
- # install base system
- cd /dist/8.2-*
- export DESTDIR = / $ tank
- for dir in base catpages dict doc info lib32 manpages; do (cd $ dir; echo "y" | ./install.sh); done
- cd src; ./install.sh all
- cd ../kernels; ./install.sh generic
- cd / $ tank / boot; cp -Rlp GENERIC / * / $ tank / boot / kernel /
- # install base configs
- cat << EOF> /$tank/etc/rc.conf
- zfs_enable = "YES"
- hostname = "$ hostname"
- ifconfig_ $ iface = "DHCP"
- sshd_enable = "YES"
- ntpd_enable = "YES"
- ntpd_program = "/ usr / sbin / ntpd"
- ntpd_flags = "- p /var/run/ntpd.pid -f /var/db/ntpd.drift"
- Eof
- cat << EOF> /$tank/etc/ntp.conf
- server 82.207.71.6 iburst maxpoll 9
- server 91.198.10.4 iburst maxpoll 9
- server 79.142.192.4 iburst maxpoll 9
- server 193.193.193.107 iburst maxpoll 9
- Eof
- echo 'zfs_load = "YES"'> /$tank/boot/loader.conf
- echo "vfs.root.mountfrom = \" zfs: $ tank / root \ "" >> /$tank/boot/loader.conf
- cp / mnt2 / usr / share / zoneinfo / $ tz / $ tank / etc / localtime
- cp /boot/zfs/zpool.cache /$tank/boot/zfs/zpool.cache
- cat << EOF> / $ tank / etc / fstab
- # Device Mountpoint FStype Options Dump Pass #
- / dev / gpt / swap0 none swap sw 0 0
- procfs / proc procfs rw 0 0
- Eof
- export LD_LIBRARY_PATH = / mnt2 / lib
- cd /
- # correct ZFS mount points and quotas
- zfs unmount -a
- zfs set mountpoint = / opt $ tank / opt
- zfs set quota = 1G $ tank / tmp && zfs set mountpoint = / tmp $ tank / tmp
- zfs set quota = 5G $ tank / usr && zfs set mountpoint = / usr $ tank / usr
- zfs set quota = 10G $ tank / var && zfs set mountpoint = / var $ tank / var
- 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