FreeBSD 9-RELEASEをRoot on ZFSで自動インストールするスクリプト作ったよー

FreeBSDをRoot on ZFSでインストールするには多大なコマンド入力が必要で、超面倒&高確率でミスを犯すので自動インストールするシェルスクリプト作った。 FreeBSD 9-RELEASE用。8はシステムの展開方法が違うので、そのままじゃ使えない。むしろ、さくらのVPS(2G)用。VNCコンソールでちまちま設定するのが面倒だったので…。

パーティションサイズやcompressionの設定、loader.confの中身は激しく俺仕様なので、要修正。

起動メディアからインストーラを立ち上げたら「Shell」に落ちて、このスクリプトを/varあたりに置いて実行すれば完全自動でRoot on ZFSな環境が出来上がるよ! ユーザーやらタイムゾーンやらの設定は全くしてないので、次回起動時に適宜設定する方向で。

システムファイルを配布サイトから取ってくる関係上、ifconfigとroute add defaultだけは手入力が必要。あと、スクリプトをどうやってインストール環境に持ってくかって問題もあるが、Root on ZFSしようとする人なら自前でFTPサーバくらい用意出来るだろうって事で。

freebsd9-root-on-zfs-installer.sh
#!/bin/sh
# FreeBSD 9.1-RELEASE Root on ZFS Installer
 
# システムファイルの配布サイト
URL="ftp://150.65.7.130/pub/FreeBSD/releases/amd64/9.1-RELEASE/"
 
# RAMディスク設定
RAMDISK="/tmp"
RAMDISK_DEV="md1"
# インストールに必要なtxzが収まり、物理メモリが1GBちょい空く位の容量にする
RAMDISK_SIZE="512M"
 
# インストールファイルのダウンロード先
DISTDIR="$RAMDISK/dist"
DISTFILES="base.txz lib32.txz kernel.txz doc.txz ports.txz src.txz games.txz"
 
# インストール先ディスク
DISK="ada0"
# スワップパーティション名
SWAPNAME="-l swap"
# スワップサイズ
SWAPSIZE="-s 8G"
# データパーティション名
DATANAME="-l data"
# データボリュームサイズ
DATASIZE="-s 10G"
 
# ストレージプール名
ZPOOLNAME="zroot"
 
# インストール先ZFSファイルシステム
SYSROOT="$ZPOOLNAME/ROOT"
# 仮マウントポイントルート
MOUNTPOINT="/tmp/zfs"
# ストレージプールの代替マウントポイント
ALTROOT="$MOUNTPOINT/"
# インストール先フルパス
DESTDIR=$MOUNTPOINT/$SYSROOT
 
# ramdisk作り直し
echo 'Create ramdisk'
umount -f /dev/$RAMDISK_DEV
mdmfs -s $RAMDISK_SIZE $RAMDISK_DEV $RAMDISK
 
mkdir $MOUNTPOINT
 
# パーティション作成
echo 'Create partitions...'
sysctl kern.geom.debugflags=0x10
dd if=/dev/zero of=/dev/$DISK bs=1m count=100
 
gpart create -s gpt $DISK
gpart add -a 4k -s 64k -t freebsd-boot $DISK
gpart add -a 4k $SWAPSIZE -t freebsd-swap $SWAPNAME $DISK
gpart add -a 4k $DATASIZE -t freebsd-zfs $DATANAME $DISK
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $DISK
 
# 4kセクタでzpool作成
echo 'Create storage pool : ' $ZPOOLNAME
gnop create -S 4096 /dev/${DISK}p3
 
zpool create -R $ALTROOT -f $ZPOOLNAME /dev/${DISK}p3.nop
zpool export $ZPOOLNAME
 
gnop destroy /dev/${DISK}p3.nop
 
zpool import -R $ALTROOT $ZPOOLNAME
 
echo 'Create ZFS file systems'
zfs set checksum=fletcher4 zroot
 
zfs create -o normalization=formC $SYSROOT
 
zfs create $SYSROOT/usr
zfs create -o compression=gzip-9 $SYSROOT/usr/include
zfs create -o compression=gzip-9 $SYSROOT/usr/src
zfs create $SYSROOT/usr/home
cd $DESTDIR/; ln -s /usr/home home
cd /
 
