bash script and proof if sd card is available
Hello,
I`m mounting a sd card at boot. Then I have the partition "/dev/mmcblk0p1" When the sd card is not inserted, of course this partition will not shown. Now I need a bash script to do some actions, when the partition is available. But my test with: Code:
if [ -d "/dev/mmcblk0p1/" ] Guess it is because it is a partition and not a directory? How can I check if the partition or the sd card available? Thank you! |
/dev/mmcblk0p1/ is actually a node, a special type of thing.
Try Code:
if [ -b "/dev/mmcblk0p1/" ] |
The script appears correct, but if you're using /dev/mmcblk0p1 as a mount point, then it will always be there. It would be a directory. /dev/mmcblk0p1 cannot be a partition itself. It can only be a mount point.
Separate partitions can be mounted to any mount point (directory off of /). But the partition cannot mount if the mount point is not there. So, I think your terminology is a bit off when you say /dev/mmcblk0p1 is a partition, because I think it's actually a mount point for a partition. Edit: No, it's probably a device file. business_kid is correct. |
i just went through the process of setting up a udev rule when a usb device is connected.
i'm sure it would apply to your situation also. this tutorial helped me the most: http://hackaday.com/2009/09/18/how-to-write-udev-rules/ and https://wiki.archlinux.org/index.php/Udev |
I have an sdcard; it's device node is /dev/mmcblk0, (equivalent to /dev/sda) and the first partition is /dev/mmcblk0p1 (equivalent to /dev/sda1). I'm pretty sure it's a device node made in udev.
Code:
bash-4.3$ ls -l /dev/mmcblk0p1 I mount it in /mnt/zip/ which is a directory. |
I'm probably not being very efficient about it, but
Code:
mount | grep mmcblk0p1 |
Goo morning to all,
you are great :-) With udev it work fine. So it is better to mount the sd-card not in fstab. I can do this in the sh script, which the udev rule start. But the Warning: Warning: To mount removable drives, do not call mount from udev rules. In case of FUSE filesystems, you will get Transport endpoint not connected errors. Instead, you could use udisks that handles automount correctly or to make mount work inside udev rules, copy /usr/lib/systemd/system/systemd-udevd.service to /etc/systemd/system/systemd-udevd.service and replace MountFlags=slave to MountFlags=shared.[3] Keep in mind though that udev is not intended to invoke long-running processes. did bnot help. The folders are not existing at my Linux and udisks2 seems not working? here my settings: udev rule for checking sd-card is inserted: Code:
/etc/udev/rules.d# cat 81-sdcard.rules Code:
/home/ged/prepare_sd_card.sh Code:
/etc/udev/rules.d/99-udisks2.rules And udisks2 seems also not mounting Thank you! |
why do you need to mount the sd card with a custom script?
doesn't it automount on insertion? or, can't you configure udev (or udisks or udisks2 or gvfs...) to automount it? my udev rule example was not meant for mounting! it was meant for what you wrote in post #1: device is present, now do things. speaking of which, what things do you need to do with the sd card? what scripts/actions? |
Quote:
I must not need to mount the sd-card itself with an own scrpit. But after mounting, I have to do some tasks. Made some, folders, ... And: I move the /var/log and other folders to the sd-card with: /dev/mmcblk0p1 /var/log vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,nofail 0 0 (example from fstab) So when the sd-card on insertion, I need runnig some tasks. No, the sd-card will not be automoundet :-( I use a baglebone black. And yes, unfortunately I can't configure udev (or udisks or udisks2 or gvfs...) to automount |
1 Attachment(s)
I try to reach this logic.
Move folders, where often are written, to the SD-Card ... when the SD card is insertion or removing it sync with the temporary backup folder to keep all 3 folders up-2-date |
From the vague picture that's developing, it sounds like networking rather than sdcards might be a better way to go if you're trying to sync folders.
|
Hello,
I´m not sure if I unterstand your answer correct, but here are the reason: I Dont want to write too often in the beaglebone black flash memory. The logfiles write very often and the config folder of an application same. So I want to move this 2 sources to the sd-card. Neither the logger application or the other application knows about this. They write in the default folder .. but moved with mount to the sd card. But when the sd card is missing or broken, the system should use the original folder A cronjob copy each 6h the datas from the sd in a backup folder of the flash memory. When the beaglebone start or the sd-card will be replaced, it sync all 3 destinations: back folder original folder sd card fold to get the latest version of each file Hope I could explain clearly? |
Hello again,
I´m near finished all tasks ... but automount on a beaglebone black with Debian seems not working. Can someone support me for the automount part? Thank you! |
Code:
/dev/sdb1 /mnt/hd auto relatime,diratime,user,exec,dev,suid,nofail 0 0 Frankly, sd cards are not the thing for regular writes either - ramdisks are. You need to choose your most writable source or consider an nfs mount over your network, or such like. Com,pare how many writes you can expect from your beaglebone flash versus an sd card. The flash will probably come out on top. The other consideration is atime. How are you handling that? |
Hello,
yes, you are right. But if the sd card failed, I can replace without to buy a new beagle and reinstall the software. And later also a Database should be working and therefore I need the sd card. But I´m not able to realize the automount. Tried different ways :-( |
All times are GMT -5. The time now is 12:11 AM. |