LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 02-26-2002, 07:21 AM   #1
sourceman
Member
 
Registered: Feb 2002
Posts: 48

Rep: Reputation: 15
Question 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/hdd12evice 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.
 
Old 02-26-2002, 08:09 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,397

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
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
 
Old 02-26-2002, 08:22 AM   #3
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 46
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
 
Old 02-26-2002, 08:28 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,397

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
/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...
 
Old 02-26-2002, 08:45 AM   #5
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 46
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.
 
Old 02-26-2002, 08:53 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,397

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
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
 
Old 02-26-2002, 09:04 AM   #7
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 46
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.
 
Old 02-27-2002, 01:16 AM   #8
sourceman
Member
 
Registered: Feb 2002
Posts: 48

Original Poster
Rep: Reputation: 15
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.
 
Old 02-27-2002, 05:56 AM   #9
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 46
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
 
Old 02-27-2002, 06:49 AM   #10
sourceman
Member
 
Registered: Feb 2002
Posts: 48

Original Poster
Rep: Reputation: 15
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.
 
Old 02-27-2002, 06:52 AM   #11
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,397

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
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
 
Old 02-27-2002, 08:31 AM   #12
sourceman
Member
 
Registered: Feb 2002
Posts: 48

Original Poster
Rep: Reputation: 15
Mmmmmmm...

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



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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash-Check If FS is Already Mounted On Directory fortezza Programming 15 04-27-2013 07:06 PM
Check to see if a drive is mounted joshnya Linux - Newbie 2 11-07-2005 08:56 AM
script check to see if device is mounted Warmduvet Programming 14 09-03-2004 06:17 PM
Boot disk; check. CD in drive; check. Doesn't work; check. Hal DamnSmallLinux 7 02-04-2004 02:10 AM
SCRIPT: check if auto-mount mount-points are still mounted markus1982 Linux - Software 0 05-25-2003 05:48 AM


All times are GMT -5. The time now is 05:22 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration