zfs install script for freebsd


#!/bin/sh

#---------------------------------------------------------------------------------------------
export path=/sbin:/bin:/usr/sbin:/usr/bin:/mnt2/sbin:/mnt2/bin:/mnt2/usr/sbin:/mnt2/usr/bin
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/mnt2/sbin:/mnt2/bin:/mnt2/usr/sbin:/mnt2/usr/bin

#swap partition size in MB
swapsize=512

err() {
echo Error $1;
exit 1
}

diskdrive=$1

#add check for -z $1

#Create MBR geometry on the disk
gpart create -s mbr $diskdrive || err "Creating MBR geometry on the disk $diskdrive"

begin=`gpart show $diskdrive | grep "\- free -"|awk '{print $1}'`
size=` gpart show $diskdrive | grep "\- free -"|awk '{print $2}'`

echo "Creating FreeBSD partition for ZFS pool. Start from sector# $begin with sise $size on $diskdrive"

slice=`gpart add -b $begin -s $size -t freebsd $diskdrive|awk '{print $1}'` || err "Creating partition"
index=`gpart show $diskdrive|grep "freebsd"|awk '{print $3}' `

gpart create -s BSD $slice || err "gpart create -s BSD $slice"

echo "slice:$slice index:$index"

gpart set -a active -i $index $diskdrive
echo ----------------------------------------
gpart show $slice
echo ----------------------------------------

#creating two slice
# freebsd-zfs whool disk - $swapsize
# freebsd-swap $swapsize
#mathematics

whoolsize=`gpart show $slice | grep "\- free -"|awk '{print $2}'`
end1=`echo "$whoolsize-$swapsize*1024*2"|bc`||err "calculate middle point"
swapsizeb=`echo "$swapsize*1024*2"|bc`||err "calculate swapsize in blocks"

echo "end1 is $end1, swapsize is $swapsizeb blocks"

#create fist slice freebsd-zfs
gpart add -i 1 -b 0 -s $end1 -t freebsd-zfs $slice || err "create slice freebsd-zfs"

#create second slice freebsd-swap
gpart add -i 2 -b $end1 -s $swapsizeb -t freebsd-swap $slice ||err "create slice freebsd-swap"

#usualy /cdrom mount in /mnt2 in FixIT mode

kldload /mnt2/boot/kernel/opensolaris.ko >/dev/null
kldload /mnt2/boot/kernel/zfs.ko >/dev/null

#creating ZFS pool and set bootable
mkdir /boot/zfs
zpool create zroot /dev/${slice}a
zpool set bootfs=zroot zroot

gpart bootcode -b /mnt2/boot/boot0 $diskdrive

#Export zroot, before installing boot code
zpool export zroot

#unprotect disks
sysctl kern.geom.debugflags=0x10

dd if=/mnt2/boot/zfsboot of=/dev/$slice count=1
dd if=/mnt2/boot/zfsboot of=/dev/${slice}a skip=1 seek=1024

zpool import zroot

#Creating ZFS layout
#The fletcher4 algorithm should be more robust than the fletcher2 algorithm.
zfs set checksum=fletcher4 zroot

zfs create -o compression=on -o exec=on -o setuid=off zroot/tmp
chmod 1777 /zroot/tmp

zfs create zroot/usr
zfs create zroot/usr/home
cd /zroot ; ln -s /usr/home home

zfs create -o compression=lzjb -o setuid=off zroot/usr/ports
zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/distfiles
zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/packages
zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/usr/src
zfs create zroot/var
zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/var/crash
zfs create -o exec=off -o setuid=off zroot/var/db
zfs create -o compression=lzjb -o exec=on -o setuid=off zroot/var/db/pkg
zfs create -o exec=off -o setuid=off zroot/var/empty
zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/var/log
zfs create -o compression=gzip -o exec=off -o setuid=off zroot/var/mail
zfs create -o exec=off -o setuid=off zroot/var/run
zfs create -o compression=lzjb -o exec=on -o setuid=off zroot/var/tmp

chmod 1777 /zroot/var/tmp

# cd /dist/8.0-*
cd /mnt2/8.0-RELEASE/

DESTDIR=/zroot
export DESTDIR=/zroot
for dir in base catpages dict doc games info manpages; \
# do (cd $dir ; ./install.sh) ; \
do (cd $dir ; cat ${dir}.?? | tar --unlink -xpzf - -C ${DESTDIR} ) ; \
done

# There is system halted -- it's very strange, to do investigate it.
#echo extracting ports;
#tar --unlink -xpzf ports/ports.tgz -C ${DESTDIR}/usr ;
#
echo installing source code and kernel

cd src ; ./install.sh all
cd ../kernels ; ./install.sh generic
cd /zroot/boot ; cp -Rlp GENERIC/* /zroot/boot/kernel/

#zfs set readonly=on zroot/var/empty

echo create boot environment

echo 'zfs_enable="YES"' >> /zroot/etc/rc.conf
echo 'hostname="beastie.mydomain.local"'>> /zroot/etc/rc.conf
echo 'ifconfig_re0="DHCP"' >> /zroot/etc/rc.conf
echo 'zfs_load="YES"' >> /zroot/boot/loader.conf
echo 'vfs.root.mountfrom="zfs:zroot"' >> /zroot/boot/loader.conf
echo 'LOADER_ZFS_SUPPORT=YES' > /zroot/etc/src.conf

cat >/zroot/mkd.sh <> /var/log/make.log
make depend >> /var/log/make.log
make >> /var/log/make.log
cd i386/loader
make install >> /var/log/make.log
umount /dev
EOF

chmod +x /zroot/mkd.sh

echo making ZFS loader

chroot /zroot /mkd.sh

cp /boot/zfs/zpool.cache /zroot/boot/zfs/zpool.cache

echo Create /etc/fstab
cat << EOF > /zroot/etc/fstab
# Device Mountpoint FStype Options Dump Pass#
/dev/${slice}b none swap sw 0 0
EOF

export LD_LIBRARY_PATH=/mnt2/lib

echo Unmount all zfs filesystems
zfs unmount -a -f

echo Change mount points for zroot pool
zfs set mountpoint=legacy zroot
zfs set mountpoint=/tmp zroot/tmp
zfs set mountpoint=/usr zroot/usr
zfs set mountpoint=/var zroot/var

echo "Exit Fixit mode, and then sysinstall. "
echo "Remove the FreeBSD install DVD/Memstick and the system will boot using the ZFS root."
#--------------------------------------------------------------------------------------------

сперто от сюда

Запись опубликована в рубрике overminds с метками . Добавьте в закладки постоянную ссылку.

Добавить комментарий