After following this answer a while back I have now run into some problems.

My situation: I have a USB-HDD set up to get mounted to a directory on my SD card using fstab. Using the Raspebrry Pi Camera Board, it will take photos and save them to the USB-HDD.

The problem is that if my USB-HDD is NOT plugged into my Raspebrry Pi, the directory still exists and files can get saved to the SD card. This is a big problem as my SD card is only 4GB and I need to save days-worth of images to the USB-HDD and that ends up using 1GB in just 15 minutes. I will have no access to the Raspberry Pi so it can't be using up all my SD card space, and possibly wearing it out.

  GNU nano 2.2.6                             File: /etc/fstab

proc            /proc           proc    defaults,noatime                 0       0
/dev/mmcblk0p1  /boot           vfat    defaults,noatime                 0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime                 0       1
/dev/sda1       /media/VISION   vfat    defaults,users,umask=000,noatime 0       0
/dev/mmcblk0p2  /mnt/sdcard     ext4    defaults,noatime                 0       0
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that

I want the system to have no permissions to save to the directory when the USB-HDD is unplugged, but when it is plugged in it does have permission. Maybe this can be done by having the fstab mount directory not on the SD card(could have it on the USB-HDD so it wont be there when its unplugged?).

2 Answers 2


Unmount the drive. Create a folder images inside /media/VISION. Make this folder readonly. Next mount the diver and again create the folder images. Edit your script to have it write the the folder /media/VISION/images. If the drive isn't mounted the script can't write to the folder. However, if it is mounted, it can.

It might even work without creating the subfoldeer, and just making the folder /media/VISION (on the SD) readonly. But I'm not sure in mounting overrides these permissions. You'd have to check yourself.

Also make sure you script doesn't fail, if it can't write.


Have you considered running your program via a script that first checks to see if that drive is currently mounted?

Run mount | grep /your/path/here and with a bash script see if you get a return. If you do, start your program.

Src: http://www.linuxquestions.org/questions/linux-newbie-8/check-to-see-if-a-drive-is-mounted-380749/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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