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. |
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 |
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 |
/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... |
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. |
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 |
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. |
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. |
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 |
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. |
Quote:
http://www.linuxquestions.org/questi...threadid=15015 |
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. |