(zfs single user primer) dual booting with a ZFS volume floating between them

in #computers3 years ago (edited)

Why? Because I can. I've been playing around with computers for since the 80s. I've always been fascinated with telling it what to do and having it respond. And the idea that I could code something that could be used again and again..

This beautiful idea, to use again and again, has lead me to be poor in the face of great wealth that could be had would I just sell out and sit in and office and code away somewhere.

i see nothing here matters, but i've always strived to see it done my way..

what is my way? well, the right way of course!

it is the best that I can do, given what I have to offer

Recently I've fell in favor of using ZFS. I do not use it in all its glory, as a multi-disk raid complex of 20 disks.. but it has that ability.. to combine all that into just 1 apparent disk. Then you can use that one disk, and have disks fail within that raid and replace them, on-the-fly. all sorts of cool stuff.

it can also be read by everyone. even windows. but I think you gotta pay for it there, standard addition won't cut it. but linux, BSDs, mac os.. all read it.

and surprisingly.. it is one the ONLY FORMAT shared by LINUX and BSD

yes. I thought sharing would be easy. but the BSD guys see no reason implement ext3/ext4 apparently.

so, to talk to your old linux disks, requires an old linux machine with a network connection. oddly enough linux has fallen away as a reason to use it. I simply have it now.. and enjoy it. Its purpose as a utility disk to be used between systems has been realized on all levels. its (zfs) entire potentially has not at all been explored, as you can include so many options upon each directory you setup .. quotas, compression.. all sorts of fun stuff.

here what I actually use...

zpool create bridge /dev/ada3

i think i did all of the setup in netBSD as it had the oldest version.

ZFS is built to be backward compatible. (not forward, unfortunately)

if you use features that don't exist in the old version, it becomes incompatible


SIDENOTE: this is really cool...

c. Using files

We can also create a zpool with files. Make sure you give an absolute path while creating a zpool

mkfile 100m file1
zpool create geekpool /file1
zpool list
NAME       SIZE  ALLOC   FREE    CAP  HEALTH  ALTROOT
geekpool  95.5M   115K  95.4M     0%  ONLINE  -

source
/SIDENOTE: end


after creating the pool... well now what? the pool is just there, waiting to be used

how do you use it?

by creating mountpoints .. I start from scratch..

zpool create bridge /dev/ada3
zpool create bridge/home mountpoint=none
zpool create bridge/home/Downloads mountpoint=/home/me/Downloads
zpool create bridge/home/Pictures mountpoint=/home/me/Pictures
zpool create bridge/home/storage mountpoint=/home/me/storage
zpool create bridge/netbsd/src mountpoint=/usr
zpool create bridge/netbsd/pkgsrc mountpoint=/usr/pkgsrc
zpool create bridge/netbsd/xsrc mountpoint=/usr/xsrc


by giving home the mountpoint=none, I have allowed the majority of my home folder to reside on the native disk.

this setup is on NetBSD. and because of the /usr stuff (I never planned to share it this way) .. I had to move the root when I imported it onto freeBSD

did you know you use import and export .. to 'load' and 'unload' a pool from ZFS?

yeah, that took a second for me to figure out. why ya'll gotta use words in ways i didn't expect.. anyway that is what import and export means.. to load and unload the filesystem

and ZFS does not like to be loaded if it wasn't unloaded properly from the 'previous owner' .

you can only unload it properly explicitly, shutting down the system does not do it

first I figure out I could force it to load it

zpool import -f bridge

i became very fast at doing this

Login:me
Password: **********************************
[superAwesomePrompt^^^^] su
Password: **************************************
[evenBetterPrompt$$#@!! zpool import -f bridge
[evenBetterPrompt$$#@!! exit
[superAwesomePrompt^^^^] startx

since it had... 'become a thing' .. i didn't want to repeat myself

so I noticed cron, and dropped it in there

@reboot   root   /root/importBridge



@reboot is a neat command, it runs at startup time. there is no shutdown. that is something that is a bit of a hack that I did.. that I'll show you later on.


importBridge was a simple command

#!/bin/sh
logger -p kern.notice "Importing bridgeZFS"
set r=`zpool import bridge -R /mnt/bridge -f`
logger -p kern.notice "importBridge>>$r<<DONE"

the logger was fun to play with, by adding the -p kern.notice I was able to get it into the

dmesg -a

dmesg wasn't necessary, but nice way to make sure things are working.

the '-R' (root) part of the import command.. is really nice find for someone using ZFS more as a portable medium than a system disk. (tho it has become the system disk that I am now using, with FreeBSD, it has 'just worked' so I am ok with that)

-R /mnt/bridge

-R is 'set root' .. forces the root here and doesn't 'overwrite' my /usr folder upon importing. it doesn't overwrite things, but it does cause some weirdness and unpredictable behavior (it will hide things until unmounted, but not exactly sure what prescribed behavior is.. think NOT SUPPOSE TO DO IT) Yes, i have done it. at first, i had forgotten that /usr was part of my bridgeZFS .. I was reminded when I found some netBSD files. I suppose I might have overwritten something there .. let us hope they are ok.

so after setting the root, everything is mounted inside that root. I then used 'ln -s' to link all the folders like

ln -s /mnt/bridgeZFS/home/me/Downloads /home/me/Downloads
ln -s /mnt/bridgeZFS/home/me/Pictures /home/me/Pictures
ln -s /mnt/bridgeZFS/home/me/storage /home/me/storage

to fix the -f from being necessary.. was first started with an rc.d script

#!/bin/sh

# PROVIDE: bridgeZFS
# REQUIRE: zfs
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable the bridgeZFS:
#
# bridgeZFS_enable="YES"
#

. /etc/rc.subr

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

name="bridgeZFS"
rcvar="bridgeZFS_enable"
start_cmd="${name}_start"
stop_cmd="${name}_stop"

bridgeZFS_start()
{
        /root/bin/importBridge
}
bridgeZFS_stop()
{
        /root/bin/exportBridge
}
load_rc_config $name
: ${bridgeZFS_enable=NO}
run_rc_command "$1"

I wanted this to work, but it would only run at startup, and since importBridge didn't continue running, it wasn't thought necessary to run shutdown on it. at least that is my conclusion... as exportBridge worked when called directly, and bridgeZFS worked if asked to stop using exportBridge. but upon shutdown none of these things happened.

/root/bin/exportBridge


#!/bin/sh
echo "Exporting bridgeZFS"
set r=`zpool export bridge`
logger -p kern.notice "exportBridge>>$r<<DONE"

What I found is that by adding exportBridge to the /etc/rc.shutdown .. I can get the job done. But it is not a good answer. But one that works for the moment. The answer may be keep importBridge alive until the end.

Using the -R option does not require exporting upon completion, I don't think.

so only netBSD is required to export it and use that 'horrible' hack.

the horror comes 6 months from now and I upgrade and can't figure out how I did it .. and given its location.. will never find it again. unless I look here! wouldn't that be nice.

#pob and #vyb