Mount a Zvol under linux
Zvol are volumes backed by a zfs pool. They are quite popular as vm disk images.
Sometimes you just want to examine them in the host; here is how to mount them.
When the pool is imported, they show up under /dev/zvol/<path to zvol dataset>
. At this point they are just raw drives, and kernel knows nothing
about its structure. To be able to mount them, we first need to read its
partition structure and create partition specific /dev/
entires with
kpartx(8)
1.
# -a for add
kpartx -a /dev/zvol/<pathtozvol>
This will create corresponding devices for partitions under /dev/mapper
$:/dev/mapper]# ls -al
total 0
drwxr-xr-x 2 root root 120 Jan 12 17:04 .
drwxr-xr-x 20 root root 3980 Jan 12 17:04 ..
crw------- 1 root root 10, 236 Jan 12 17:00 control
lrwxrwxrwx 1 root root 7 Jan 12 17:04 root-zvol1 -> ../dm-0
lrwxrwxrwx 1 root root 7 Jan 12 17:04 root-zvol2 -> ../dm-1
lrwxrwxrwx 1 root root 7 Jan 12 17:04 root-zvol3 -> ../dm-2
Now you can mount them as a regular disk with mount
.
mount /dev/mapper/root-zvol1 /mnt
In nixos,
kpartx
is part of packagemultipath-tools
↩︎