Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
08-13-2017, 04:25 AM
|
#1
|
LQ Newbie
Registered: Aug 2017
Posts: 15
Rep: 
|
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/" ]
then
echo "exists."
else
echo "does not exist."
fi
failt.
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!
|
|
|
08-13-2017, 04:50 AM
|
#2
|
LQ Guru
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,262
|
/dev/mmcblk0p1/ is actually a node, a special type of thing.
Try
Code:
if [ -b "/dev/mmcblk0p1/" ]
|
|
|
08-13-2017, 05:38 AM
|
#3
|
LQ Guru
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
|
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.
Last edited by AwesomeMachine; 08-13-2017 at 11:32 AM.
|
|
|
08-13-2017, 02:00 PM
|
#5
|
LQ Guru
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,262
|
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
brw-rw---- 1 root disk 179, 1 Aug 10 16:26 /dev/mmcblk0p1
The 179,1 is major & minor numbers - see man mknod.
I mount it in /mnt/zip/ which is a directory.
|
|
|
08-13-2017, 05:05 PM
|
#6
|
Senior Member
Registered: Nov 2003
Location: Minnesota, US
Distribution: Fedora, Ubuntu, Manjaro
Posts: 1,791
|
I'm probably not being very efficient about it, but
Code:
mount | grep mmcblk0p1
will return something if the partition is mounted, and nothing if it isn't
|
|
|
08-14-2017, 01:52 AM
|
#7
|
LQ Newbie
Registered: Aug 2017
Posts: 15
Original Poster
Rep: 
|
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
KERNEL=="mmcblk0" SYMLINK+="dlc_sdcard", RUN+="/home/ged/prepare_sd_card.sh"
Code:
/home/ged/prepare_sd_card.sh
#! /bin/sh
/bin/mkdir /home/ged/ok
/bin/mount /dev/mmcblk0p1 /media/card/
Code:
/etc/udev/rules.d/99-udisks2.rules
# UDISKS_FILESYSTEM_SHARED
# ==1: mount filesystem to a shared directory (/media/VolumeName)
# ==0: mount filesystem to a private directory (/run/media/$USER/VolumeName)
# See udisks(8)
ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{UDISKS_FILESYSTEM_SHARED}="1"
The folder "OK" are written ... so my udev rule are working, but the mount are not working.
And udisks2 seems also not mounting
Thank you!
|
|
|
08-14-2017, 02:28 AM
|
#8
|
LQ Addict
Registered: Dec 2013
Posts: 19,872
|
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?
|
|
|
08-14-2017, 03:15 AM
|
#9
|
LQ Newbie
Registered: Aug 2017
Posts: 15
Original Poster
Rep: 
|
Quote:
Originally Posted by ondoho
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?
|
Hello,
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
|
|
|
08-14-2017, 03:25 AM
|
#10
|
LQ Newbie
Registered: Aug 2017
Posts: 15
Original Poster
Rep: 
|
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
|
|
|
08-14-2017, 04:45 AM
|
#11
|
LQ Guru
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,262
|
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.
|
|
|
08-14-2017, 07:23 AM
|
#12
|
LQ Newbie
Registered: Aug 2017
Posts: 15
Original Poster
Rep: 
|
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?
|
|
|
08-14-2017, 08:16 AM
|
#13
|
LQ Newbie
Registered: Aug 2017
Posts: 15
Original Poster
Rep: 
|
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!
|
|
|
08-14-2017, 10:26 AM
|
#14
|
LQ Guru
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,262
|
Code:
/dev/sdb1 /mnt/hd auto relatime,diratime,user,exec,dev,suid,nofail 0 0
That6's a good set of options(in /etc/fstab) for usb keys & that automounts. It mounts as root during boot, otherwise it mounts as a luser. I think /mnt/hd is owned by a user.
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?
|
|
|
08-15-2017, 02:42 AM
|
#15
|
LQ Newbie
Registered: Aug 2017
Posts: 15
Original Poster
Rep: 
|
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 01:40 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|