I am quite new to using nbd in general. I have written an nbdkit plugin in Rust that I have been using as an nbd server to read from a backing store, and have been using guestfish, a filesystem shell, as my client.
#!/bin/bash -
guestfish --ro --format=raw -a nbd://localhost <<-EOF
run
mount /dev/sda /
mount-local ./data
mount-local-run
EOF
This has been working perfectly well for various filesystem types (xfs, ext2..4, FAT, etc), save for the fact that guestfish's mount commands are quite slow. So I am trying to remove it as a dependency and instead use the native linux nbd-client as a client.
> modprobe nbd
// no output
> sudo nbd-client localhost /dev/nbd0
//successfully connects
> sudo mkdir /mnt/nbd0
> sudo mount /dev/nbd0 /mnt/nbd0
mount: /mnt/nbd0: cannot mount /dev/nbd0 read-only.
I am not sure why this mount command is failing. I don't implement the write callback for nbdkit, so I do expect the files to be read-only, but I don't understand why this causes the mount to fail. I can instead run
sudo mount -o ro,noload /dev/nbd0 /mnt/nbd0
After which what occurs depends on the filesystem of the volume. My filesystem is ext4, for reference.
If the volume has a filesystem type other than ext4: mount: /mnt/nbd0: wrong fs type, bad option, bad superblock on /dev/nbd0, missing codepage or helper program, or other error.
If the volume has filesystem type ext4: the mount succeeds and I can enter directories, move around, etc, but all of the files that I had in the volume are empty. As in, when I mounted with guestfish, I could perform
cat dir0/textFile0.txt
"This is text file 0!"
And now performing the same cat command, or entering the text files with vim, shows that the files are completely empty.
Is this issue being caused by the -o ro,noload argument in the mount command? If so, how can I circumvent the error when trying to mount normally? If not, is there any known cause for such behavior? I know that my nbdkit plugin works because it is completely functional using guestfish, but using nbd-client 1. I am unable to mount anything but ext4 on my filesystem (even when adding -t xfs tag, for instance), and 2. file contents are completely erased.