[Nix-dev] [PATCH] Root filesystem on NFS

Rickard Nilsson rickard.nilsson at telia.com
Mon Aug 29 11:01:08 CEST 2011


 Hi Nicolas,

 On Sun, 28 Aug 2011 01:13:30 +0200, Nicolas Pierron 
 <nicolas.b.pierron at gmail.com> wrote:
> Hi Rickard,
>
> On Sat, Aug 27, 2011 at 13:05, Rickard Nilsson
> <rickard.nilsson at telia.com> wrote:
>> The only way I have managed to get root fs on NFS to work in NixOS 
>> is by
>> using the "nfsmount" program from klibc. The following patch works 
>> fine for
>> me, but since I'm new to NixOS I'm open for any changes:
>
> I am happy to see new users willing to share their configuration.
>
>>
>> Index: modules/system/boot/stage-1.nix
>> ===================================================================
>> --- modules/system/boot/stage-1.nix     (revision 28845)
>> +++ modules/system/boot/stage-1.nix     (working copy)
>> @@ -169,6 +169,10 @@
>>         cp
>> 
>> ${kernelPackages.splashutils}/${kernelPackages.splashutils.helperName}
>> $out/bin/splash_helper
>>       ''}
>>
>> +      # Copy nfsmount
>> +      # TODO: Maybe only do this if there is a nfs mount point 
>> defined?
>
> Sure, we don't want to pollute other user environment:
>
> ${if fileSystems != [] && filter (fs.fsType == "nfs") fileSystems 
> then ''
>
>> +      cp -v ${pkgs.klibc}/lib/klibc/bin.static/nfsmount $out/bin
>
> '' else ""}
>
>> +
>>       ${config.boot.initrd.extraUtilsCommands}
>>
>>       # Run patchelf to make the programs refer to the copied 
>> libraries.
>>
>>
>
>
>> By applying this patch, the following root device specification in
>> configuration.nix works perfectly for me:
>>
>>  fileSystems = [
>>    { mountPoint = "/";
>>      fsType = "nfs";
>>      device = "192.168.42.1:/export/nixos_root";
>>    }
>>  ];
>>
>>
>> However, you of course also need to get the network up before 
>> mounting the
>> root fs. I have solved this in the following way directly in
>> configuration.nix, but I would really appreciate any suggestions on 
>> how to
>> solve it more generally in the NixOS repository, so I could write a 
>> proper
>> patch for it:
>>
>>  boot.initrd.extraUtilsCommands =
>>    ''
>>      cp ${pkgs.iproute}/sbin/ip $out/bin
>>      cp ${pkgs.glibc}/lib/libresolv.so.* $out/lib
>>    '';
>
> This is ok.
>
>>  boot.initrd.postDeviceCommands =
>>    ''
>>      ip link set eth0 up
>>      ip addr add 192.168.42.200/24 dev eth0
>>    '';
>
> But we probably don't want to hard write this one, best would be to
> take into account the networking user configuration.  Such things
> could be done by extracting the jobs.dhclient script and giving it as
> argument of boot.initrd.postDeviceCommands, but this has never been
> experimented before.
>
>>  # This is necessary, otherwise upstart will tear
>>  # down the network connection and the root fs will stop working.
>>  networking.useDHCP = false;
>
> This should not be necessary if you reused the upstart jobs content 
> to
> write the init script.  Otherwise, if another definition gives you
> trouble you can still use mkOverride to force it to another value.

 I will look into getting DHCP working during init. It is something I 
 have been thinking of already. Thanks for the hint about the upstart 
 jobs. Ideally I would like to adjust the existing network configuration 
 in NixOS to support the possibility to bring up the network before the 
 root mounting. That way the user wouldn't have to do anything else then 
 activate "networking.earlyInit = true" or something like that. And it 
 could even be done automatically if you had a cifs or nfs root.


> If you are searching option declarations / definitions, use
> "nixos-option -l option.name" to locate it.

 Thanks for the tip, I wasn't aware of nixos-option.

 
> Thanks for your interest in NixOS.
> Feel free to contribute, I'll take pleasure to review your patches.

 I will polish the nfsmount patch a bit and then submit it again. The 
 network stuff will require some more work before being patch-worthy.


 Best regards,
   Rickard Nilsson



More information about the nix-dev mailing list