用户工具

站点工具


doc:z:rootonzfsufsboot

.

ZFS做根分区由UFS分区启动

(注:

原文请参见:http://wiki.freebsd.org/RootOnZFS/UFSBoot

1 创建ZFS

为了模拟双系统环境,之前使用DiskGenius划分两个NTFS的主分区

 Fixit# gpart show ad4
 =>       63  125829018  ad4  MBR  (60G)
          63   10490382    1  !7  (5.0G)
   10490445     4209030    2  !7  (2.0G)
   14699475   111129606       - free -  (53G)

显示ad4磁盘信息,以及为安装FreeBSD所预留的空间

 Fixit# gpart add -b 14699475 -s 111129606 -t freebsd ad4
 ad4s3 added
<code bash>
 Fixit# gpart create -s BSD ad4s3
 ad4s3 created

查看硬盘ad4创建分区后的分区结构:

 Fixit# gpart show ad4
 =>       63  125829018  ad4  MBR  (60G)
          63   10490382    1  !7  (5.0G)
   10490445     4209030    2  !7  (2.0G)
   14699475   111129606    3  freebsd  (53G)

设置活动分区

 Fixit# gpart set -a active -i 1 ad4

Create partitions (ad4s3a, ad4s3b, ad4s3d)

 Fixit# gpart show ad4s3

⇒ 0 111129606 ad4s3 BSD (53G)

         0  111129606  ad4s3  - free -  (53G)
 Fixit# gpart add -i 1 -b 0 -s 1G -t freebsd-ufs ad4s3

ad4s3a added

 Fixit# gpart show ad4s3

⇒ 0 111129606 ad4s3 BSD (53G)

         0    2097152      1  freebsd-ufs  (1G)
   2097152  109032454         - free -  (52G)
 Fixit# gpart add -i 2 -b 2097152 -s 2G -t freebsd-swap ad4s3

ad4s3b added

 Fixit# gpart show ad4s3

⇒ 0 111129606 ad4s3 BSD (53G)

         0    2097152      1  freebsd-ufs  (1.0G)
   2097152    4194304      2  freebsd-swap  (2.0G)
   6291456  104838150         - free -  (50G)
 Fixit# gpart add -i 4 -t freebsd-zfs ad4s3

ad4s3a added

 Fixit# gpart show ad4s3

⇒ 0 111129606 ad4s3 BSD (53G)

         0    2097152      1  freebsd-ufs  (1.0G)
   2097152    4194304      2  freebsd-swap  (2.0G)
   6291456  104838150      4  freebsd-zfs  (50G)

Note: While a ZFS Swap Volume can be used instead of the freebsd-swap partition, crash dumps can't be created on the ZFS Swap

Volume. Sizes and offsets are specified in sectors (1 sector is typically 512 bytes) but can also be specified in MB and GB by

using a 'M' or 'G' suffix. 安装引导器

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

ad4 has bootcode It's ok if you get an “unknown class” message here, but it you get “failed to install” or the like, you'll need to try

again after making sure that nothing is mounted from /dev/ad4.

 Fixit# gpart bootcode -b /mnt2/boot/boot ad4s3

ad4s3 has bootcode

加载ZFS内核模块

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

Create ZFS Pool tank

 Fixit# mkdir /boot/zfs
 Fixit# zpool create tank /dev/ad4s3d
 Fixit# zpool set bootfs=tank tank

Note: zpool名称可以是tank,也可以是其它任何名称 Create UFS /boot

 Fixit# mkdir /tank/bootdir
 Fixit# newfs -U /dev/ad4s3a
 Fixit# mount /dev/ad4s3a /tank/bootdir

2. 设置ZFS,安装FreeBSD

创建ZFS文件系统结构

文件系统校验方式fletcher4算法要比fletcher2算法更好些。

 Fixit# zfs set checksum=fletcher4                                      tank
 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

Note: If you use nullfs or nfs to mount /usr/ports to different locations/servers, you will also need to nullfs/nfs mount

/usr/ports/distfiles and/or /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

注意: 压缩选项可以使用开启(on),关闭(off),lzjb,gzip,gzip-N(其中N值为1时最快,9时最高压缩比);gzip就是gzip-6). ZFS文件系统上启用压缩,会造成文件存储延迟。

will not be accessed that often.

3. 安装FreeBSD

安装FreeBSD到ZFS上

 Fixit# cd /dist/8*
 Fixit# export DESTDIR=/tank
 Fixit# for dir in base catpages dict doc games info lib32 manpages; \                 #这里如果你准备重新make buildworld的那么只需释放base。
          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/

将/var/empty设置设置成只读

 Fixit# zfs set readonly=on tank/var/empty

4. 安装后配置

注意:你可以使用任何你熟悉的工具,只要在以下文件里添加内容就可以了。 Chroot 到 /tank

 Fixit# chroot /tank

创建 /etc/rc.conf

 Fixit# vi /etc/rc.conf
zfs_enable="YES"
hostname="tomato.freebsd.tk"
ifconfig_em0="DHCP"

注意: em0,需要改成你的网卡名称

创建 /boot/loader.conf

 Fixit# vi /boot/loader.conf
zfs_load="YES"
vfs.root.mountfrom="zfs:tank"

创建 /etc/fstab

 Fixit# vi /etc/fstab
 
# Device                       Mountpoint              FStype  Options         Dump    Pass#
/dev/ad4s3a                    /bootdir                ufs     rw              0       0
/dev/ad4s3b                    none                    swap    sw              0       0

重新编译引导器 /boot/loader (Required for 8.0-RELEASE and 7.{0-2}-RELEASE)

 Fixit# echo 'LOADER_ZFS_SUPPORT=YES' > /etc/src.conf
 Fixit# mount -t devfs devfs /dev
 Fixit# export DESTDIR=""
 Fixit# cd /usr/src/sys/boot/
 Fixit# make obj && make depend && make
 Fixit# cd i386/loader && make install

设置root用户密码

 Fixit# passwd

设置本地时区

 Fixit# tzsetup

创建 /etc/mail/aliases.db

 Fixit# cd /etc/mail
 Fixit# make aliases

退出chroot状态

 Fixit# umount /dev
 Fixit# exit

安装 zpool.cache 到 ZFS filesystem

 Fixit# cp /boot/zfs/zpool.cache /tank/boot/zfs/

5. 完成安装

移动 /tank/boot 到 /tank/bootdir

 Fixit# cd /tank
 Fixit# cp -a boot bootdir/
 Fixit# rm -r boot
 Fixit# ln -s bootdir/boot /tank/boot
 Fixit# chflags -h sunlink /tank/boot

注意:原文里使用mv,不不过会提示出错,所以使用cp,及rm了

export LD_LIBRARY_PATH

 Fixit# export LD_LIBRARY_PATH=/mnt2/lib 

卸载全部ZFS filesystems

 Fixit# cd /
 Fixit# umount /tank/bootdir
 Fixit# zfs unmount -a

修改zpool挂载点,退出完成安装

 Fixit# zfs set mountpoint=legacy tank
 Fixit# zfs set mountpoint=/home tank/home
 Fixit# zfs set mountpoint=/tmp tank/tmp
 Fixit# zfs set mountpoint=/usr tank/usr
 Fixit# zfs set mountpoint=/var tank/var
 Fixit# exit
/data/vhosts/wiki-data/pages/doc/z/rootonzfsufsboot.txt · 最后更改: 2011/02/11 15:14 由 gehaowu