0

Is there a way to unmount the last mounted filesystem without doing umount <dev>?

I ask because I'm getting tired of doing mount to get the device when all I could do is just unmount the last filesystem.

3 Answers 3

1

Presumably you know the mountpoint, so you can just do umount /mnt/point.

I don't know of an "unmount last filesystem" option, but personally, it sounds a bit risky. You could do something like

fs='/dev/sda1'
mount $fs /mnt/point
.
.
.
umount $fs

If that makes your life any easier.

1

I have never tried this, but you might want to test it. The tune2fs utility gives the last mount time for a file system, if run with the -l flag. You can then write a script to list all the last mount time field for all your mount points and then unmount the latest one.

Partial output from tune2fs

    root@localhost:/# tune2fs -l /dev/sda1  | grep -i time
    Last mount time:          Tue Mar  5 17:40:36 2013
    Last write time:          Mon Feb  4 11:53:20 2013
1

According to the answer to this question, /proc/mounts contains a list of filesystems in mounted order. Therefore you could do

umount `tail -1 /proc/mounts | cut -f2 -d' '`

You must log in to answer this question.