创建可启动的 ZFS 文件系统

创建可启动的 ZFS 文件系统

我有一台来自 OVH 的服务器,并按照以下步骤在 OVH 服务器上的 FreeBSD10 上设置 ZFShttps://wiki.freebsd.org/RootOnZFS/GPTZFSBoot/Mirror

创建可启动的 ZFS 文件系统

zpool destroy zroot
gpart destroy -F ada0
gpart destroy -F ada1

gpart create -s gpt ada0
gpart create -s gpt ada1

gpart add -b 34 -s 64k -t freebsd-boot ada0
gpart add -s 8G -t freebsd-swap -l swap0 ada0
gpart add -t freebsd-zfs -l disk0 ada0

gpart add -b 34 -s 64k -t freebsd-boot ada1
gpart add -s 8G -t freebsd-swap -l swap1 ada1
gpart add -t freebsd-zfs -l disk1 ada1

gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1

创建 ZFS 池 zroot

mkdir /tmp/zroot
zpool create -o cachefile=/boot/zfs/zpool.cache -m none -f zroot mirror /dev/gpt/disk0 /dev/gpt/disk1
zpool set bootfs=zroot zroot
zfs set checksum=fletcher4 zroot
zfs set mountpoint=/tmp/zroot zroot

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

安装 FreeBSD 到 ZFS 文件系统

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

chmod 1777 /tmp/zroot/tmp

zfs create zroot/usr

zfs create zroot/var
zfs create -o compression=lz4 -o exec=off -o setuid=off zroot/var/crash
zfs create -o exec=off -o setuid=off zroot/var/db
zfs create -o compression=lz4 -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=lz4 -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=lz4 -o exec=on -o setuid=off zroot/var/tmp

chmod 1777 /tmp/zroot/var/tmp

zpool export zroot

zpool import -o cachefile=/tmp/zpool.cache zroot

cd /tmp/zroot
mkdir fileinstall
cd fileinstall
fetch http://ftp1.fr.FreeBSD.org/pub/FreeBSD/releases/amd64/10.0-RELEASE/base.txz
fetch http://ftp1.fr.FreeBSD.org/pub/FreeBSD/releases/amd64/10.0-RELEASE/kernel.txz
fetch http://ftp1.fr.FreeBSD.org/pub/FreeBSD/releases/amd64/10.0-RELEASE/src.txz
fetch http://ftp1.fr.FreeBSD.org/pub/FreeBSD/releases/amd64/10.0-RELEASE/doc.txz
fetch http://ftp1.fr.FreeBSD.org/pub/FreeBSD/releases/amd64/10.0-RELEASE/ports.txz

sh

export DESTDIR=/tmp/zroot

for file in base.txz kernel.txz doc.txz src.txz ports.txz;
do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/});
done


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

chroot /tmp/zroot /bin/sh

echo 'zfs_load="YES"' >> /boot/loader.conf
echo 'if_em_load="YES"' >> /boot/loader.conf
echo 'vfs.root.mountfrom="zfs:zroot"' >> /boot/loader.conf
echo 'geom_mirror_load="YES"' >> /boot/loader.conf

echo 'dumpdev="AUTO"' >> /etc/rc.conf
echo 'zfs_enable="YES"' >> /etc/rc.conf
echo 'sshd_enable="YES"' >> /etc/rc.conf
echo 'local_unbound_enable=yes' >> /etc/rc.conf
echo 'ifconfig_igb0="inet XXX.XXX.XXX.XXX netmask 255.255.255.0 broadcast XXX.XXX.XXX.XXX"' >> /etc/rc.conf

echo '# IPv6 configuration' >> /etc/rc.conf
echo 'ipv6_enable="YES"' >> /etc/rc.conf
echo 'ipv6_network_interfaces="igb0"' >> /etc/rc.conf
echo 'ipv6_activate_all_interfaces="YES"' >> /etc/rc.conf
echo 'ipv6_network_interfaces="auto"' >> /etc/rc.conf
echo 'ip6addrctl_policy="ipv6_prefer"' >> /etc/rc.conf
echo 'ifconfig_igb0_ipv6="inet6 2001:XXX:: prefixlen 64"' >> /etc/rc.conf
echo 'ipv6_static_routes="ovhgw"' >> etc/rc.conf
echo 'ipv6_route_ovhgw="2001:XXX:ff -prefixlen 128 -interface igb0"' >> /etc/rc.conf
echo 'ipv6_defaultrouter="2001:XXX:ff"' >> /etc/rc.conf
echo 'hostname="ns426770.ip-37-187-148.eu"' >> /etc/rc.conf

echo 'search ovh.net' >> /etc/resolv.conf
echo 'nameserver 213.186.33.99' >> /etc/resolv.conf

vi /tmp/zroot/etc/fstab
# Device                        Mountpoint              FStype  Options         Dump    Pass#
/dev/gpt/swap0                  none                    swap    sw              0       0
/dev/gpt/swap1                  none                    swap    sw              0       0
zroot                           /                       zfs     rw,noatime      0       0
zroot/tmp                       /tmp                    zfs     rw,noatime      0       0
zroot/usr                       /usr                    zfs     rw,noatime      0       0
zroot/usr/home                  /usr/home               zfs     rw,noatime      0       0
zroot/usr/ports                 /usr/ports              zfs     rw,noatime      0       0
zroot/usr/ports/distfiles       /usr/ports/distfiles    zfs     rw,noatime      0       0
zroot/usr/ports/packages        /usr/ports/packages     zfs     rw,noatime      0       0
zroot/usr/src                   /usr/src                zfs     rw,noatime      0       0
zroot/var                       /var                    zfs     rw,noatime      0       0
zroot/var/crash                 /var/crash              zfs     rw,noatime      0       0
zroot/var/db                    /var/db                 zfs     rw,noatime      0       0
zroot/var/db/pkg                /var/db/pkg             zfs     rw,noatime      0       0
zroot/var/empty                 /var/empty              zfs     ro              0       0
zroot/var/log                   /var/log                zfs     rw,noatime      0       0
zroot/var/mail                  /var/mail               zfs     rw,noatime      0       0
zroot/var/run                   /var/run                zfs     rw,noatime      0       0
zroot/var/tmp                   /var/tmp                zfs     rw,noatime      0       0


passwd root
vi /etc/ssh/sshd_config

exit
exit
cd /
zfs umount -a
zfs set mountpoint=legacy zroot
zfs set mountpoint=/tmp zroot/tmp
zfs set mountpoint=/usr zroot/usr
zfs set mountpoint=/var zroot/var


zfs create -V 4G zroot/swap
zfs set checksum=off zroot/swap
zfs set org.freebsd:swap=on zroot/swap
zfs set readonly=on zroot/var/empty

当我重新启动系统时,我无法访问它,并且 OVH 管理屏幕上出现错误,但由于我没有 KVM 访问权限,因此我无法看到错误。

我在这个过程中是否遗漏了什么?

答案1

好的,我错过了“echo 'defaultrouter="XXX.XXX.XXX.254"”,否则一切正常

相关内容