Mounting
Automount
Automatically mount USB drives on insert using udevil.
# xbps-install udevil
You need to run devmon (a script that detects and mounts hotplugged devices), which is installed with udevil. Do it either by making a user’s service with run containing:
#!/bin/sh
exec devmon
or launch it in ~/.xinitrc
devmon &
I use it like this to display notification (with herbe, but you can use something else) that the drive is mounted:
devmon --exec-on-drive "herbe \"Mount %l %f to %d\""
- exec-on-drive: execute command after drive mount
But my drives weren’t automatically mounting. I looked for errors using:
# dmesg | tail
and found:
ntfs: Unknown parameter 'utf8'
In /etc/udevil/udevil.conf on line with default_options_ntfs I changed utf8 to iocharset=utf8:
default_options_ntfs = nosuid, noexec, nodev, noatime, fmask=0133, uid=$UID, gid=$GID, iocharset=utf8
Network mounts
I add to /etc/fstab things that I am mounting repeatedly. Using noauto option so they are not mounted automatically.
When I want to mount them:
$ mount /mnt/server1/path1
Windows samba share
# xbps-install cifs-utils
In /etc/fstab:
//i.p.address/path /mnt/server1/path1 cifs noauto,rw,credentials=/path/to/credentials,uid=1000,gid=1000,domain=your.windows.domain,user,_netdev 0 0
- credentials: file with information for authentication to the server in following format:
username=youruser
password=yourpass
let no one read it:
$ chmod 600 /path/to/credentials
- uid,gid: user and group that will be assigned ownership of mounted files, find out yours:
$ id -u
1000
$ id -g
1000
- domain: windows domain, active directory realm, omit if you are not using it
- user: let user other than root to mount
- _netdev: the filesystem is network-dependent
If you have troubles with permissions, look into:
- nounix: disable the CIFS Unix Extensions
- dir_mode=0777,file_mode=0666: default permissions for folders and files
Make mountpoint:
# mkdir -p /mnt/server1/path1
User that will do the mounting does not need to have permission to this folder.
SSH file system
# xbps-install fuse-sshfs
In /etc/fstab:
user@domain:/path/on/server /mnt/server2/path1 fuse.sshfs noauto,rw,user 0 0
Make mountpoint:
# mkdir -p /mnt/server2/path1
User that will do the mounting needs to have write access to this folder, accomplished here by using the group wheel:
# chown root:wheel /mnt/server2/path1
# chmod g+w /mnt/server2/path1
Copy ~/.ssh folder or important data from it from your old machine.
Unmouting on shutdown
During shutdown, the network goes down and then unmounting the remote mounts hangs, because the servers have become unreachable.
Create a file /etc/runit/shutdown.d/08-umount.sh with following contents to lazily unmount all of type cifs,fuse.sshfs:
#!/bin/sh
umount -lat cifs,fuse.sshfs
- -l: Man says: “Lazy unmount. Detach the filesystem from the file hierarchy now, and clean up all references to this filesystem as soon as it is not busy anymore. A system reboot would be expected in near future if you’re going to use this option for network filesystem or local filesystem with submounts. The recommended use-case for umount -l is to prevent hangs on shutdown due to an unreachable network share where a normal umount will hang due to a downed server or a network partition. Remounts of the share will not be possible”
- -a: all
- -t: the actions should only be taken on filesystems of the specified type
Umount also has an option -f: Man says: “Force an unmount (in case of an unreachable NFSsystem). Note that this option does not guarantee that umount command does not hang.”