LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 10-06-2005, 11:22 AM   #1
infinity42
Member
 
Registered: Apr 2005
Location: England
Distribution: Gentoo
Posts: 142

Rep: Reputation: 16
Hot swapping cd-roms w/ hdparm -R/-U


I was feeling bored and vaguely insane today, so I thought I would try hotswapping my cdrom drives as a challenge really.

I have two ide channels:
ide0: hda (main harddrive)
ide1: hdc && hdd (cdroms)

First I did:
Code:
#hdparm -Y /dev/hdc /dev/hdd
To put them to sleep. Took ages, but seemed to work fine.
Then I ran:
Code:
# hdparm -U 1 /dev/hdc
Took a long time, and the output went something like this:
Code:
/dev/hda:
 attempting to unregister hwif#1
That was all, no error messages. Well ide1 was still in /proc/ide, but i pulled the power on the drives, then the ide cables. Plugged the ide cable into two other cdroms (I have 5 in my box.. don't ask), then the power. They spun up and did the whirry thing. The ide light on the case came on, and has been on solid since. Well ide1 was still in proc, so i had a look at /proc/ide/ide1/hdc/model and it still thought that the other drives where there. So I ran
Code:
# hdparm -R 0x170 0x376 15 /dev/hdc
At that point it seg faulted! Also ide1 disappeared from proc at this point, and /dev/hdc && /dev/hdd disappeared (I use udev). So I tried
Code:
# hdparm -R 0x170 0x376 15 /dev/hda
as the device doesn't matter really, it's just used for ioctl i believe. This spits out:
Code:
/dev/hda:
 attempting to scan hwif (0x170, 0x376, 15)
 HDIO_SCAN_HWIF failed: Input/output error
and this comes out in dmesg:
Code:
 ide1: I/O resource 0x376-0x376 not free.
ide1: ports already in use, skipping probe
I tried running
Code:
# hdparm -U 1 /dev/hda
but it just seems to hang there.

Any ideas? (I'm happy to try most things, however insane) I will reboot soonish and try it again, see if i can get more logging out of the kernel to see what is going on.

(Yes I know this is unsupported, blah blah.. dangerous, blah blah.. )
 
Old 10-06-2005, 01:03 PM   #2
infinity42
Member
 
Registered: Apr 2005
Location: England
Distribution: Gentoo
Posts: 142

Original Poster
Rep: Reputation: 16
I've just worked it out! To unregister run
Code:
#hdparm -U 1 /dev/hda
i.e. a with a device not on the IDE bus you are trying to disconnect! This removes ide1 perfectly. Now swap the drives around and run
Code:
#hdparm -R 0x170 0x376 15 /dev/hda
(I think these numbers are always the same for ide1. You can find them in /var/log/dmesg; they look something like:
Code:
Probing IDE interface ide0...
ide0 at 0x1f0-0x1f7,0x3f6 on irq 14
Probing IDE interface ide1...
ide1 at 0x170-0x177,0x376 on irq 15
) Check in dmesg and you should see something like this:
Code:
ide1 at 0x170-0x177,0x376 on irq 15
hdc: ATAPI 32X CD-ROM drive, 128kB Cache
hdd: ATAPI 12X CD-ROM drive, 86kB Cache
although probably with more descriptive names (these cdroms are a couple of quite old ones)

I would not reccomend trying this with harddrives unless you are sure that the harddrive is not spinning and the heads are parked before you pull the power; I think hdparm -Y should do that, but I'm really not sure. Don't even think about trying to hot-swap your root drive .

Hope that helps someone, or at least someone finds it interesting.
 
Old 10-06-2005, 05:00 PM   #3
infinity42
Member
 
Registered: Apr 2005
Location: England
Distribution: Gentoo
Posts: 142

Original Poster
Rep: Reputation: 16
I have just written a (very simplistic) script to make this process easier. I'll share it here just in case anyone ever wants it:
Code:
#!/bin/zsh
DEVICE=/dev/hda
BUS=1
IO_ADR=0x170
if [ -z $1 ];then
        echo "Usage: $0 [off|on|rescan]"
        exit
fi
if [ "$1" = "on" ];then;do_r='y';fi
if [ "$1" = "off" ];then;do_u='y';fi
if [ "$1" = "rescan" ];then;do_u='y';do_r='y';fi
[ ! -z $do_u ] && hdparm -U $BUS $DEVICE
[ ! -z $do_r ] && hdparm -R $IO_ADR 0 0 $DEVICE
It is written for zsh, but it would be trivial to port it to bash. See above post for info about how it works.

I should just mention that this is considered dangerous to hardware etc. I would personally recommend you only use it on cdrom drives, and use common sense when messing around inside a powered on computer. I hold no responsibility blah blah if it wipes your harddrive/causes a nuclear disaster (Those bugs in the kernel where fixed last year :P)

Enjoy!

[Note: a mod may want to move this to the success stories forum if you think it's appropriate]
 
  


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
Hot swapping a scsi hard drive with Redhat ES 3 ttang99 Linux - Enterprise 0 09-01-2005 08:38 AM
Hot swapping? gauge73 Linux - Hardware 3 08-10-2005 12:52 PM
CD-ROMs PhuckFonix Linux - Games 2 07-24-2004 01:15 PM
Hot swapping cdrom and floppy rootyard Linux - Laptop and Netbook 0 01-08-2004 10:19 AM
hdparm -g NOT= hdparm -i ---LILO hangs @ L stevewalsh Linux - General 4 07-23-2001 09:37 PM


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

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