FreeBSD from Scratch Stage1でZFSを使う
やってみたらできちゃったので置いておきますね。
ちなみにZFSのマウントポイントを使ってると自動でマウントされちゃってマズーなのでLiveCDとかでlegacyに切り替え、fstabの編集など行ってから使用してください。
at own your risk:-)
# $Id$ # vim: set ft=sh: # Root mount point where you create the new system. Because it is only # used as a mount point, no space will be used on that file system as all # files are of course written to the mounted file system(s). DESTPOOL="zroot" DESTZONE="`date "+%Y.%m.%d-%H:%M"`" DESTDIR="/newroot" # Where your src tree is. SRC="/usr/src" # Where your obj is. MAKEOBJDIRPREFIX="/usr/obj" # Your kernel config name as from make buildkernel KERNCONF=... KERNCONF="ML115G1" # Your target architecture as used for make buildworld TARGET=... # If you did not specify a TARGET when building world, it defaulted # to the build architecture (run "uname -m" to find out if you are unsure). TARGET="amd64" # amd64 arm i386 ia64 mips pc98 powerpc sparc64 sun4v # Available time zones are those under /usr/share/zoneinfo. TIMEZONE="Asia/Tokyo" # # The create_file_systems function must create the mountpoints under # DESTDIR, create the file systems, and then mount them under DESTDIR. # create_file_systems () { zfs create ${DESTPOOL}/${DESTZONE} zfs create ${DESTPOOL}/${DESTZONE}/system zfs create -o compression=on -o exec=on -o setuid=off ${DESTPOOL}/${DESTZONE}/tmp zfs create ${DESTPOOL}/${DESTZONE}/usr zfs create ${DESTPOOL}/${DESTZONE}/var zfs create -o compression=lzjb -o exec=off -o setuid=off ${DESTPOOL}/${DESTZONE}/var/crash zfs create -o exec=off -o setuid=off ${DESTPOOL}/${DESTZONE}/var/db zfs create -o compression=lzjb -o exec=on -o setuid=off ${DESTPOOL}/${DESTZONE}/var/db/pkg zfs create -o exec=off -o setuid=off ${DESTPOOL}/${DESTZONE}/var/empty zfs create -o compression=lzjb -o exec=off -o setuid=off ${DESTPOOL}/${DESTZONE}/var/log zfs create -o compression=lzjb -o exec=off -o setuid=off ${DESTPOOL}/${DESTZONE}/var/mail zfs create ${DESTPOOL}/${DESTZONE}/var/run zfs create -o compression=lzjb -o exec=on -o setuid=off ${DESTPOOL}/${DESTZONE}/var/tmp zfs set quota=8g ${DESTPOOL}/${DESTZONE} zpool set bootfs=${DESTPOOL}/${DESTZONE}/system zroot mkdir ${DESTDIR} mount -t zfs ${DESTPOOL}/${DESTZONE}/system ${DESTDIR} mkdir ${DESTDIR}/usr mount -t zfs ${DESTPOOL}/${DESTZONE}/usr ${DESTDIR}/usr mkdir ${DESTDIR}/var mount -t zfs ${DESTPOOL}/${DESTZONE}/var ${DESTDIR}/var mkdir ${DESTDIR}/var/crash mount -t zfs ${DESTPOOL}/${DESTZONE}/var/crash ${DESTDIR}/var/crash mkdir ${DESTDIR}/var/db mount -t zfs ${DESTPOOL}/${DESTZONE}/var/db ${DESTDIR}/var/db mkdir ${DESTDIR}/var/db/pkg mount -t zfs ${DESTPOOL}/${DESTZONE}/var/db/pkg ${DESTDIR}/var/db/pkg mkdir ${DESTDIR}/var/empty mount -t zfs ${DESTPOOL}/${DESTZONE}/var/empty ${DESTDIR}/var/empty mkdir ${DESTDIR}/var/log mount -t zfs ${DESTPOOL}/${DESTZONE}/var/log ${DESTDIR}/var/log mkdir ${DESTDIR}/var/mail mount -t zfs ${DESTPOOL}/${DESTZONE}/var/mail ${DESTDIR}/var/mail mkdir ${DESTDIR}/var/run mount -t zfs ${DESTPOOL}/${DESTZONE}/var/run ${DESTDIR}/var/run mkdir ${DESTDIR}/var/tmp mount -t zfs ${DESTPOOL}/${DESTZONE}/var/tmp ${DESTDIR}/var/tmp chmod 1777 ${DESTDIR}/var/tmp mkdir ${DESTDIR}/tmp mount -t zfs ${DESTPOOL}/${DESTZONE}/tmp ${DESTDIR}/tmp chmod 1777 ${DESTDIR}/tmp mkdir ${DESTDIR}/usr/ports mkdir ${DESTDIR}/home mkdir ${DESTDIR}/export } # # The create_etc_fstab function must create an fstab matching the # file systems created in create_file_systems. # create_etc_fstab () { cat <<EOF >${DESTDIR}/etc/fstab # Device Mountpoint FStype Options Dump Pass# /dev/gpt/swap0 none swap sw 0 0 /dev/gpt/swap1 none swap sw 0 0 /dev/gpt/swap2 none swap sw 0 0 /dev/gpt/swap3 none swap sw 0 0 ${DESTPOOL}/${DESTZONE}/system / zfs rw 0 0 ${DESTPOOL}/${DESTZONE}/usr /usr zfs rw 0 0 zroot/src /usr/src zfs rw 0 0 zroot/obj /usr/obj zfs rw 0 0 zroot/ports /usr/ports zfs rw 0 0 zroot/ports/distfiles /usr/ports/distfiles zfs rw 0 0 zroot/ports/packages /usr/ports/packages zfs rw 0 0 ${DESTPOOL}/${DESTZONE}/var /var zfs rw 0 0 ${DESTPOOL}/${DESTZONE}/var/crash /var/crash zfs rw 0 0 ${DESTPOOL}/${DESTZONE}/var/db /var/db zfs rw 0 0 ${DESTPOOL}/${DESTZONE}/var/db/pkg /var/db/pkg zfs rw 0 0 ${DESTPOOL}/${DESTZONE}/var/empty /var/empty zfs ro 0 0 ${DESTPOOL}/${DESTZONE}/var/log /var/log zfs rw 0 0 ${DESTPOOL}/${DESTZONE}/var/mail /var/mail zfs rw 0 0 ${DESTPOOL}/${DESTZONE}/var/run /var/run zfs rw 0 0 ${DESTPOOL}/${DESTZONE}/var/tmp /var/tmp zfs rw 0 0 ${DESTPOOL}/${DESTZONE}/tmp /tmp zfs rw 0 0 zroot/home /home zfs rw 0 0 zroot/export /export zfs rw 0 0 EOF chmod 644 ${DESTDIR}/etc/fstab chown root:wheel ${DESTDIR}/etc/fstab } # # The copy_files function is used to copy files before mergemaster is run. # copy_files () { # Add or remove from this list at your discretion. Mostly mandatory. for f in \ /etc/csh.cshrc \ /etc/exports \ /etc/group \ /etc/fstab.* \ /etc/hosts \ /etc/make.conf \ /etc/make.conf.ports \ /etc/make.conf.ports.knob \ /etc/make.conf.ports.site \ /etc/make.conf.src \ /etc/master.passwd \ /etc/mergemaster.rc \ /etc/motd \ /etc/my.cnf \ /etc/netconfig \ /etc/newsyslog.conf \ /etc/nsswitch.conf \ /etc/ntp.conf \ /etc/periodic.conf \ /etc/portsnap.conf \ /etc/profile \ /etc/rc.conf \ /etc/rc.conf.local \ /etc/resolv.conf \ /etc/src.conf \ /etc/sysctl.conf \ /etc/syslog.conf \ /etc/ttys \ /etc/mail/aliases \ /etc/mail/aliases.db \ /etc/mail/mailer.conf \ /etc/ssh/*key* \ /etc/ssh/*_config \ /var/cron/allow \ /var/cron/tabs/* \ /root/.tcshrc \ /root/.cshrc \ /root/.login \ /root/.profile \ /boot/device.hints \ /boot/loader.conf \ /usr/local/etc/ezjail.conf \ /usr/local/etc/dhcpd.conf \ /usr/local/etc/dovecot.conf \ /usr/local/etc/pkgtools.conf \ /usr/local/etc/smartd.conf \ /usr/local/etc/sudoers \ /usr/local/etc/syslog-ng.conf \ /usr/local/etc/proftpd.conf \ /usr/local/etc/smb.conf \ /usr/local/etc/ldap.conf \ /usr/local/etc/nss_ldap.conf \ /usr/local/etc/pam.d/samba \ /usr/local/etc/openldap/ldap.conf \ /usr/local/etc/openldap/slapd.conf \ /usr/local/etc/openldap/schema/samba.schema \ /usr/local/etc/postfix/main.cf \ /usr/local/etc/postfix/isp_passwd \ /usr/local/etc/postfix/isp_passwd.db \ /usr/local/etc/mediatomb/config.xml \ /usr/local/share/mediatomb/js/user.js; do if test -e ${f}; then d=`echo ${f} | sed -e 's@\(/.*/\).*@\1@'` if test ! -d ${DESTDIR}${d}; then mkdir -p ${DESTDIR}${d} fi cp -a ${f} ${DESTDIR}${f} fi done for d in \ /usr/local/etc/apache22/local \ /usr/local/etc/ezjail \ /usr/local/etc/samba ; do if test -d ${d}; then cp -a ${d} ${DESTDIR}${d} fi done sed -e '/^vfs\.root\.mountfrom=.*$/d' /boot/loader.conf > ${DESTDIR}/boot/loader.conf echo vfs.root.mountfrom="zfs:${DESTPOOL}/${DESTZONE}/system" >> ${DESTDIR}/boot/loader.conf } # # Everything else you want to tune in the new system. # NOTE: Do not install too many binaries here. With the old system running and # the new binaries and headers installed you are likely to run into bootstrap # problems. Ports should be compiled after you have booted in the new system. # all_remaining_customization () { zfs set readonly=on ${DESTPOOL}/${DESTZONE}/var/empty zpool set bootfs=${DESTPOOL}/${DESTZONE}/system zroot cp /boot/zfs/zpool.cache ${DESTDIR}/boot/zfs/zpool.cache }
ZFSを使い始めて思ったのがパテ切から開放されるのがこんなに楽とは!とか。
こんな変態的な事やらなければインストール時にちょっと手間かけるだけでディスク管理から(ほぼ)開放される。ような気がする。