LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Identical removable HDDs (https://www.linuxquestions.org/questions/linux-newbie-8/identical-removable-hdds-224365/)

dgermann 08-30-2004 12:41 PM

Identical removable HDDs
 
Hi--

OK, I have gotten as far as getting a second removable HDD so I can swap these as my backups, taking one offsite.

I have two identical drives (Western Digital 200Gb) on my Red Hat 9.0 system.

Here's what I did:

1. The first is installed and partitioned as /dev/sda1 and sda2.

2. I plugged in the second and ran fdisk to make identical partitions.

3. Ran /sbin/mkfs -t ext3 /dev/sdb1 and sdb2

4. Ran e2label /dev/sdb1 label1 and sdb2 label2

5. Shut off power to HDD2, then HDD1, then powered up HDD2--it still sees it as sdb instead of sda.

6. Thinking I should start over, I removed partitions via fdisk from sdb, then, with only HDD2 powered up and plugged in (usb2 port), tried to run fdisk on it as sda--fdisk complained that "unable to read /dev/sda"

I want to be able to swap these out from day to day, so I want the cron files to see these as the same drive.

Suggestions?

dgermann 08-30-2004 10:24 PM

OK, folks, here's an update, that might give us some clues:

I powered off the 1st HDD.

Then I powered on the 2nd HDD.

Then I rebooted the machine.

Voila! the 2d HDD was now recognized as sda1 and sda2, and the drives mounted OK.

So that leaves this question for you gurus :Pengy: :

How can I get it to allow me to swap these two backup drives without having to reboot? (This is a file server, and 5 computers might have to re-login if I rebooted, and files might be lost if someone was in the middle of work).

Is it an option to the mount command?

I notice in /var/log/messages a lot of references to devlabel--is there perhaps something I should do with that?

And would it be better to post this question in another category?

nukkel 08-31-2004 04:29 AM

Hi,

Well what happens is, the first removable storage device that you attach after a (re)boot -- be it an usb flash keychain, or a digital camera, or an external harddrive, ... -- is always assigned to sda. Then the second sdb and so on, even if the first device was removed in the meantime. This is your problem and it goes rather deep I'm afraid... It would require kernel programming to alter this behaviour.

What I think you could do in your case is to make a script of some kind that you run instead of mounting the drive, and that:
1 - Checks which drive is there (sda or sdb)
2 - Mounts whichever drive it finds to a fixed mount point, so that the partition(s) is/are mounted at the same mount point, regardless of it being on sda or sdb.

Please feel free to ask for clarification -- I'm a bit concise here 'cos I don't know your level of experience :jawa:
nukkel

dgermann 08-31-2004 11:04 AM

nukkel--

Thanks for the help!

As you guessed, I am still a real novice. I got the general drift of what you have said, and I do see that something is going on in the kernel to tell it where sda and sdb are. But beyond that, it is all greek (maybe I could say it is all linux :p ) to me!

For one thing, I do not understand anything about fixed mount points.

Here is the script I use now.

=====
#!/bin/bash
echo "Run this as su"
/sbin/e2label /dev/sda1 /backups2
/sbin/e2label /dev/sda2 /extra
mount -L /backups2
mount -L /extra
df -h
=====

If I recall correctly, once one of them has been mounted, then a simple umount followed by powering down the one and powering up the second, followed by running this script again, does not work.

So what would the script you have in mind look like?

Thanks, nukkel, for befriending this lost linux soul!

scuzzman 08-31-2004 11:22 AM

maybe instead of having the system them as the same device, simply have them linked to the same mount point. ie:
Code:

#!/bin/bash

# script-name: swapdrive
# lets assume the mountpoint is going to be
# /backup
# if this directory has yet to be created, create it
# sudo mkdir /backup

# Note: this script is not correct, and thus not fully useable yet
# what's not useable will be in italics
# the conditional here is what you're needing
# something along the lines of detecting whether
# a particular device is already mounted ie:

if (/dev/sda1 is already mounted) {
umount /dev/sda1
mount /dev/sda2 /backup # mount the second drive to /backup
}
else { # if the first one isnt mounted, umount sda2 and mount sda1
umount /dev/sda2
mount /dev/sda1 /backup # mount the first drive
}

exit
#EOF


Coldburn 08-31-2004 02:18 PM

why not raid these drives?
 
why dont you mirror (raid 1) these drives? Use mdadm to create the mirror and you can shut down either of the two drives and hot-swap them provided your hardware will allow it. You wouldnt have the /sda /sdb problem either since the raid set would use /dev/md?

http://www.linuxdevcenter.com/pub/a/...2/05/RAID.html

nukkel 08-31-2004 02:28 PM

Hi Doug,

You're welcome! :cool: Sorry, I must have missed the fact that you used e2label, which is actually a good move. A you sure that you have set the labels on both HDD's? I.e. plug both in, and then

/sbin/e2label /dev/sda1 backups2
/sbin/e2label /dev/sda2 extra
/sbin/e2label /dev/sdb1 backups2
/sbin/e2label /dev/sdb2 extra

so they look identical. (also note, it's not necessary to put a / in the label.) Then when only one of the HDD's are plugged in it should work by simply doing "mount -L /extras". There's no need to re-run e2label every time -- the label is preserved until changed.

Again, I could have told you this before, I just missed it :s

Could you try this? putting the labels on both drives and then mounting by just doing "mount -L ..."? See if they can be swapped OK...

If that don't work, I'll get back to you on that script -- to look where the attached drive "went" (sda? sdb?) and then mount it accordingly etc...

Good luck!
nukkel

nukkel 08-31-2004 02:32 PM

Coldburn: nice suggestion, however I wonder... If your 2 drives differ because e.g. you put sth. on one of them from another computer... What will then be considered the "correct" one?

dgermann 08-31-2004 08:12 PM

Wow! You guyr are terrific!
 
John, nukkel, Coldburn--

Wow! You guys are terrific! I think you have given me much more than I could have expected. An overrunning cup, as it were....

Everyone--

I seem to be up and running with my original script. nukkel, you answered the remaining question I had on the script, whether I could just comment out the two e2label lines. I will do that.

I simply umounted the #2 HDD, powered down, powered up #1 HDD, and ran the script.

I think I tried that before and took its complaints about e2 label not working meaning the whole thing failed. But this time it did mount the #1 HDD.

(The error message reads:
/sbin/e2label: Attempt to read block from file system resulted in short read while trying to open /dev/sda1
Couldn't find valid filesystem superblock.
I/O error: dev 08:02, sector 0)

John--

Thanks for all the work on this one! Wow!

It looks like your script does much the same as mine, in the sense that it mounts the one after checking which drive is actually present. Mine is a dumber script, not doing any checking, just clumping through with jack boots and mounting whether it is sda or sdb....

Let's say I add a 3rd, 4th and maybe even 5th HDD for more backups. Any reason I'd need to have a step-above script like yours in place of mine (now simplified)?

Coldburn--

Thanks for bringing up this idea. I wondered just this morning how this might be like raid, and how that might be set up.

You have given me the entry point to see how it is done.

Does raid allow me to take one or more drives off site for safety?

nukkel--

Thank you for sticking with me on this. You have given me some real confidence!

dgermann 08-31-2004 08:24 PM

OK folks, I commented out the 2 e2label lines. When it runs the script now, I get these error messages:

I/O error: dev 08:01, sector 312464000
I/O error: dev 08:02, sector 78252416

It does seem to mount the drive OK, though.

Not to worry? Or a problem?

nukkel 09-01-2004 09:10 AM

I guess this is, since the mount is done using labels, it is looking around for a drive which has a partition with that label, so it makes some "wrong guesses", tries to read but there's nothing there. Result, I/O error... It shouldn't be a problem.

However, don't forget to un-mount the partitions before unplugging a drive (using the umount command, or in the GUI), otherwise there may still be data in RAM cache that should have been written to disk. This would also give these I/O errors, when the drive has been unplugged without unmounting.

As for using even more disks... I guess just labeling all of them in the same way would work OK...

P.S. Keep up this state of mind, and you won't be a novice for much longer :cool: Never give up experimenting!

dgermann 09-01-2004 06:04 PM

nukkel--

Thanks for the compliments!

What I did was make a small script file:

===
#!/bin/bash
echo "run this as su"
umount /backups2
umount /extra
echo "OK to power down first HDD"
echo ""
echo "Now, power up second HDD"
echo ""
echo "When second drive up to speed,"
echo ""
echo "Hit <Return>."
read anykey
mount -L /backups2
mount -L /extra
df -h
===

So that should make sure I umount each time.

Thanks for sticking with me on this, nukkel!

nukkel 09-02-2004 02:53 AM

I think that's the safest way to go! Glad to hear it worked out for you!

best regards,
nukkel

Coldburn 09-03-2004 10:21 PM

Re: Wow! You guyr are terrific!
 
Quote:

Originally posted by dgermann
John, nukkel, Coldburn--

Coldburn--

Thanks for bringing up this idea. I wondered just this morning how this might be like raid, and how that might be set up.

You have given me the entry point to see how it is done.

Does raid allow me to take one or more drives off site for safety?

nukkel--

Thank you for sticking with me on this. You have given me some real confidence!

Yes! You can administrativly 'fail' a drive and safely hot-swap (or pull it from the machine while running - provided the hardware supports it) without a hickup. I've done similar on HP and Compaq storage systems for years. It feels weird at first but ya get used to it! ;)

This article isnt too bad.. http://www.linuxdevcenter.com/pub/a/...2/05/RAID.html

If I google mdadm i seem to get the same article copied on different sites...

Oh and to answer your question..

Quote:

Coldburn: nice suggestion, however I wonder... If your 2 drives differ because e.g. you put sth. on one of them from another computer... What will then be considered the "correct" one?
Typically when you fail a drive it's marked with a flag, so the raid set will know which drives are the 'good' ones.

dgermann 09-04-2004 07:52 PM

Coldburn--

Thanks!

The article is a little beyond my skills at this point, but perhaps tying it would give me the educations I need. Scary.

If I put both these drives on the machine, and say another couple drives, then I could swap daily and have a decent back up system, yes? Seems to me I do not need to do anything other than use this software to accomplish that, right? No other hardware needed? If so, that's neat.

Would it get rid of those I/O errors I mentioned? Those have me wondering, although it seems it may be a kernal issue, rather than a problem with the drives. Anybody know anything about those I/O errors?


All times are GMT -5. The time now is 07:12 PM.