0

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.

zdh5
  • 1
  • 1
  • why not use the readonly option for nbdclient? you can also try `-o loop,ro` utilizing the loop device is another layer that enforces readonly-ness. it may also be that nbdclient tries to use another feature not implemented by your server, what happens if you try with the regular nbd server? – frostschutz Aug 11 '22 at 19:02
  • @frostschutz It doesn't seem like adding the `-readonly` tag to the nbd-client changes anything unfortunately. I tried `-o ro,loop` and that returned `mount: /mnt/nbd0: cannot mount /dev/loop0 read-only.` I haven't tried connecting to nbd-client via nbd-server yet but I'll check that out and report back (I can't use nbd-server for my needs but it might tell us something anyway) – zdh5 Aug 11 '22 at 19:37
  • @frostschutz I followed the steps here unix.stackexchange.com/questions/658076/cannot-get-nbd-to-work to serve an xfs .img file with some test files on it and it successfully mounted. I was able to access all of the files, etc. I also served the same .img file using `nbdkit file <.img file>` (which is a provided nbdkit plugin) and was able to view the files normally. – zdh5 Aug 11 '22 at 20:36

0 Answers0