How to mount NFS volume via preseed

I need to have instantiated instances automatically add an entry for NFS to /etc/fstab; auto-mounting is not necessary but OK. I’m using a custom Ubuntu image. In /etc/maas/preseeds/curtin_userdata_custom I have en entry looks like (sensitive information removed):

mounts:
  - ["00.00.00.00:/path", "/mnt/nfs", "nfs", "auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid", "0", "0"]

When I set trace to true and verbosity to 3 (https://gist.github.com/smoser/2610e9b78b8d7b54319675d9e3986a1b) and check the config and node results, I see the following in the config (Getting curtin debug logs):

...
mounts:
- - 00.00.00.00:/path
  - /mnt/nfs
  - nfs
  - auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid
  - '0'
  - '0'
network:...

The node results show nothing with respect to nfs other than nfs packages getting installed.

When I check the system, no entry is added to /etc/fstab. No errors show in /var/log/cloud-init.log or /var/log/cloud-init-output.log

For grins and giggles, I grep -i for nfs recursively in /var/lib/cloud and there are no references to nfs there at all.

I’ve also attempted using runcmd in the preseed file. That also doesn’t work.

Any assistance on this would be greatly appreciated.

Hi,

The curtin preseed provides config to curtin (the installer) not to cloud-init; The config you’re specifying is for cloud-init. curtin does not support ‘mounts’ like you’ve defined. The set of top-level config keys curtin supports is here:

https://curtin.readthedocs.io/en/latest/topics/config.html

For curtin to mount things during the install (and in the target) you will need to add entries to the
‘storage’ config provided, specifically a ‘type: mount’ entry

https://curtin.readthedocs.io/en/latest/topics/storage.html#mount-command

I’ve not tested an ‘nfs’ mount before, but this is the format curtin would accept, it would need to be added to the storage config list.

- id: nfs1
  fstype: "none"
  options: "auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid"
  path: "/mnt/nfs"
  spec: "00.00.00.00:/path"
  freq: "0"
  passno: "0"
  type: mount

This would generate the following entry in /etc/fstab

# /mnt/nfs was on 00.00.00.00:/path during curtin installation
00.00.00.00:/path /mnt/nfs nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid 0 0

I would suggest that you add ‘_netdev’ to the options list, as this tells systemd that the mount point requires networking to be up. It may already do that for fstab ‘spec’ entries which look like IP or hostnames, but just in case, we add ‘_netdev’ when mounting iscsi volumes.

If you instead would like to have cloud-init issue this mount on first boot, you need to
have curtin write out cloud-config file to the target system like so:

write_files:
  nfsmnt:
     - path: /etc/cloud/cloud.cfg.d/99-nfs-mount.cfg
       content: |
         #cloud-config
         mounts:  
           - ["00.00.00.00:/path", "/mnt/nfs", "nfs", "auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid", "0", "0"]
1 Like

Thank you for your reply @raharper.

So, I’ve tested the curtin method for this topic. It fails because mount.nfs doesn’t exist. I will re-test and see if I can grab logs for posterity. This could be a cool feature for the future if I’m right.

Let’s also install ‘nfs-common’ during the install as well:

late_commands:
  99_install_package_nfs: [curtin, in-target, --, apt-get, install, --assume-yes, nfs-common]
write_files:
  nfsmnt:
     - path: /etc/cloud/cloud.cfg.d/99-nfs-mount.cfg
       content: |
         #cloud-config
         mounts:  
           - ["00.00.00.00:/path", "/mnt/nfs", "nfs", "auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid", "0", "0"]

1 Like

Yeah. That would be necessary. Here are the logs for posterity sake:

start: cmd-install/stage-partitioning/builtin/cmd-block-meta: configuring mount: srdnfs
Running command ['mount', '-o', 'auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid', '00.00.00.00:/path', '/tmp/tmp3i5k9x3y/target/mnt/nfs'] with allowed return codes [0] (capture=True)
Unexpected error while running command.
Command: ['mount', '-o', 'auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid', '00.00.00.00:/path', '/tmp/tmp3i5k9x3y/target/mnt/nfs']
Exit code: 32
Reason: -
Stdout: ''
Stderr: mount: /tmp/tmp3i5k9x3y/target/mnt/nfs: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program.

Traceback (most recent call last):
  File "/curtin/curtin/commands/block_meta.py", line 1006, in mount_fstab_data
    util.subp(mcmd, capture=True)
  File "/curtin/curtin/util.py", line 275, in subp
    return _subp(*args, **kwargs)
  File "/curtin/curtin/util.py", line 141, in _subp
    cmd=args)
curtin.util.ProcessExecutionError: Unexpected error while running command.
Command: ['mount', '-o', 'auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid', '00.00.00.00:/path', '/tmp/tmp3i5k9x3y/target/mnt/nfs']
Exit code: 32
Reason: -
Stdout: ''
Stderr: mount: /tmp/tmp3i5k9x3y/target/mnt/nfs: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program.

Mount failed: 00.00.00.00:/path @ /tmp/tmp3i5k9x3y/target/mnt/nfs with options auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid
An error occured handling 'srdnfs': RuntimeError - Mount failed: 00.00.00.00:/path @ /tmp/tmp3i5k9x3y/target/mnt/nfs with options auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid
finish: cmd-install/stage-partitioning/builtin/cmd-block-meta: FAIL: configuring mount: srdnfs
TIMED BLOCK_META: 0.182
finish: cmd-install/stage-partitioning/builtin/cmd-block-meta: FAIL: curtin command block-meta
Traceback (most recent call last):
  File "/curtin/curtin/commands/block_meta.py", line 1006, in mount_fstab_data
    util.subp(mcmd, capture=True)
  File "/curtin/curtin/util.py", line 275, in subp
    return _subp(*args, **kwargs)
  File "/curtin/curtin/util.py", line 141, in _subp
    cmd=args)
curtin.util.ProcessExecutionError: Unexpected error while running command.
Command: ['mount', '-o', 'auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid', '00.00.00.00:/path', '/tmp/tmp3i5k9x3y/target/mnt/nfs']
Exit code: 32
Reason: -
Stdout: ''
Stderr: mount: /tmp/tmp3i5k9x3y/target/mnt/nfs: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program.


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/curtin/curtin/commands/main.py", line 202, in main
    ret = args.func(args)
  File "/curtin/curtin/log.py", line 97, in wrapper
    return log_time("TIMED %s: " % msg, func, *args, **kwargs)
  File "/curtin/curtin/log.py", line 79, in log_time
    return func(*args, **kwargs)
  File "/curtin/curtin/commands/block_meta.py", line 88, in block_meta
    return meta_custom(args)
  File "/curtin/curtin/commands/block_meta.py", line 1786, in meta_custom
    handler(command, storage_config_dict)
  File "/curtin/curtin/commands/block_meta.py", line 1041, in mount_handler
    target=state.get('target'), fstab=state.get('fstab'))
  File "/curtin/curtin/commands/block_meta.py", line 1016, in mount_apply
    mount_fstab_data(fdata, target=target)
  File "/curtin/curtin/commands/block_meta.py", line 1011, in mount_fstab_data
    raise RuntimeError(msg)
RuntimeError: Mount failed: 00.00.00.00:/path @ /tmp/tmp3i5k9x3y/target/mnt/nfs with options auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid
Mount failed: 00.00.00.00:/path @ /tmp/tmp3i5k9x3y/target/mnt/nfs with options auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid
curtin: Installation failed with exception: Unexpected error while running command.
Command: ['curtin', 'block-meta', 'custom']
Exit code: 3
Reason: -
Stdout: start: cmd-install/stage-partitioning/builtin/cmd-block-meta: curtin command block-meta
        Declared block devices: []
        start: cmd-install/stage-partitioning/builtin/cmd-block-meta/clear-holders: removing previous storage devices
        Running command ['mdadm', '--assemble', '--scan', '-v'] with allowed return codes [0, 1, 2] (capture=True)
        mdadm assemble scan results:

        mdadm: looking for devices for further assembly
        mdadm: no recogniseable superblock on /dev/dm-0
        mdadm: no recogniseable superblock on /dev/sdd
        mdadm: no recogniseable superblock on /dev/sdc
        mdadm: no recogniseable superblock on /dev/sdb
        mdadm: no recogniseable superblock on /dev/sda1
        mdadm: Cannot assemble mbr metadata on /dev/sda
        mdadm: no recogniseable superblock on /dev/loop0
        mdadm: No arrays found in config file or automatically

        Running command ['mdadm', '--detail', '--scan', '-v'] with allowed return codes [0, 1] (capture=True)
        mdadm detail scan after assemble:


        Running command ['udevadm', 'settle'] with allowed return codes [0] (capture=False)
        TIMED udevadm_settle(): 0.009
        Running command ['pvscan', '--cache'] with allowed return codes [0] (capture=True)
        Running command ['vgscan', '--mknodes', '--cache'] with allowed return codes [0] (capture=True)
        Running command ['vgchange', '--activate=y'] with allowed return codes [0] (capture=True)
          1 logical volume(s) in volume group "vgroot" now active

        Loading kernel module bcache via modprobe
        Running command ['modprobe', '--use-blacklist', 'bcache'] with allowed return codes [0] (capture=False)
        Current device storage tree:

        Shutdown Plan:

        finish: cmd-install/stage-partitioning/builtin/cmd-block-meta/clear-holders: SUCCESS: removing previous storage devices
        blockmeta: detected storage config, using mode=custom
        start: cmd-install/stage-partitioning/builtin/cmd-block-meta: configuring mount: srdnfs
        Running command ['mount', '-o', 'auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid', '00.00.00.00:/path', '/tmp/tmp3i5k9x3y/target/mnt/nfs'] with allowed return codes [0] (capture=True)
        Unexpected error while running command.
        Command: ['mount', '-o', 'auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid', '00.00.00.00:/path', '/tmp/tmp3i5k9x3y/target/mnt/nfs']
        Exit code: 32
        Reason: -
        Stdout: ''
        Stderr: mount: /tmp/tmp3i5k9x3y/target/mnt/nfs: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program.

        Traceback (most recent call last):
          File "/curtin/curtin/commands/block_meta.py", line 1006, in mount_fstab_data
            util.subp(mcmd, capture=True)
          File "/curtin/curtin/util.py", line 275, in subp
            return _subp(*args, **kwargs)
          File "/curtin/curtin/util.py", line 141, in _subp
            cmd=args)
        curtin.util.ProcessExecutionError: Unexpected error while running command.
        Command: ['mount', '-o', 'auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid', '00.00.00.00:/path', '/tmp/tmp3i5k9x3y/target/mnt/nfs']
        Exit code: 32
        Reason: -
        Stdout: ''
        Stderr: mount: /tmp/tmp3i5k9x3y/target/mnt/nfs: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program.

        Mount failed: 00.00.00.00:/path @ /tmp/tmp3i5k9x3y/target/mnt/nfs with options auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid
        An error occured handling 'srdnfs': RuntimeError - Mount failed: 00.00.00.00:/path @ /tmp/tmp3i5k9x3y/target/mnt/nfs with options auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid
        finish: cmd-install/stage-partitioning/builtin/cmd-block-meta: FAIL: configuring mount: srdnfs
        TIMED BLOCK_META: 0.182
        finish: cmd-install/stage-partitioning/builtin/cmd-block-meta: FAIL: curtin command block-meta
:
        Traceback (most recent call last):
          File "/curtin/curtin/commands/block_meta.py", line 1006, in mount_fstab_data
            util.subp(mcmd, capture=True)
          File "/curtin/curtin/util.py", line 275, in subp
            return _subp(*args, **kwargs)
          File "/curtin/curtin/util.py", line 141, in _subp
            cmd=args)
        curtin.util.ProcessExecutionError: Unexpected error while running command.
        Command: ['mount', '-o', 'auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid', '00.00.00.00:/path', '/tmp/tmp3i5k9x3y/target/mnt/nfs']
        Exit code: 32
        Reason: -
        Stdout: ''
        Stderr: mount: /tmp/tmp3i5k9x3y/target/mnt/nfs: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program.


        During handling of the above exception, another exception occurred:

        Traceback (most recent call last):
          File "/curtin/curtin/commands/main.py", line 202, in main
            ret = args.func(args)
          File "/curtin/curtin/log.py", line 97, in wrapper
            return log_time("TIMED %s: " % msg, func, *args, **kwargs)
          File "/curtin/curtin/log.py", line 79, in log_time
            return func(*args, **kwargs)
          File "/curtin/curtin/commands/block_meta.py", line 88, in block_meta
            return meta_custom(args)
          File "/curtin/curtin/commands/block_meta.py", line 1786, in meta_custom
            handler(command, storage_config_dict)
          File "/curtin/curtin/commands/block_meta.py", line 1041, in mount_handler
            target=state.get('target'), fstab=state.get('fstab'))
          File "/curtin/curtin/commands/block_meta.py", line 1016, in mount_apply
            mount_fstab_data(fdata, target=target)
          File "/curtin/curtin/commands/block_meta.py", line 1011, in mount_fstab_data
            raise RuntimeError(msg)
        RuntimeError: Mount failed: 00.00.00.00:/path @ /tmp/tmp3i5k9x3y/target/mnt/nfs with options auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid
        Mount failed: 00.00.00.00:/path @ /tmp/tmp3i5k9x3y/target/mnt/nfs with options auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,user,suid

Stderr: ''