zfs create -o compression=gzip-9 -o setuid=off $SYSROOT/usr/ports
zfs create -o compression=off -o exec=off -o setuid=off $SYSROOT/usr/ports/distfiles
zfs create -o compression=off -o exec=off -o setuid=off $SYSROOT/usr/ports/packages
 
zfs create -o compression=on $SYSROOT/var
zfs create -o exec=off -o setuid=off $SYSROOT/var/crash
zfs create -o exec=off -o setuid=off $SYSROOT/var/db
zfs create -o exec=on  -o setuid=off $SYSROOT/var/db/pkg
zfs create -o exec=off -o setuid=off $SYSROOT/var/empty
zfs create -o exec=off -o setuid=off $SYSROOT/var/log
zfs create -o exec=off -o setuid=off $SYSROOT/var/mail
zfs create -o exec=off -o setuid=off $SYSROOT/var/run
zfs create -o exec=on  -o setuid=off $SYSROOT/var/tmp
chmod 1777 $DESTDIR/var/tmp
 
zfs create -o exec=on  -o setuid=off $SYSROOT/tmp
chmod 1777 $DESTDIR/tmp
 
echo 'Set bootfs='$SYSROOT
zpool set bootfs=$SYSROOT $ZPOOLNAME
 
echo 'Create zpool.cache'
zpool export $ZPOOLNAME
zpool import -o cachefile=/tmp/zpool.cache -R $ALTROOT $ZPOOLNAME
 
echo 'Fetch system files'
mkdir $DISTDIR
cd $DISTDIR
for file in $DISTFILES
do
    fetch ${URL}$file
done
 
echo 'Install system files'
for file in $DISTFILES
do
    echo "  extract... ${file}"
    cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}
done
 
cp /tmp/zpool.cache $DESTDIR/boot/zfs/zpool.cache
 
LOADERCONF=$DESTDIR/boot/loader.conf
echo 'Create '$LOADERCONF
echo 'zfs_load="YES"' >> $LOADERCONF
echo 'vm.kmem_size="512M"' >> $LOADERCONF
echo 'vm.kmem_size_max="1024M"' >> $LOADERCONF
echo 'vfs.root.mountfrom="zfs:'$SYSROOT'"' >> $LOADERCONF
echo 'vfs.zfs.prefetch_disable="1"' >> $LOADERCONF
echo 'vfs.zfs.vdev.cache.size="10M"' >> $LOADERCONF
echo 'vfs.zfs.arc_max="128M"' >> $LOADERCONF
 
RCCONF=$DESTDIR/etc/rc.conf
echo 'Create '$RCCONF
echo 'zfs_enable="YES"' >> $RCCONF
 
# sshを有効にする(危険なので各種設定が終わったらルートログイン不許可にすること)
#echo 'sshd_enable="YES"' >> $RCCONF
#SSHCONF=$DESTDIR/etc/ssh/ssh_config
#echo 'PermitRootLogin yes' >> $SSHCONF
 
FSTAB=$DESTDIR/etc/fstab
echo 'Create '$FSTAB
echo '/dev/gpt/swap none swap sw 0 0' >> $FSTAB
 
echo 'Set mountpoints'
zfs set readonly=on $SYSROOT/var/empty
 
zfs umount -af
zfs set mountpoint=none $ZPOOLNAME
zfs set mountpoint=legacy $SYSROOT
zfs set mountpoint=/usr $SYSROOT/usr
zfs set mountpoint=/tmp $SYSROOT/tmp
zfs set mountpoint=/var $SYSROOT/var
 
echo 'Done.'

で、だ。自作スクリプトが完成した直後に、zfsinstallという、そのまんまの名前の高機能なインストーラの存在を知って涙目。

お、俺スクリプトの方が引数とかないし、か、簡単に使えるし(震え声)

