nbdkit-client - how to mount NBD filesystems on a client machine
For NBD exports that contain filesystems there are several approaches to mounting them on a client machine.
To ensure the nbd kernel module is loaded you may need to do:
# echo nbd > /etc/modules-load.d/nbd.conf
This will not take effect until you reboot, so also do:
# modprobe nbd
For simple setups the following method is the easiest way to get an NBD filesystem to mount at boot. Create or edit /etc/rc.local or /etc/rc.d/rc.local:
#!/bin/sh -
nm-online
modprobe nbd
nbd-client server /dev/nbd0
mount /dev/nbd0 /mnt
You can use systemd mount points to mount NBD filesystems at boot and/or on demand.
Set up an nbdtab(5) mapping. If /etc/nbdtab doesn't exist, then create it first. Add this line:
nbd0 server / bs=512,persist
As a workaround for NetworkBlockDevice/nbd#91 you must currently modify the [email protected] file:
# cp /usr/lib/systemd/system/[email protected] /etc/systemd/system/
# vi /etc/systemd/system/[email protected]
and edit or create these settings in the [Service]
section:
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/nbd-client %i
ExecStop=/usr/sbin/nbd-client -d /dev/%i
Finally create a systemd mount file called /etc/systemd/system/mnt.mount:
[Unit]
[email protected]
[Mount]
What=/dev/nbd0
Where=/mnt
Type=ext4
You can either reboot now or do:
# systemctl start mnt.mount
Other systemd services which need this mount point can depend on this mount unit.
nbdkit(1), nbdkit-loop(1), nbdkit-service(1), nbd-client(8), nbdtab(5), systemd(1), systemd.mount(5).
Richard W.M. Jones
Copyright (C) 2013-2020 Red Hat Inc.