27

New ZFS Boot Environments Tool

 4 years ago
source link: https://www.tuicool.com/articles/hit/b67vyae
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

About a month ago I was honored to give talk about ZFS Boot Environments on PBUG . At the end of the presentation I mentioned the history of tools to manage ZFS Boot Environments on FreeBSD.

zeEVjqy.png!web

Pawel Jakub Dawidek – which also was on this PBUG #3 meeting – suggested that I should try to add beadm into the FreeBSD base system. I also heard that idea from many beadm users which repetitively asked why beadm is not in the FreeBSD base system. So after finished PBUG #3 that is exactly what I did. I created new PR – Bug 230323 – Idea/Feature Request – include beadm in the base – and to my (positive) surprise they included new bectl tool into the FreeBSD base! We now have new member of that ZFS Boot Environment tools family – the bectl tool.

I will of course maintain and update beadm tool and it will still be available in the FreeBSD Ports under sysutils/beadm category as having such tool written in POSIX /bin/sh allows fast debugging and easy changes to such tool. In short (TLDR) the bectl tool is beadm implemented in C language and as it has just been imported into FreeBSD base which means that it will be part of the FreeBSD 12.0-RELEASE. Currently bectl is already available in the 12.0-ALPHA2 image.

Comparison

The new bectl tool is at very early stage and does not (yet) offer full replacement for the beadm tool. Here is quick comparision of the usage information between bectl and beadm tools.

[email protected]:~ # <strong>beadm</strong>
usage:
  beadm activate 
  beadm create [-e nonActiveBe | -e [email protected]] 
  beadm create 
  beadm destroy [-F] 
  beadm list [-a] [-s] [-D] [-H]
  beadm rename  
  beadm mount  [mountpoint]
  beadm { umount | unmount } [-f] 
  beadm version

… and new bectl tool.

[email protected]:~ # <strong>bectl</strong>
missing command
usage:  bectl ( -h | -? | subcommand [args...] )
        bectl activate [-t] beName
        bectl create [-e nonActiveBe | -e [email protected]] beName
        bectl create [email protected]
        bectl destroy [-F] beName | [email protected]⟩
        bectl export sourceBe
        bectl import targetBe
        bectl jail [ -o key=value | -u key ]... bootenv
        bectl list [-a] [-D] [-H] [-s]
        bectl mount beName [mountpoint]
        bectl rename origBeName newBeName
        bectl { ujail | unjail } ⟨jailID | jailName | bootenv)
        bectl { umount | unmount } [-f] beName

For example bectl is not able to rename currently used/mounted boot environment while beadm can.

[email protected]:~ # <strong>bectl rename safe new</strong>
boot environment is already mounted
failed to rename bootenv safe to new

Its possible to rename such ZFS dataset mounted as / with zfs rename -u ... command (this is exactly what beadm does under the hood) as a workaround for bectl tool.

[email protected]:~ # <strong>bectl list</strong>
BE      Active Mountpoint Space Created
safe    NR     /          188K  2018-08-18 02:32
default -      -          427M  2018-08-18 02:26

[email protected]:~ # <strong>zfs list | grep safe</strong>
zroot/ROOT/safe      108K  6.85G   427M  /

[email protected]:~ # <strong>zfs rename -u zroot/ROOT/safe zroot/ROOT/new</strong>

Its then listed as usual under new name in bectl as shown below:

[email protected]:~ # <strong>bectl list</strong>
BE      Active Mountpoint Space Created
new     NR     /          188K  2018-08-18 02:32
default -      -          427M  2018-08-18 02:26

One nice addition that bectl has that beadm lacks is dynamic FreeBSD Jail creation in specified boot environment.

Here is bectl FreeBSD Jail creation in action.

[email protected]:~ # <strong>bectl list</strong>
BE      Active Mountpoint Space Created
new     NR     /          188K  2018-08-18 02:32
default -      -          427M  2018-08-18 02:26

[email protected]:~ # <strong>bectl jail default</strong>
# <strong>pwd</strong>
/
# <strong>ls /</strong>
.cshrc          bin             entropy         libexec         net             root            usr
.profile        boot            etc             media           proc            sbin            var
COPYRIGHT       dev             lib             mnt             rescue          tmp             zroot
# <strong>exit</strong>
[email protected]:~ # <strong>jls</strong>
   JID  IP Address      Hostname                      Path
     1                  default                       /tmp/be_mount.OnRc

[email protected]:~ # <strong>mount | grep default</strong>
zroot/ROOT/default on /tmp/be_mount.OnRc (zfs, local, noatime, nfsv4acls)

[email protected]:~ # <strong>bectl unjail default</strong>

[email protected]:~ # <strong>jls</strong>
   JID  IP Address      Hostname                      Path

If you move/migrate to bectl from beadm you will also have to be more careful as bectl does not ask questions

For example beadm tool asks if you are sure that you want to destroy specified boot environment. The bectl tool will just remove it without even writing anything on the screen.

[email protected]:~ # <strong>bectl list</strong>
BE      Active Mountpoint Space Created
new     NR     /          188K  2018-08-18 02:32
default -      -          427M  2018-08-18 02:26

[email protected]:~ # <strong>beadm destroy safe</strong>
Are you sure you want to destroy 'safe'?
This action cannot be undone (y/[n]): <strong>n</strong>

[email protected]:~ # <strong>bectl destroy safe</strong>

[email protected]:~ # <strong>bectl list</strong>
BE      Active Mountpoint Space Created
new     NR     /          188K  2018-08-18 02:32

One of the things that bectl lacks is also the Ansible plugin, beadm is supported by the Ansible plugin so if you prefer to use that configuration management tool, then bectl will ‘backport’ you to raw Ansible module

The good information is that beadm and bectl can work together on the same host, so you do not have to choose. You may still use beadm tool for daily tasks (or for Ansible module) and bectl for the jail / unjail options for example.

But I think in time bectl will have needed features added and having such tool in FreeBSD base system is a welcome addition.

EOF


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK