Собственно сам скрипт.
Код: Выделить всё
dev1=ada0
dev2=ada1
dev3=ada2
dev4=ada3
dev5=ada4
dev6=ada5
pool_name=rpool
swap_size="16G"
start_boot="40"
end_boot="1024"
start_fs="4096"
# ----- Start script -----
# TMP
mount_dir=/var/tmp
umount /dev/md1
mdmfs -s 512M md1 /tmp
sysctl kern.geom.debugflags=17
# Gpart create
zpool destroy -f $pool_name
gpart destroy -F $dev1
gpart destroy -F $dev2
gpart destroy -F $dev3
gpart destroy -F $dev4
gpart destroy -F $dev5
gpart destroy -F $dev6
gpart create -s GPT $dev1
gpart add -b $start_boot -s $end_boot -t freebsd-boot $dev1
gpart add -t freebsd-zfs -l disk1 $dev1
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $dev1
gpart create -s GPT $dev2
gpart add -b $start_boot -s $end_boot -t freebsd-boot $dev2
gpart add -t freebsd-zfs -l disk2 $dev2
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $dev2
gpart create -s GPT $dev3
gpart add -b $start_boot -s $end_boot -t freebsd-boot $dev3
gpart add -t freebsd-zfs -l disk3 $dev3
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $dev3
gpart create -s GPT $dev4
gpart add -b $start_boot -s $end_boot -t freebsd-boot $dev4
gpart add -t freebsd-zfs -l disk4 $dev4
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $dev4
gpart create -s GPT $dev5
gpart add -b $start_boot -s $end_boot -t freebsd-boot $dev5
gpart add -t freebsd-zfs -l disk5 $dev5
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $dev5
gpart create -s GPT $dev6
gpart add -b $start_boot -s $end_boot -t freebsd-boot $dev6
gpart add -t freebsd-zfs -l disk6 $dev6
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $dev6
# Create pool zfs for a non gnop, comment "4kb sector" section/
# zpool create -f $pool_name raidz /dev/gpt/disk1 /dev/gpt/disk2 /dev/gpt/disk3 /dev/gpt/disk4 /dev/gpt/disk5 /dev/gpt/disk6
# ----- 4kb sector ------
gnop create -S $start_fs /dev/gpt/disk1
gnop create -S $start_fs /dev/gpt/disk2
gnop create -S $start_fs /dev/gpt/disk3
gnop create -S $start_fs /dev/gpt/disk4
gnop create -S $start_fs /dev/gpt/disk5
gnop create -S $start_fs /dev/gpt/disk6
zpool create -f -o altroot=$mount_dir -o cachefile=/var/tmp/zpool.cache $pool_name raidz /dev/gpt/disk1.nop /dev/gpt/disk2.nop /dev/gpt/disk3.nop /dev/gpt/disk4.nop /dev/gpt/disk5.nop /dev/gpt/disk6.nop
zpool export $pool_name
gnop destroy -f /dev/gpt/disk1.nop
gnop destroy -f /dev/gpt/disk2.nop
gnop destroy -f /dev/gpt/disk3.nop
gnop destroy -f /dev/gpt/disk4.nop
gnop destroy -f /dev/gpt/disk5.nop
gnop destroy -f /dev/gpt/disk6.nop
zpool import -o altroot=$mount_dir -o cachefile=/var/tmp/zpool.cache $pool_name
# ----- 4kb sector ------
#Set bootfs
zpool set bootfs=$pool_name $pool_name
zfs set checksum=fletcher4 $pool_name
zfs set mountpoint=$mount_dir $pool_name
zpool export $pool_name
zpool import -o cachefile=/tmp/zpool.cache $pool_name
# zfs sets
zfs create $pool_name/usr
zfs create $pool_name/usr/home
zfs create $pool_name/var
## zfs create $pool_name/tmp
zfs create -o compression=on -o exec=on -o setuid=off $pool_name/tmp
zfs create -o compression=lzjb -o setuid=off $pool_name/usr/ports
zfs create -o compression=off -o exec=off -o setuid=off $pool_name/usr/ports/distfiles
zfs create -o compression=off -o exec=off -o setuid=off $pool_name/usr/ports/packages
zfs create -o compression=lzjb -o exec=off -o setuid=off $pool_name/usr/src
zfs create -o compression=lzjb -o exec=off -o setuid=off $pool_name/var/crash
zfs create -o exec=off -o setuid=off $pool_name/var/db
zfs create -o compression=lzjb -o exec=on -o setuid=off $pool_name/var/db/pkg
zfs create -o exec=off -o setuid=off $pool_name/var/empty
zfs create -o compression=lzjb -o exec=off -o setuid=off $pool_name/var/log
zfs create -o compression=gzip -o exec=off -o setuid=off $pool_name/var/mail
zfs create -o exec=off -o setuid=off $pool_name/var/run
zfs create -o compression=lzjb -o exec=on -o setuid=off $pool_name/var/tmp
# Create swap
zfs create -V $swap_size $pool_name/swap
zfs set org.freebsd:swap=on $pool_name/swap
zfs set checksum=off $pool_name/swap
# Chmod tmp
chmod 1777 $mount_dir/tmp
cd /var/tmp ; ln -s /usr/home home
chmod 1777 $mount_dir/var/tmp
# Install freebsd
cd /usr/freebsd-dist
export DESTDIR=$mount_dir
for file in base.txz lib32.txz kernel.txz doc.txz ports.txz src.txz; do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}); done
# Copy cache
cp /tmp/zpool.cache $mount_dir/boot/zfs/zpool.cache
# Create config
echo 'zfs_enable="YES"' >> $mount_dir/etc/rc.conf
chmod 1777 $mount_dir/boot
echo 'zfs_load="YES"' >> $mount_dir/boot/loader.conf
echo "vfs.root.mountfrom=\"zfs:$pool_name\"" >> $mount_dir/boot/loader.conf
mkdir $mount_dir/cdrom
touch $mount_dir/etc/fstab
# cat << EOF > $mount_dir/etc/fstab
##Device Mountpoint FStype Options Dump Pass#
# /dev/gtp/swap0 none swap sw 0 0
# /dev/cd0 /cdrom cd9660 ro,noauto 0 0
# EOF
# Change mountpoint
zfs set readonly=on $pool_name/var/empty
zfs umount -af
zfs set mountpoint=legacy $pool_name
zfs set mountpoint=/tmp $pool_name/tmp
zfs set mountpoint=/usr $pool_name/usr
zfs set mountpoint=/var $pool_name/var
echo "Finished"
sleep 5
reboot
Скрипт используя gnop выравнивает диск под 4кб
проверить можно zdb | grep ashift, должно быть 12 а не 9.
Но ...
Мне не нравится следующее.
Когда я создаю GPT, дискам даю метки
Код: Выделить всё
gpart add -t freebsd-zfs -l disk2 $dev2
Как то так:
Код: Выделить всё
zpool status
pool: rpool
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
rpool ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
ada0p2 ONLINE 0 0 0
ada1p2 ONLINE 0 0 0
Код: Выделить всё
zpool status
pool: rpool
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
rpool ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
disk1 ONLINE 0 0 0
disk2 ONLINE 0 0 0
Как поправить положение, хочется видить диски в пуле по меткам.
Спасибо.