distcc 手仕舞い編

以前掲載させていただきました ZFS root の一連の手順をスクリプト化したスクリプトですが、distcc の tmpfs 問題を受けて修正を入れました。

使用されている方もいらっしゃらないとは思いますが、備忘録代わりとして再掲させていただきます。

#!/bin/sh -x
#
# zfs.sh - ZFS root installation for FreeBSD.
#
# Usage: Please boot single user mode, type below and do.
#   mount -w /
#   mkdir -p ${path}  # that will include this script.
#   mount /dev/da[0-9]s1d ${path}
#   sh -x ${path}/zfs.sh
#

# ------------------------------------------------------------------------- #
#  Initialize.
# ------------------------------------------------------------------------- #

# to set basic information of your machine, for example "Drive Letter",
# sourced by CPU name.
cpu_name=`dmesg|egrep -i 'CPU:'`

# Please change "Opteron or Pentium" to CPU name of your machine,
# and set "tank", "bootdir" and "datank" to Drive Letter of your machine.
case ${cpu_name} in
    *Opteron*)
        pools='tank=/dev/ad4s1d datank=/dev/ad6'
        bootdir='/dev/ad4s1a'
        datanks="xxxxxxxxxx"  # for second drive.
        defaultrouter='defaultrouter="xxx.xxx.xxx.xxx"'
        hostname='melchior'
        ifconfig='ifconfig_bge0="inet xxx.xxx.xxx.xxx  netmask 255.255.255.0"'
        keymap='us.iso'
        ;;
    *Pentium*)
        pools='tank=/dev/ad0s1d'
        bootdir='/dev/ad0s1a'
        hostname='xxxxxxxxxx'
        ifconfig='ifconfig_fxp0="DHCP"'
        keymap='us.pc-ctrl'
        ;;
    *)
        pools='tank=/dev/ad8s1d'
        bootdir='/dev/ad8s1a'
        hostname='xxxxxxxxxx'
        ifconfig='ifconfig_em0="DHCP"'
        keymap='us.pc-ctrl'
esac

# Please change tank's names, if you want.
tanks="home tmp usr var"

# Please add or delete configuration lines, if you want.
rc_conf="# $Id$\n\
${defaultrouter}\n\
${ifconfig}\n\
check_quotas=\"NO\"\n\
hostname=\"${hostname}.localhost\"\n\
keymap=\"${keymap}\"\n\
keyrate=\"fast\"\n\
ntpdate_enable=\"YES\"\n\
ntpdate_flags=\"ntp.jst.mfeed.ad.jp\"\n\
zfs_enable=\"YES\""

rc_local='# $Id$\n\
mount -w -t tmpfs none /var/tmp'

loader_conf='# $Id$\n\
zfs_load="YES"\n\
vfs.root.mountfrom="zfs:tank/bsdroot"\n\
tmpfs_load="YES"' # not required, if you want.

# ------------------------------------------------------------------------- #
#  Functions.
# ------------------------------------------------------------------------- #

rcsDO() {
    if [ -e $1 ]; then
        ci -l $1
    fi

    echo -e $2 >> $1

    if [ -e $1,v ]; then
        rcsdiff $1 | less
        ci -l -m"$3" $1
    else
        ci -l $1
    fi
}

poolsDO() {
    for i in ${pools}; do
        `echo ${i} | sed -e "s/^\(.*\)=\(.*\)$/$1/"`;
    done
}

tanksDO() {
    for i in ${pools}; do
        pool=`echo ${i} | sed -e "s/^\(.*\)=\(.*\)$/\1/"`;
        for j in `eval echo '${'${pool}'s}'`; do
            zfs create ${pool}/${j}
        done
    done
}

# ------------------------------------------------------------------------- #
#  Installation.
# ------------------------------------------------------------------------- #

poolsDO 'zpool create \1 \2'
poolsDO 'zfs set mountpoint=none \1'

zfs create tank/bsdroot
tanksDO

zfs set mountpoint=/tank tank/bsdroot
for i in ${tanks}; do
    zfs set mountpoint=/tank/${i} tank/${i}
done

df -h
zfs list

rcsDO /etc/rc.conf ${rc_conf} 'added settings.'

find -x / | cpio -pmd /tank

rm -rf /tank/boot
mkdir /tank/bootdir
cd /tank
ln -s bootdir/boot boot

rcsDO /boot/loader.conf ${loader_conf} 'added zfs and tmpfs.'

ci -l /tank/etc/fstab
cp /tank/etc/fstab /tank/etc/fstab.bak
echo '# $Id$' > /tank/etc/fstab
sed -e "s/^\(${bootdir}.*\/\)/\1bootdir/" /tank/etc/fstab.bak >> /tank/etc/fstab
# tmpfs is not required, if you want.
# echo 'tmpfs  /tmp      tmpfs  rw,mode=1777  0  0' >> /tank/etc/fstab
# echo 'tmpfs  /var/tmp  tmpfs  rw,mode=1777  0  0' >> /tank/etc/fstab
rcsdiff /tank/etc/fstab | less
ci -l -m"modified ${bootdir}." /tank/etc/fstab  # and added tmpfs.

rcsDO /tank/etc/rc.local ${rc_local}

for i in ${tanks}; do
    zfs set mountpoint=/${i} tank/${i}
done

cd /
zfs set mountpoint=legacy tank/bsdroot

# ------------------------------------------------------------------------- #
#  The End.
# ------------------------------------------------------------------------- #
# Congratulations. your ZFS settings was done.
# Please type below, do and reboot your machine.
# umount ${path}  # that includes this script.
# reboot

exit 0