Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When mounting a filesystem image via mount -o loop, is there any mechanism to prevent the same file to be mounted a second time?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

There is no specific command that may stop the file to be mounted several times with different mountpoints, but you may use this script to not mount it if it is already mounted:

#!/bin/bash
mount |grep -qF "$1" || mount "$1" $2 -o loop

the first parameter is a file to mount, and second is a mount point to use.

share|improve this answer
1  
Hrm, so that's suboptimal... test $(losetup -j "$1" | wc -l) -eq 0 && mount "$1" $2 -o loop will check for a loopdevice even if it's unmounted by the way. –  Tobias Kienzler Nov 2 '12 at 8:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.