<a href=“https://postorder-apotheek.com/product/winstrol/” rel=“dofollow”>Winstrol</a> <a href=“https://postorder-apotheek.com/product/emla/” rel=“dofollow”>Emla</a> <a href=“https://postorder-apotheek.com/product/nembutal/” rel=“dofollow”>Nembutal</a> <a href=“https://postorder-apotheek.com/product/vitamine-b12/” rel=“dofollow”>Vitamine B12</a> <a href=“https://postorder-apotheek.com/product/turinabol/” rel=“dofollow”>Turinabol</a> <a href=“https://postorder-apotheek.com/product/trenbolone/” rel=“dofollow”>Trenbolone</a> <a href=“https://postorder-apotheek.com/product/thyroxine/” rel=“dofollow”>Thyroxine</a> <a href=“https://postorder-apotheek.com/product/t5-fatburner/” rel=“dofollow”>T5 Fatburner</a> <a href=“https://postorder-apotheek.com/product/sustanon/” rel=“dofollow”>Sustanon</a> <a href=“https://postorder-apotheek.com/product/proviron/” rel=“dofollow”>Proviron</a> <a href=“https://postorder-apotheek.com/product/primobolan/” rel=“dofollow”>Primobolan</a> <a href=“https://postorder-apotheek.com/product/oxymetholone/” rel=“dofollow”>Oxymetholone</a> <a href=“https://postorder-apotheek.com/product/melanotan/” rel=“dofollow”>Melanotan</a> <a href=“https://postorder-apotheek.com/product/euthyrox/” rel=“dofollow”>Euthyrox</a> <a href=“https://postorder-apotheek.com/product/liothyronine-t3/” rel=“dofollow”>Liothyronine T3</a> <a href=“https://postorder-apotheek.com/product/hgh-injectie/” rel=“dofollow”>HGH Injectie</a> <a href=“https://postorder-apotheek.com/product/genotropin/” rel=“dofollow”>Genotropin</a> <a href=“https://postorder-apotheek.com/product/dianabol/” rel=“dofollow”>Dianabol</a> <a href=“https://postorder-apotheek.com/product/deca-durabolin/” rel=“dofollow”>Deca Durabolin</a> <a href=“https://postorder-apotheek.com/product/clenbuterol/” rel=“dofollow”>Clenbuterol</a> <a href=“https://postorder-apotheek.com/product/c-testosteron/” rel=“dofollow”>C+ Testosteron</a> <a href=“https://postorder-apotheek.com/product/bacteriostatisch/” rel=“dofollow”>Bacteriostatisch</a> <a href=“https://postorder-apotheek.com/product/aspart-insuline/” rel=“dofollow”>Aspart Insuline</a> <a href=“https://postorder-apotheek.com/product/androgel/” rel=“dofollow”>Androgel</a> <a href=“https://postorder-apotheek.com/product/anavar/” rel=“dofollow”>Anavar</a> <a href=“https://postorder-apotheek.com/product/zopiclon/” rel=“dofollow”>Zopiclon</a> <a href=“https://postorder-apotheek.com/product/zolpidem/” rel=“dofollow”>Zolpidem</a> <a href=“https://postorder-apotheek.com/product/temazepam/” rel=“dofollow”>Temazepam</a> <a href=“https://postorder-apotheek.com/product/modafinil/” rel=“dofollow”>Modafinil</a> <a href=“https://postorder-apotheek.com/product/mirtazapine/” rel=“dofollow”>Mirtazapine</a> <a href=“https://postorder-apotheek.com/product/midazolam/” rel=“dofollow”>Midazolam</a> <a href=“https://postorder-apotheek.com/product/melatonine/” rel=“dofollow”>Melatonine</a> <a href=“https://postorder-apotheek.com/product/lormetazepam/” rel=“dofollow”>Lormetazepam</a> <a href=“https://postorder-apotheek.com/product/rivotril/” rel=“dofollow”>Rivotril</a> <a href=“https://postorder-apotheek.com/product/tramadol/” rel=“dofollow”>Tramadol</a> <a href=“https://postorder-apotheek.com/product/tapentadol/” rel=“dofollow”>Tapentadol</a> <a href=“https://postorder-apotheek.com/product/roaccutane/” rel=“dofollow”>Roaccutane</a> <a href=“https://postorder-apotheek.com/product/lyrica/” rel=“dofollow”>Lyrica</a> <a href=“https://postorder-apotheek.com/product/paracetamol/” rel=“dofollow”>Paracetamol</a> <a href=“https://postorder-apotheek.com/product/oxycodon/” rel=“dofollow”>Oxycodon</a> <a href=“https://postorder-apotheek.com/product/naproxen/” rel=“dofollow”>Naproxen</a> <a href=“https://postorder-apotheek.com/product/morfine/” rel=“dofollow”>Morfine</a> <a href=“https://postorder-apotheek.com/product/ibuprofen-eg/” rel=“dofollow”>Ibuprofen EG</a> <a href=“https://postorder-apotheek.com/product/finasteride/” rel=“dofollow”>Finasteride</a> <a href=“https://postorder-apotheek.com/product/diclofenac/” rel=“dofollow”>Diclofenac</a> <a href=“https://postorder-apotheek.com/product/codeine/” rel=“dofollow”>Codeine</a> <a href=“https://postorder-apotheek.com/product/baclofen/” rel=“dofollow”>Baclofen</a> <a href=“https://postorder-apotheek.com/product/promethazine/” rel=“dofollow”>Promethazine</a> <a href=“https://postorder-apotheek.com/product/levocetirizine-eg/” rel=“dofollow”>Levocetirizine</a> <a href=“https://postorder-apotheek.com/product/fexofenadine/” rel=“dofollow”>Fexofenadine</a> <a href=“https://postorder-apotheek.com/product/efedrine/” rel=“dofollow”>Efedrine</a> <a href=“https://postorder-apotheek.com/product/desloratadine/” rel=“dofollow”>Desloratadine</a> <a href=“https://postorder-apotheek.com/product/clomid/” rel=“dofollow”>Clomid</a> <a href=“https://postorder-apotheek.com/product/cetirizine-eg/” rel=“dofollow”>Cetirizine EG</a> <a href=“https://postorder-apotheek.com/product/pantoprazol/” rel=“dofollow”>Pantoprazol</a> <a href=“https://postorder-apotheek.com/product/omeprazol/” rel=“dofollow”>Omeprazol</a> <a href=“https://postorder-apotheek.com/product/nexium/” rel=“dofollow”>Nexium</a> <a href=“https://postorder-apotheek.com/product/nolvadex/” rel=“dofollow”>Nolvadex</a> <a href=“https://postorder-apotheek.com/product/letrozol/” rel=“dofollow”>Letrozol</a> <a href=“https://postorder-apotheek.com/product/exemestaan/” rel=“dofollow”>Exemestaan</a> <a href=“https://postorder-apotheek.com/product/arimidex/” rel=“dofollow”>Arimidex</a> <a href=“https://postorder-apotheek.com/product/minoxidil/” rel=“dofollow”>Minoxidil</a> <a href=“https://postorder-apotheek.com/product/minoxidil-2/” rel=“dofollow”>Minoxidil</a> <a href=“https://postorder-apotheek.com/product/vidalista/” rel=“dofollow”>Vidalista</a> <a href=“https://postorder-apotheek.com/product/tamsulosine/” rel=“dofollow”>Tamsulosine</a> <a href=“https://postorder-apotheek.com/product/tadalafil/” rel=“dofollow”>Tadalafil</a> <a href=“https://postorder-apotheek.com/product/kamagra/” rel=“dofollow”>Kamagra</a> <a href=“https://postorder-apotheek.com/product/spedra/” rel=“dofollow”>Spedra</a> <a href=“https://postorder-apotheek.com/product/priligy/” rel=“dofollow”>Priligy</a> <a href=“https://postorder-apotheek.com/product/viagra/” rel=“dofollow”>Viagra</a> <a href=“https://postorder-apotheek.com/product/lovegra/” rel=“dofollow”>Lovegra</a> <a href=“https://postorder-apotheek.com/product/lovegra-2/” rel=“dofollow”>Lovegra</a> <a href=“https://postorder-apotheek.com/product/levitra/” rel=“dofollow”>Levitra</a> <a href=“https://postorder-apotheek.com/product/kamagra-2/” rel=“dofollow”>Kamagra</a> <a href=“https://postorder-apotheek.com/product/kamagra-3/” rel=“dofollow”>Kamagra</a> <a href=“https://postorder-apotheek.com/product/dutasteride/” rel=“dofollow”>Dutasteride</a> <a href=“https://postorder-apotheek.com/product/cobra/” rel=“dofollow”>Cobra</a> <a href=“https://postorder-apotheek.com/product/cialis/” rel=“dofollow”>Cialis</a> <a href=“https://postorder-apotheek.com/product/cenforce/” rel=“dofollow”>Cenforce</a> <a href=“https://postorder-apotheek.com/product/avodart/” rel=“dofollow”>Avodart</a> <a href=“https://postorder-apotheek.com/product/valaciclovir/” rel=“dofollow”>Valaciclovir</a> <a href=“https://postorder-apotheek.com/product/tamiflu/” rel=“dofollow”>Tamiflu</a> <a href=“https://postorder-apotheek.com/product/famciclovir/” rel=“dofollow”>Famciclovir</a> <a href=“https://postorder-apotheek.com/product/aciclovir/” rel=“dofollow”>Aciclovir</a> <a href=“https://postorder-apotheek.com/product/wegovy/” rel=“dofollow”>Wegovy</a> <a href=“https://postorder-apotheek.com/product/ozempic/” rel=“dofollow”>Ozempic</a> <a href=“https://postorder-apotheek.com/product/zoloft/” rel=“dofollow”>Zoloft</a> <a href=“https://postorder-apotheek.com/product/xanax/” rel=“dofollow”>Xanax</a> <a href=“https://postorder-apotheek.com/product/venlafaxine/” rel=“dofollow”>Venlafaxine</a> <a href=“https://postorder-apotheek.com/product/valium/” rel=“dofollow”>Valium</a> <a href=“https://postorder-apotheek.com/product/tentin/” rel=“dofollow”>Tentin</a> <a href=“https://postorder-apotheek.com/product/ritalin/” rel=“dofollow”>Ritalin</a> <a href=“https://postorder-apotheek.com/product/seroquel/” rel=“dofollow”>Seroquel</a> <a href=“https://postorder-apotheek.com/product/prozac/” rel=“dofollow”>Prozac</a> <a href=“https://postorder-apotheek.com/product/paroxetine/” rel=“dofollow”>Paroxetine</a> <a href=“https://postorder-apotheek.com/product/seresta/” rel=“dofollow”>Seresta</a> <a href=“https://postorder-apotheek.com/product/lorazepam/” rel=“dofollow”>Lorazepam</a> <a href=“https://postorder-apotheek.com/product/ketamine/” rel=“dofollow”>Ketamine</a> <a href=“https://postorder-apotheek.com/product/concerta/” rel=“dofollow”>Concerta</a> <a href=“https://postorder-apotheek.com/product/citalopram/” rel=“dofollow”>Citalopram</a> <a href=“https://postorder-apotheek.com/product/bromazepam/” rel=“dofollow”>Bromazepam</a> <a href=“https://postorder-apotheek.com/product/amitriptyline/” rel=“dofollow”>Amitriptyline</a> <a href=“https://postorder-apotheek.com/product/amfetamine/” rel=“dofollow”>Amfetamine</a> <a href=“https://postorder-apotheek.com/product/alprazolam/” rel=“dofollow”>Alprazolam</a> <a href=“https://postorder-apotheek.com/product/alprazolam-2/” rel=“dofollow”>Alprazolam</a> <a href=“https://postorder-apotheek.com/product/adderall/” rel=“dofollow”>Adderall</a> <a href=“https://postorder-apotheek.com/product/nitrofurantoine/” rel=“dofollow”>Nitrofurantoïne</a> <a href=“https://postorder-apotheek.com/product/minocycline/” rel=“dofollow”>Minocycline</a> <a href=“https://postorder-apotheek.com/product/fusidinezuur/” rel=“dofollow”>Fusidinezuur</a> <a href=“https://postorder-apotheek.com/product/fosfomycine/” rel=“dofollow”>Fosfomycine</a> <a href=“https://postorder-apotheek.com/product/flucloxacilline/” rel=“dofollow”>Flucloxacilline</a> <a href=“https://postorder-apotheek.com/product/flagyl/” rel=“dofollow”>Flagyl</a> <a href=“https://postorder-apotheek.com/product/doxycycline/” rel=“dofollow”>Doxycycline</a> <a href=“https://postorder-apotheek.com/product/cotrimoxazol/” rel=“dofollow”>Cotrimoxazol</a> <a href=“https://postorder-apotheek.com/product/clindamycine/” rel=“dofollow”>Clindamycine</a> <a href=“https://postorder-apotheek.com/product/claritromycine/” rel=“dofollow”>Claritromycine</a> <a href=“https://postorder-apotheek.com/product/ciprofloxacine/” rel=“dofollow”>Ciprofloxacine</a> <a href=“https://postorder-apotheek.com/product/ciprofloxacine-2/” rel=“dofollow”>Ciprofloxacine</a> <a href=“https://postorder-apotheek.com/product/amoxicilline/” rel=“dofollow”>Amoxicilline</a>

1 | | 2026-01-04 11:48 | reply



  • blog/2013/2013-06-04.1376870995.txt.gz
  • 最終更新: 2013-08-19 09:09
  • by Decomo