FreeBSD配置ZFS做为根系统

声明:不建议使用ZFS做根文件系统

需要的文件

需要FreeBSD的DVD镜像 或者 memstick.img文件,其他的都不完整,所以不推荐

启动到Fixit

1.启动DVD 2.选择Fixit 3.选择CDROM/DVD,回车

创建mbr结构分区表,如果已存可以省略

Fixit# gpart create -s mbr ad4

显示分区信息

Fixit# gpart show ad4

在ad4上创建FreeBSD使用的分区ad4s3

Fixit# gpart add -b 6313545 -s 119515536 -t freebsd ad4
ad4s3 added
Fixit# gpart create -s BSD ad4s3
ad4s3 created

创建FreeBSD Partition

ad4s3a的分区是去掉Swap分区后的大小,计算公式时1024x1024x2=1G

Fixit# gpart add -i 1 -b 0 -s 117418384 -t freebsd-zfs ad4s3
ad4s3a added
Fixit# gpart show ad4s3

Fixit# gpart add -i 2 -b 117418384 -s 8380811 -t freebsd-swap ad4s3
ad4s3b added
Fixit# gpart show ad4s3

安装FreeBSD自带的引导器,boot0阶段

Fixit# gpart bootcode -b /mnt2/boot/boot0 ad4
ad4 has bootcode

boot1阶段

Fixit# dd if=/mnt2/boot/zfsboot of=/dev/ad4s3 count=1

boot2阶段

Fixit# dd if=/mnt2/boot/zfsboot of=/dev/ad4s3a skip=1 seek=1024

加载zfs内核模块

Fixit# kldload /mnt2/boot/kernel/opensolaris.ko
Fixit# kldload /mnt2/boot/kernel/zfs.ko

创建ZFS存储池

Fixit# zpool create tank /dev/ad4s3a
Fixit# zpool set bootfs=tank tank

文件系统校验使用fletcher4方式

Fixit# zfs set checksum=fletcher4 tank

创建ZFS文件目录结构

Fixit# zfs create -o compression=on -o exec=on -o setuid=off tank/tmp
Fixit# chmod 1777 /tank/tmp
Fixit# zfs create tank/usr
Fixit# zfs create tank/home
Fixit# zfs create -o compression=lzjb -o setuid=off tank/usr/ports
Fixit# zfs create -o compression=off -o exec=off -o setuid=off tank/usr/ports/distfiles
Fixit# zfs create -o compression=off -o exec=off -o setuid=off tank/usr/ports/packages
Fixit# zfs create -o compression=lzjb -o exec=off -o setuid=off tank/usr/src
Fixit# zfs create tank/var
Fixit# zfs create -o compression=lzjb -o exec=off -o setuid=off tank/var/crash
Fixit# zfs create -o exec=off -o setuid=off tank/var/db
Fixit# zfs create -o compression=lzjb -o exec=on -o setuid=off tank/var/db/pkg
Fixit# zfs create -o exec=off -o setuid=off tank/var/empty
Fixit# zfs create -o compression=lzjb -o exec=off -o setuid=off tank/var/log
Fixit# zfs create -o compression=gzip -o exec=off -o setuid=off tank/var/mail
Fixit# zfs create -o exec=off -o setuid=off tank/var/run
Fixit# zfs create -o compression=lzjb -o exec=on -o setuid=off tank/var/tmp
Fixit# chmod 1777 /tank/var/tmp

安装FreeBSD到ZFS上

Fixit# cd /dist/8.1*
Fixit# export DESTDIR=/tank
这里推荐先不要释放ports,曾经8.0上释放ports会导致重启
Fixit# for dir in base catpages dict doc games info lib32 manpages; \
     do (cd $dir ; ./install.sh) ; done
Fixit# cd src ; ./install.sh all
Fixit# cd ../kernels ; ./install.sh generic
Fixit# cd /tank/boot ; cp -Rlp GENERIC/* /tank/boot/kernel/
Fixit# cd /
Fixit# zfs set readonly=on tank/var/empty

安装后配置

在rc.conf,src.conf,fstab,loader.conf文件里添加了这些内容就行,不管你使用什么方法ee,vi,echo。都行

Fixit# echo ‘zfs_enable="YES"’ > /etc/rc.conf
Fixit# echo ‘hostname="FreeBSD.tk.local"’ >> /etc/rc.conf
Fixit# echo ‘ifconfig_em0="DHCP"’ >> /etc/rc.conf
Fixit# echo ‘LOADER_ZFS_SUPPORT=YES’ > /tank/etc/src.conf
Fixit# echo ‘zfs_load="YES"’ > /tank/boot/loader.conf
Fixit# echo ‘vfs.root.mountfrom="zfs:tank"’ >> /tank/boot/loader.conf
Fixit# cat << EOF > /tank/etc/fstab
# Device                       Mountpoint              FStype  Options         Dump    Pass#
/dev/ad4s3b                    none                    swap    sw              0       0
EOF

重新编译引导器,添加zfs支持

Fixit# chroot /tank
Fixit# mount -t devfs devfs /dev
Fixit# export DESTDIR=""
Fixit# cd /usr/src/sys/boot/
Fixit# make obj
Fixit# make depend
Fixit# make
Fixit# cd i386/loader
Fixit# make install

设置密码

Fixit# passwd

设置时区

Fixit# tzsetup
Fixit# cd /etc/mail
Fixit# make aliases
Fixit# umount /dev
Fixit# exit

创建zpool.cache

Fixit# mkdir /boot/zfs
Fixit# zpool export tank && zpool import tank
Fixit# cp /boot/zfs/zpool.cache /tank/boot/zfs/zpool.cache
Fixit# export LD_LIBRARY_PATH=/mnt2/lib

修改zfs存储池tank的挂载点

Fixit# zfs set mountpoint=legacy tank
Fixit# zfs set mountpoint=/tmp tank/tmp
Fixit# zfs set mountpoint=/usr tank/usr
Fixit# zfs set mountpoint=/var tank/var
Fixit# zfs set mountpoint=/home tank/home

卸载所有

Fixit# zfs unmount -a

退出,重新引导系统

Fixit# exit

其他

1.有时会出现找不到引导器,重启后就可以引导了,原因不明

2.可能导致Windows7出现引导器修复界面

原文链接:http://wiki.freebsdchina.org/doc/z/zfsbootpartition

《FreeBSD配置ZFS做为根系统》有1个想法

发表评论

电子邮件地址不会被公开。 必填项已用*标注