# bectl list
BE Active Mountpoint Space Created
0915 - - 4.00M 2023-09-19 19:44
13.2-RELEASE-p2_2023-09-13_141111 - - 29.0M 2023-09-13 14:11
new - - 432K 2023-09-20 15:17
default NR / 40.8G 2023-04-10 10:06
其中 Active 这一列中 N 表示当前使用环境,R 表示下次启动时使用的环境。bectl 工具可以改变下次使用的启动环境(在启动 FreeBSD 时,启动菜单里选 8,也可以改变启动环境)
bectl activate new
Successfully activated boot environment new
再次用 bectl list 查看,观察 Active 列的变化
bectl list
BE Active Mountpoint Space Created
0915 - - 4.00M 2023-09-19 19:44
13.2-RELEASE-p2_2023-09-13_141111 - - 29.0M 2023-09-13 14:11
new R / 2.84M 2023-09-20 15:17
default N - 40.8G 2023-04-10 10:06
重启 FreeBSD (启动菜单里选择 new 启动环境,或如上用 bectl activate new 切换到 new 启动环境),用 df 观察,挂载的根目录的文件系统已经是 zroot/ROOT/new
root@u13t14 # zpool status
pool: zroot
state: ONLINE
status: Some supported and requested features are not enabled on the pool.
The pool can still be used, but some features are unavailable.
action: Enable all features using 'zpool upgrade'. Once this is done,
the pool may no longer be accessible by software that does not support
the features. See zpool-features(7) for details.
config:
NAME STATE READ WRITE CKSUM
zroot ONLINE 0 0 0
ada0p3 ONLINE 0 0 0
errors: No known data errors
未升级前不能使用所有 zfs 新功能,下面进行升级:
root@u13t14 # zpool upgrade zroot
This system supports ZFS pool feature flags.
Enabled the following features on 'zroot':
edonr
zilsaxattr
head_errlog
blake3
block_cloning
vdev_zaps_v2
Pool 'zroot' has the bootfs property set, you might need to update
the boot code. See gptzfsboot(8) and loader.efi(8) for details.
root@u13t14 # gpart bootcode -p /boot/gptzfsboot -i 1 ada0
partcode written to ada0p1
可再次查看 zpool 状态:
root@u13t14 # zpool status
pool: zroot
state: ONLINE
config:
NAME STATE READ WRITE CKSUM
zroot ONLINE 0 0 0
ada0p3 ONLINE 0 0 0
errors: No known data errors
safreya ~ % zfs create -o encryption=on -o keyformat=passphrase zroot/home/safreya/secret
Enter new passphrase: #此处输入密码,密码不会回显,就是什么也没有
Re-enter new passphrase: #此处重复输入上述密码,密码不会回显,就是什么也没有
查看加密情况:
safreya ~ % zfs get mounted zroot/home/safreya/secret
NAME PROPERTY VALUE SOURCE
zroot/home/safreya/secret mounted yes -
查看 mounted 属性,加密数据集创建即挂载,现在创建一个文件,然后卸载加密数据集:
safreya ~ % cd secret
safreya secret % echo "a secret makes a man mad" >abc.txt
safreya secret % cd ..
safreya ~ % zfs unmount zroot/home/safreya/secret
safreya ~ % zfs unload-key zroot/home/safreya/secret
safreya ~ % zfs get mounted zroot/home/safreya/secret
NAME PROPERTY VALUE SOURCE
zroot/home/safreya/secret mounted no -
safreya ~ % ls secret #并无输出
safreya ~ %
卸载加密数据集必须记得也要同时卸载密钥。挂载加密数据集亦要先加载密钥:
safreya ~ % zfs load-key zroot/home/safreya/secret
Enter passphrase for 'zroot/home/safreya/secret':
safreya ~ % zfs mount zroot/home/safreya/secret
safreya ~ % ls secret
Permissions Size User Date Modified Name
.rw-r--r-- 25 safreya 19 Sep 20:26 abc.txt
root safreya # adduser
Username: test
Full name:
Uid (Leave empty for default):
Login group [test]:
Login group is test. Invite test into other groups? []:
Login class [default]:
Shell (sh csh tcsh zsh rzsh git-shell bash rbash nologin) [sh]:
Home directory [/home/test]:
Home directory permissions (Leave empty for default):
Enable ZFS encryption? (yes/no) [no]: yes #该功能为新增功能
Use password-based authentication? [yes]:
Use an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
Enter password:
Enter password again:
Lock out the account after creation? [no]:
Username : test
Password : *****
Full Name :
Uid : 1003
ZFS dataset : zroot/home/test
Encrypted : yes
Class :
Groups : test
Home : /home/test
Home Mode :
Shell : /bin/sh
Locked : no
OK? (yes/no) [yes]:
Enter encryption keyphrase for ZFS dataset (zroot/home/test):
Enter new passphrase:
Re-enter new passphrase:
adduser: INFO: Successfully created ZFS dataset (zroot/home/test).
adduser: INFO: Successfully added (test) to the user database.
Add another user? (yes/no) [no]: no
Goodbye!
查看权限:
root safreya # zfs allow zroot/home/test
---- Permissions on zroot/home/test ----------------------------------
Local+Descendent permissions:
user test create,destroy,mount,snapshot