When using the
mount utility, if you specify a directory that does not exist, that is considered an error. Is there any option I can use so that mount points get automatically created if they don't already exist?
When using the
Install the pmount utility and let it handle /media/user/ mount points automatically. No more worries about how and where /media/user/ devices mount and by which names.
sudo apt-get update sudo apt-get install pmount
Then whenever you insert a removable device, it will automatically be mounted under /media/username/, by name.
For example: My USB stick is named "SYSBKP" so it automatically mounts as
It also handles unexpected ejects. And remounts. Silently.
- Generally, it will pop up file manager to show you what you just mounted.
Behind the scenes it makes sure the buffers are always flushed just in case the USB is pulled without warning. No more need for sync;sync;sync like the old days.
FYI, I installed from a 14.04 LTS disk and let it upgrade me to 16.04 LTS when it offered. On a fresh SSD drive - I let it take the entire space.
In any case, pmount is a very important piece of software to have if you use
/media/username/ for removable devices.
If you don't use it, the default action is to create new mount points for each insertion, with a digit appended to the name for each one. Even normal ejects cause this behavior. You end up with mount points like /media/username/SYSBKP, /media/username/SYSBKP1, /media/username/SYSBKP2, etc.- and you don't know which one is the active one.
This means you can't write scripts that assume the mount point name (unless you include all the mount commands in the script). Should you choose the wrong one it is treated as a local directory.
pmount makes sure your USB drive it has its own assigned mount point under /media/username/. In this case, it is always /media/pi/SYSBKP
It also works when you put in another USB flash drive with the same name. So it is not going by UUID.
I not only use this for flash drives, but also for fulll-size powered backup drives, for rsync backups, and have full confidence that the scripts will work without modification.
It is a simple, reliable solution to creating mount points.
Note that I have personally tested it with NTFS, FAT32 and the various EXT formatted drives. If the drive contains multiple partitions it will mount regular file systems individually by name, avoiding the swap partition. This is all visible in nautilus, and is alluded to in more detail in this Q&A:
I see in comments there is an issue with the NFS+ Time Machine drives.
It may or may not work automatically
How to access Time Machine Drives in Linux (macworld.com)
It turns out Apple does a couple slick things with the file system to make incremental backups work, including hard linking to directories, which isn't allowed in Linux. So for anyone that needs to access their Time Machine from something other than its associated Mac, here's how you do it... (see linked article for the rest)