Mount a specified subset of filesystems with ONE command ("mount -a; but with pattern")
To mount all available (and not yet mounted) disks and filesystems/partitions, one can use
mount -a
However, what I want to do is to mount a specific subset of all filesystems/partitions, but not ALL of them. Example:
mount -a /mnt/hotplugA # mount command does not support this
mount -a /mnt/hotplugB # mount command does not support this
umount -R /mnt/hotplugA # umount DOES support recursive unmounting
where hotplugA and hotplugB are mount points for two different drives (that I use for backup), and that also have multiple additional filesystems/partitions to be mounted underneath the top-level mount point.
The semantics should be that mount -a /mnt/hotplugA should mount all partitions that /etc/fstab specifies as to be mounted at /mnt/hotplugA and below, such that the result is the mounts
/mnt/hotplugA
/mnt/hotplugA/fs1
/mnt/hotplugA/fs2
...
/mnt/hotplugA/fsN
Basically whatever /etc/fstab specifies. Now, the standard mount command does not support the functionality I describe above (but umount does know how, it supports umount -R /path and will unmount anything including and below /path).
Are there any good solutions to the above requirement?
I found a solution that involves creating and using an alternate /etc/fstab file that contains only the filesystems that you want to operate on:
grep PATTERN /etc/fstab >! /tmp/fstab.$$; mount -a --fstab /tmp/fstab.$$
grep /mnt/hotplugA /etc/fstab >! /tmp/fstab.$$; mount -a --fstab /tmp/fstab.$$
Tested and working.