Linux – Script to “remount” a partition (umount then mount)

linuxmountscripting

I'm doing some experiments with NTFS(-3G) and fstab. For every change I do to fstab, I need to issue:

sudo umount /mountpoint
sudo mount /mountpoint

To check the results. Since I'm doing a LOT of tests, it gets really annoying to issue the umount/mount combo every time.

Is there any way I could combine these 2 commands in a single remount script? Is there already any switch to mount that do that?

  • I'm using Ubuntu 10.10
  • All command-line parameters passed to the script must be "re-passed" to the mount command (so I can use -a, -t type, etc)
  • Preferably, only the last parameter should be passed to umount

Best Answer

In your shell (assuming bash or other compatible shell) run

function remount() { unmount "$1" && mount "$1"; }

now whenever you run remount /whatever, it'll do an unmount, then a mount.
This will expire if you close your shell. So if you want it to persist, put it in your .bashrc, .profile, or whatever applies to your case.

Related Question