LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Check if it IS mounted (https://www.linuxquestions.org/questions/linux-general-1/check-if-it-is-mounted-15098/)

sourceman 02-26-2002 07:21 AM

Check if it IS mounted
 
I wrote a script file that does a bunch of things to all the possible partitions of HDA HDB HDC and HDD.

One thing I do is... I attempt to mount them.
If you try to mount a partition that doesn't exist then it spits out the message (for example) "open /dev/hdd12:Device not configured"
My "issues" start here... I don't want a lot of useless messages to be displayed. I don't need to know if it failed or not. It must just return clean.

Is there a way I can tell if a partition exists before I try to mount it?
Then I could only mount those.

And, in the same token, is there a way to tell if a HDD exists?
This will also help a lot.

acid_kewpie 02-26-2002 08:09 AM

i'd say just use something like

TESTPART=hda5

if [ `fdisk -l | grep -c $TESTPART` -eq 1 ]
then
echo partition found
fi

should work fine

Mik 02-26-2002 08:22 AM

You could try using the information in /proc/partitions.

Maybe something like:

for partition in `egrep "hd[a|b|c|d][0-9]+" /proc/partitions | awk {'print $4'}`
do
mount $partition
done

acid_kewpie 02-26-2002 08:28 AM

/proc/partitions doesn't contain hdXY references, you could parse the file heavily to convert


3 1 4200966 ide/host0/bus0/target0/lun0/part1 8787 7526 130498 120300 8821 8695 140336 317040 0 94430 437340

into

hda1

i guess. not gonna be fun really...

Mik 02-26-2002 08:45 AM

Ok sorry I guess that won't work on each machine then. But the output of my /proc/partitions does show it.

root:~# cat /proc/partitions
major minor #blocks name

3 0 6353235 hda
3 1 56196 hda1
3 2 1 hda2
3 5 104391 hda5
3 6 1028128 hda6
3 7 5156833 hda7
root:~#

I guess when you use a devfs then you get all those weird entries in it. So in that case using acid_kewpie's suggestion might be a better solution.

acid_kewpie 02-26-2002 08:53 AM

hmm, i'm not on devfs. i'm all confused now.... but then "fdisk -l" has stopped working for me, maybe it
's showign it in a different format or something.. ahh whatever

Mik 02-26-2002 09:04 AM

Hmm that's weird. Maybe it's some Redhat/Mandrake way of doing things. I don't have any of those systems around to check, but the ones I did check now all show the hdxX references in /proc/partitions. The man page of fdisk even says when using -l if there are no devices given then the entries in /proc/partitions are used. So that would explain why fdisk -l wouldn't work for you.
Maybe I should check my Mandrake system when I get home, probably also got those weird entries since I've seen them before.

sourceman 02-27-2002 01:16 AM

I'm running Mandrake and my /proc/partitions file gives similar info to Mik's.

I tried it and it worked juz great, x'cept...
There is still one problem...
hda2, in your example, is not a mountable partition.

Mmmmmmm, I wonder if I can figure out how to do this one myself. It looks like #blocks will always be 1 in this case.

Mik 02-27-2002 05:56 AM

I guess it would be logical that the number of blocks will always be 1. If you want to check it that way a simple adjustment would be enough:

for partition in `egrep "hd[a|b|c|d][0-9]+" /proc/partitions | \
awk {'if ($3 > 1) print $4'}`
do
mount $partition
done

sourceman 02-27-2002 06:49 AM

Yep. That's exactly what I did.... but then, I thought... why the hell do I wanna use egrep and awk, they're soooo big, and i'm stingy with my space at the moment. (It's on a boot disk).

So I wrote a little C app of like 10 lines or something.
Statically compiles to about 10k.
All I do is pass it a command line like "hda2" or "hdc" and it returns true or false, which I use in my script file.

Thanks for the help.

acid_kewpie 02-27-2002 06:52 AM

Quote:

On a quiet night you can hear Windows crashing.
nothing quiet about windows crashing when i'm involved!
http://www.linuxquestions.org/questi...threadid=15015

sourceman 02-27-2002 08:31 AM

Mmmmmmm...

OK, due to popular demand, I will remove the irritating word "windows" from my threads.

:D

Alright... it'll have to be this one then.


All times are GMT -5. The time now is 08:19 PM.