LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 11-26-2008, 01:23 PM   #1
lulatsch
LQ Newbie
 
Registered: Nov 2008
Posts: 24

Rep: Reputation: 15
Mounting harddrives, letter changes


Hello,

as part of a backup system, I use 2 very simple scripts to mount and unmount a harddrive;


To mount;
#!/bin/sh
#/sbin/backup-mount
echo " /dev/sda5 mounted at /mnt/backup" >>/var/log/messages
mount /dev/sda5 /mnt/backup >>/var/log/messages
echo " /dev/sda5 mounted at /mnt/backup"

To unmount;

#!/bin/sh
#/sbin/backup-unmount
sync
echo "/mnt/backup now offline" >>/var/log/messages
umount /dev/sda5 >>/var/log/messages
echo "/mnt/backup now offline"


The problem is that when devices get (often) inserted in a haphazard manner, the drive isn't sda5 anymore, but sometimes sdb5, sdc5, sdd5 etc, and then the script doesn't work anymore.

How can I alter the script so that it picks up sd*5?
 
Old 11-26-2008, 01:32 PM   #2
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,085

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
This is a problem that udev was developed to solve.
See here: http://www.reactivated.net/writing_udev_rules.html
There are several example rules that you can modify to suit your needs.
udev needs to be restarted before your new rule will take effect.
Welcome to LQ!
 
Old 11-26-2008, 01:59 PM   #3
lulatsch
LQ Newbie
 
Registered: Nov 2008
Posts: 24

Original Poster
Rep: Reputation: 15
Thankyou for the udev tip, I am looking into it.

But I have a question: what advantage would using udev bring me, opposed to (e.g.) putting the UUID of the drive in /etc/fstab?
 
Old 11-27-2008, 01:20 PM   #4
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,085

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
May I suggest you try it?
 
Old 11-27-2008, 03:40 PM   #5
newtovanilla
Member
 
Registered: Apr 2008
Posts: 267

Rep: Reputation: 30
I read that people who have this kind of problem with booting use a disk identifier so that the GRUB will find it without the sda5 setting. I think that is the
Quote:
UUID
you mentioned. Does mount work with UUID? They would put the UUID in the file /etc/fstab and then also in the GRUB menu, so that it would boot up without the sda5 setting.
 
Old 11-27-2008, 03:42 PM   #6
lulatsch
LQ Newbie
 
Registered: Nov 2008
Posts: 24

Original Poster
Rep: Reputation: 15
Yes, one can specify the UUID of a device in /etc/fstab. This is the solution I am planning on using, as of yet.
 
Old 11-27-2008, 10:34 PM   #7
salter
Member
 
Registered: Oct 2008
Posts: 100

Rep: Reputation: 15
Shell scripts can handle input in the form of $1 (for the first parameter passed), etc.

Change the script so that it will take the drive letter from the command-line parameter (if no such parameter is passed, then apply a default value like 'a').

This way you will not have to change the script in the future, but you can still act flexible on a changed drive configuration.

Last edited by Tinkster; 10-30-2010 at 04:05 PM.
 
Old 12-06-2008, 07:26 AM   #8
lulatsch
LQ Newbie
 
Registered: Nov 2008
Posts: 24

Original Poster
Rep: Reputation: 15
The problem has expanded: several different harddrives (with differing UUIDS etc, of course) will be used, and each of these needs to be mounted to /dev/sda5 when it's connected. How can this be done?
 
Old 12-06-2008, 10:51 AM   #9
lazlow
Senior Member
 
Registered: Jan 2006
Posts: 4,362

Rep: Reputation: 172Reputation: 172
Why not use you original script like a subroutine and pass it the $1 from another(master) script. Then have a different master script for each drive(backup1, backup2, etc). I can see no good reason that you should be limited to /dev/sda5.
 
Old 12-06-2008, 05:14 PM   #10
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,085

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
Quote:
The problem has expanded:....
Please reread my post #2:
Quote:
This is a problem that udev was developed to solve....
Don't try and mount each disk at /dev/sdXY This is "The wrong way to do it", and may cause you many problems in the future.

Make a udev rule by following the link I gave you, to mount them, based on each disk's UUID if that is what you'd like, at /media/CurrentBackupDevice

Then your problem is solved.

There is no point in us offering solutions if you are not prepared to try them.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mounting harddrives knudsen83 Linux - Newbie 5 01-27-2008 05:14 PM
Mounting WinXp Harddrives NooDleZ Linux - Newbie 5 02-19-2004 11:24 AM
Mounting Harddrives izmeh Linux - General 1 10-23-2003 11:43 PM
Mounting DVD and Harddrives Mighty_Viking Linux - Hardware 3 05-31-2003 04:05 PM
Mounting other harddrives jester_69 Linux - General 9 06-23-2002 03:04 AM


All times are GMT -5. The time now is 02:08 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration