NFS
Sick of network mounts that fail and grip your VMs? Then you can follow these tips:
nfs-client or cif-client
Particularly useful for Remote filesystem or detachable drives, you really on want them mounted upon access, so what you want to do is use the noauto,x-systemd.automount parameters. In addition, you can use the x-systemd.mount-timeout= option to specify how long systemd should wait for the mount command to finish. Also, the _netdev option ensures systemd understands when that the mount is network dependent and order it after the network is online.
- include these options instead of default on your /etc/fstab
noauto,x-systemd.automount,x-systemd.mount-timeout=30,_netdev
- also include as appropriate
,rw,suid,dev,exec,nouser,async
now to stop your nfs-server crashing on a bad export
If you have an invalid line in /etc/exports then by default your nfs-server will not start
# cat /etc/exports /virtual/shared 192.168.122.0/24(rw,no_root_squash,subtree_check) /mnt/SSD 192.168.122.0/24(rw,no_root_squash,subtree_check) /mnt/junk 192.168.122.0/24(rw,no_root_squash,subtree_check)
- so this will fail
systemctl restart nfs-server; systemctl status nfs-server
● nfs-server.service - NFS server and services Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Wed 2020-07-29 15:45:36 AEST; 1min 4s ago Process: 23060 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=1/FAILURE) Process: 23061 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS) Process: 23062 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS) Jul 29 15:45:36 c3po2 systemd[1]: Starting NFS server and services... Jul 29 15:45:36 c3po2 exportfs[23060]: exportfs: Failed to stat /mnt/junk: No such file or directory Jul 29 15:45:36 c3po2 systemd[1]: nfs-server.service: Control process exited, code=exited, status=1/FAILURE Jul 29 15:45:36 c3po2 systemd[1]: nfs-server.service: Failed with result 'exit-code'. Jul 29 15:45:36 c3po2 systemd[1]: Stopped NFS server and services.
On Debian the nfs-server definition is deployed here:
/lib/systemd/system/nfs-server.service
Since systemd it is a simple matter of ignoring return codes from commands by prefixing the command with a - in the service definition:
[Unit] Description=NFS server and services DefaultDependencies=no Requires=network.target proc-fs-nfsd.mount Requires=nfs-mountd.service Wants=rpcbind.socket Wants=nfs-idmapd.service After=local-fs.target After=network.target proc-fs-nfsd.mount rpcbind.socket nfs-mountd.service After=nfs-idmapd.service rpc-statd.service Before=rpc-statd-notify.service # GSS services dependencies and ordering Wants=auth-rpcgss-module.service After=rpc-gssd.service gssproxy.service rpc-svcgssd.service # start/stop server before/after client Before=remote-fs-pre.target Wants=nfs-config.service After=nfs-config.service [Service] EnvironmentFile=-/run/sysconfig/nfs-utils Type=oneshotq RemainAfterExit=yes ExecStartPre=/usr/sbin/exportfs -r ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS ExecStop=/usr/sbin/rpc.nfsd 0 ExecStopPost=/usr/sbin/exportfs -au ExecStopPost=/usr/sbin/exportfs -f ExecReload=/usr/sbin/exportfs -r [Install] WantedBy=multi-user.target
- So I made the following changes and now my nfs-server survives a bad export definition in the /etc/exports file!
ExecStartPre=-/usr/sbin/exportfs -r ExecStopPost=-/usr/sbin/exportfs -au ExecStopPost=-/usr/sbin/exportfs -f ExecReload=-/usr/sbin/exportfs -r
- restart and view status
systemctl restart nfs-server; systemctl status nfs-server
- and it no longer fails to start
sudo systemctl status nfs-server
● nfs-server.service - NFS server and services Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled) Active: active (exited) since Wed 2020-07-29 15:47:15 AEST; 16min ago Process: 23252 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=1/FAILURE) Process: 23253 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS) Main PID: 23253 (code=exited, status=0/SUCCESS) Jul 29 15:47:15 c3po2 systemd[1]: Starting NFS server and services... Jul 29 15:47:15 c3po2 exportfs[23252]: exportfs: Failed to stat /mnt/junk: No such file or directory Jul 29 15:47:15 c3po2 systemd[1]: Started NFS server and services.
samba or cifs mounts
- the package cifs-utils should be installed instead of smbfs.
apt install cifs-utils
- mount via:
mount -t cifs //FILE-SERVER-IP-ADDRESS/public /local/mountpoint -o user=nobody
You will be asked for a password. Confirm the password by pressing the Enter key. The share should now be mounted and ready for reading and writing.
how to move a system mount or folder
So you have a /var mount and it is in a Logical Volume on some Volume Group and you want to move it into another location e.g. into another LVM or part of the file system, what do you do?
Visit existing filesystem if moving to an existing file system, else these other instruction you are dealing with moving to a new Logical Volume.
onto existing file system target
- change to root
su -
- make a folder on the target file system (which might be in a new Logical Volume see #moving to new LV)
mkdir /var.new
- copy the old /var contents over to /newvar
cp -a /var/* /newvar/
- rename the old /var
mv /var /var.old
- rename the /var.new
mv /var.new /var
- verify (there should only be /var/log changes, unless you have prior moved /var/log off via a mount or link)
diff -r /var.new /var
- important fix the fstab
cp /etc/fstab /etc/fstab.date
- now edit /etc/fstab and fix up your mount
vi /etc/fstab
- check that you can mount it
umount /var mount /var ls -lrta /var
- double check rest of fstab
mount -a
- make sure you have no errors otherwise the OS will not reboot
You are done, you may reboot.
moving to new LV
You are here because you want to move /var from a VG Logical Volume to another.
- change to root
su -
- make a new Logical Volume for /var
lvcreate -L 2G -n var /dev/vg
- place a file system on it
mkfs.ext4 /dev/vg/var
- mount the new LV
mkdir /mnt/tmp mount /dev/vg/var /mnt/tmp
- copy the /var over to new LV /var directory
cp -a /var /mnt/tmp
- rename the old /var
mv /var /var.old
- umount the temporary acces
umount /mnt/tmp rmdir /mnt/tmp
- test mount the new LVM
mount /dev/vg/var /var
- fix up fstab
vi /etc/fstab
- test that you have no errors
mount -a
- make sure you have no errors otherwise the OS will not reboot
You are done, you may reboot.
Refer to this https://snott.net/linux/how-to-move-a-system-folder-into-a-newly-created-lvm/
re-mount eject USB
- eject
eject /dev/sdX
- remount
eject -t /dev/sdX
hints
- How to tell where something is mounted?
df <path>