thesandmantoo
Posts: 3
Joined: Sat Jan 27, 2018 7:46 pm

nfs root in img-file

Sat Jan 27, 2018 7:57 pm

Hi,

Hopefully some nfs expert here can help me on this topic:

I'm trying to make raspbian on a raspberry pi3 boot to a NFS root. The problem seems to be that the root filesystem is on an img-file on a NAS (yes, in my use-case I do need it to be a file). The file was constructed from the raspbian installer by instructions at https://cellux.github.io/articles/moving-to-nfs-root/ and it can be mounted fine from another linux machine. My cmdline.txt looks like this:

Code: Select all

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/nfs rootfstype=ext4 elevator=deadline nfsroot=192.168.0.74:/i-data/c6db3422/nfs/linuxfs/skynet201801.img ip=dhcp elevator=deadline rootwait
It seems like the problem is that after the image file is mounted over NFS it should then be mounted as a loopback device as root. Can anyone verify this, and is there any way around it?

epoch1970
Posts: 1655
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: nfs root in img-file

Sun Jan 28, 2018 6:56 pm

Can't you loop-mount that image on the NFS server and export that directory instead?
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

thesandmantoo
Posts: 3
Joined: Sat Jan 27, 2018 7:46 pm

Re: nfs root in img-file

Mon Feb 05, 2018 4:33 pm

unfortunately I don't have such control over the NAS :/

epoch1970
Posts: 1655
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: nfs root in img-file

Mon Feb 05, 2018 9:54 pm

Then I think you're good for an init script (like this --psuter doesn't seem to be around),
or for a custom initramfs (like that --ejolson is around these parts, I think).

My idea is: run a script very early that does fetch the image file over the NFS export, loop-mount it and continue booting over "root=/dev/mapper/loop0p0" or something like that.
I expect you can pass "foo=bar" parameters in cmdline.txt and parse /proc/cmdline from your script(s) if you want a little flexibility, e.g. to specify the image name, nfs server address...

Could be rubbish. But I don't think you can use "nfsroot=" with an image just like that.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

thesandmantoo
Posts: 3
Joined: Sat Jan 27, 2018 7:46 pm

Re: nfs root in img-file

Tue Feb 13, 2018 10:33 am

Thanks for your reply, epoch1970. That would not work as (I forgot to mention), I want to read/write against the filesystem on the nas (and not in RAM). This because I want to be able to have the NAS take backups by just copying the img-file. I actually ended up unpacking the filesystem on the nas, running nfs against that filesystem and having the NAS tarring and gzipping the files when backing up.

User avatar
PeterO
Posts: 4167
Joined: Sun Jul 22, 2012 4:14 pm

Re: nfs root in img-file

Tue Feb 13, 2018 10:54 am

I don't think you're going to be able to do this without extracting the file systems from the image file first and copying the files onto the NAS.

There may be more than one way to do this but I would do it like this ......

Use kpartx (you'll have to install it first I expect) to make the partitions in the image file appear as block devices in /dev/mapper

I use "sudo kpartx -a -v uncompressed-rasbian-image-file.img" which creates two mountable devices in /dev/mapper

Then you will have to copy the files from there onto the NAS in such a way that they can be mounted onto the PI.
(I don't have a NAS, but I do use a MINT desktop as a NFS file server).

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “Networking and servers”

Who is online

Users browsing this forum: No registered users and 7 guests