Solved How to mount automatically a zpool before FreeBSD read the swap space on the fstab file.

Hello.

Usually I mount a zpool manually when FreeBSD booted totally with this command :

Code:
# zpool import -f -R /mnt/zroot zroot

but let's say that I want to mount the zroot pool as soon as possible,for sure before that,on fstab,it loads the swap space,this :

Code:
nano /etc/fstab :

md99    none    swap    sw,file=/mnt/zroot/swap0,late    0    0

as you can see,the swap file is called swap0 and it's stored on the zpool. So,the zpool should be imported before that the system is able to read the previous statement.
 
Anyway,are you sure that it will work ? As I said,I know how to import the zpool only when FreeBSD is fully loaded. Using your method seems to have the same problem as before : swapfile="/mnt/zroot/swap0" means that rc.conf will NOT find the zpool mounted when it should look for the swap0 file,because as I said,I import that later.
 
I'm using devuan 5 as host os where I have virtualized freebsd with qemu / kvm. On the host OS I have attached an USB disk that I have added to qemu and shared with the FreeBSD vm. That disk is "formatted" with ZFS. So,FreeBSD is booted by qemu,it's one img file that has UFS as file system.
 
Normally you don't manually import the pool at each boot, once you import a ZFS pool and don't export it, it should be imported after a reboot.
Having
Code:
zfs_enable="YES"
in /etc/rc.conf should ensure that all datasets are mounted.
 
What your suggestion should do ? I've applied it and I've rebooted and then I checked if the zpool zroot-swap had been mounted in /mnt/zroot-swap,but it is not. I should go ahead giving this command manually :

Code:
# zpool import -f -R /mnt/zroot-swap zroot-swap

because the parameter that you have suggested does not work as expected ; it does not import that zpool automatically.
 
Why do you need to do a force import with your zroot-swap pool ?
Why it have an altroot ?
Also when you reboot, does the zroot-swap is imported ?
Imported pool and mounted datasets are not the same, if it does not import at boot then it is an issue with importing. If it does not mount the datasets then it means that
Code:
zfs mount -a
does not works.

When you boot, without manually importing the poll, what is the output of zpool status, and zfs list
 
The zroot-swap pool is connected to this disk :

Code:
Disk /dev/sda: 298.09 GiB, 320072933376 bytes, 625142448 sectors
Disk model: 3200BMV External
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: C1325982-C3AC-11EE-B26E-74D43583CD3F

Device       Start       End   Sectors   Size Type
/dev/sda1       40      1063      1024   512K FreeBSD boot
/dev/sda2     2048   4196351   4194304     2G FreeBSD swap
/dev/sda3  4196352 625141759 620945408 296.1G FreeBSD ZFS

,that I have attached to the netbook via USB and shared it with the FreeBSD vm adding the disk between the qemu parameter :

Code:
qemu-system-arm \
 -enable-kvm -serial stdio \
-m 1024 -M virt -cpu cortex-a15 \
-drive if=pflash,format=raw,unit=0,file=$UEFICODE1 \
-drive if=pflash,format=raw,unit=1,file=$UEFIVARS2 \
-drive file=$DISK,media=disk,format=raw \
----> drive file=/dev/sda,media=disk,format=raw \
-net nic,model=virtio,macaddr=52:54:00:00:00:01 -net bridge,br=br1 \
-device virtio-gpu-pci \
-usb -device nec-usb-xhci \
-device usb-kbd -device usb-mouse \
-device vmware-svga,id=video0,vgamem_mb=16 \

I don't know why it is not mounted automatically during the booting of FreeBSD. I always used -f ; but does not change anything if I use -f or not. It is not imported automatically,but as I said,that disk is recognized and FreeBSD can import it manually.
 
What does zpool status gives as a non root user ?
Also kldstat | grep zfs
Also zpool get cachefile zroot-swap.
Does this pool is imported on another system ?
 
Code:
# zpool import
pool : zpool-swap
id : 7032416720980846619
state : online
zroot-swap : online
vtbd1p3 : online

# zpool get cachefile zroot-swap
cannot open zroot-swap : no such pool

should I import the zpool "zroot-swap" before to give that command ?

----> Does this pool is imported on another system ?

nop.
 
Yes import the pool before doing the zpool get cachefile zroot-swap.
Looking at zpool import, it seems to know about a zpool-swap ?
Also did you at least once imported without the -R option (by using -o altroot=/mnt/zroot-swap)?
Sets the cachefile property to none and the altroot property to root
 
Yes import the pool before doing the zpool get cachefile zroot-swap.
Looking at zpool import, it seems to know about a zpool-swap ?
Also did you at least once imported without the -R option (by using -o altroot=/mnt/zroot-swap)?

Code:
# zpool import -o altroot=/mnt/zroot-swap zroot-swap
# ls /mnt/zroot-swap/zroot-swap
swap0

# zpool get cachefile zroot-swap

NAME = zroot-swap
PROPERTY = cachefile
VALUE = none
SOURCE = local
 
Given the source is local, it is not set as the default.
If you want to have it to mount it needs to be included in /etc/zfs/zpool.cache
You should first fix your mount point issue, you can specify what are the mount point of your root datasets.
Then you export it, import it again without any flags zpool import zroot-swap
Finally, as root
zpool set cachefile=/etc/zfs/zpool.cache zroot-swap
 
As this is VM you can attach a secondary disk, create a swap partition on it and set it in fstab instead of creating a swapfile.
 
During the installation of FreeBSD on the USB disk,the installer created this swap partition :

Code:
/dev/sda2     2048   4196351   4194304     2G FreeBSD swap

What I did has been to declare the disk between the qemu parameters and then I've declared that swap partition on the fstab file of the FreeBSD vm like this :

Code:
/dev/vtdb1p2    none    swap    sw    0    0

It's working.
 
Back
Top