# CDROM (not) hot swaping [UPDATE NEW INFO]

## beatryder

Has any one out there had trouble with hot swaping?

If I start my laptop with my modular bay battery installed, and try to get my cdrom working after that (via swaping the battery for the cdrom) it wont work.

Is there any way of forcing the kernel to reinitalize the IDE drivers? Or somthing to that nature?

Ok, so after following some suggestions I found on the forums I have managed to DMA working properly  for this drive.

I have since made another observation

When I boot *without* the cd/dvdrw installed I get the following in my dmesg

```

 ata2: diasbling port

```

But this does not show up in dmesg when the drive is plugged in

```

$ dmesg | grep ata 

[   26.241603] libata version 1.11 loaded.

[   26.241672] ata_piix version 1.03

[   26.241712] ata1: SATA max UDMA/133 cmd 0x1F0 ctl 0x3F6 bmdma 0xBFA0 irq 14

[   26.243234] ata1: dev 0 cfg 49:0f00 82:746b 83:7fe8 84:4023 85:f46b 86:3c48 87:4023 88:203f

[   26.243239] ata1: dev 0 ATA-6, max UDMA/100, 117210240 sectors: LBA48

[   26.243241] ata1(0): applying bridge limits

[   26.243316] ata1: dev 0 configured for UDMA/100

[   26.243318] scsi0 : ata_piix

[   26.244071] ata2: SATA max UDMA/133 cmd 0x170 ctl 0x376 bmdma 0xBFA8 irq 15

[   26.245785] ata2: dev 0 cfg 49:0b00 82:0000 83:0000 84:0000 85:0000 86:0000 87:0000 88:0407

[   26.245788] ata2: dev 0 ATAPI, max UDMA/33

[   26.245868] ata2: dev 0 configured for UDMA/33

[   26.245870] scsi1 : ata_piix

```

Is there a way to make ata2 start listening on that port after boot? Or set it up so that it allocates the resources even if the device is not connected?

Compiling as a module is not an option, as the computer will not boot unless its static.

----------

## NeddySeagoon

beatryder,

IDE is not hot swappable by design.

----------

## beatryder

Then can someone explain to me how Laptop hot swap drives work???

I apologize for the harsh tone, but this is frustrating.

This works perfectly under windows. Which means that there is a way to do it, I just need to figure out how.

----------

## NeddySeagoon

beatryder,

Is your laptop CDROM IDE or something else ?

SCSI, SATA, USB, and Firewire are all hot swappable

----------

## beatryder

Its an atapi DVD/RW, if I remove IDE support from my kernel. it will not work no matter what I try.

-Thx

[Edit] I was wrong, it just took some kernel hacking.

----------

## NeddySeagoon

beatryder,

It must be close to IDE but standard IDE is not hot swappable.

Do you need the IDE driver for your main HDD?

If not, making IDE support as a module and loading it after the CD/DVD is installed may be a work around.

/usr/src/linux/Documentation/kernel-parameters.txt and the IDE documentaion may be worth a read too.

----------

## beatryder

My HD works on the SATA driver, so its uneffected by IDE driver changes

I have tried playing with modulizing the ide drivers, albeit I have not spend more than 15 mins on it.

I will give that some further looking into and post a fix if I can find one.

----------

## NeddySeagoon

beatryder,

Hmm, I'm surprised that a laptop has both SATA and IDE. It tight for space.

Some chip sets come with IDE built in, so there may be no savings to be had.

If it works by modprobing the IDE module, udev and hotplug can probably automate it.

----------

## beatryder

FYI, SATA is backwards compatable to IDE,

My HD is an IDE HD but its using a SATA controler, also to my knowledge there are no SATA CD/DVD ROMs out there yet.

----------

## fredgt

There are already some dvd/cdrom drives on sata but as most motherboards still have a ide on board there is not much use for it especialy with some operating systems not supporting it without 3rd party drivers. So installing them can become a lot more difficult with a sata cdrom drive.

Normally ide isn't hotswappable but some laptops do have a hotswappable support for the cd-rom drive. I don't know how but it is possible.

I wouldn't advise using it. When i unplug my cd-rom while running it keeps giving errors in dmesg just untill i plug it in again.

```

hdc: status error: status=0x00 { }

ide: failed opcode was: unknown

hdc: status error: status=0xff { Busy }

ide: failed opcode was: unknown

hdc: drive not ready for command

hdc: ATAPI reset complete

```

When you boot with the cdrom in it it could work when you swap to battery and then back to the cdrom but i wouldn't advise u to use it much as it keeps generating error and could generate some big error logs. So shutting down before swappig is probably the best option.

----------

## beatryder

 *NeddySeagoon wrote:*   

> beatryder,
> 
> Hmm, I'm surprised that a laptop has both SATA and IDE. It tight for space.
> 
> Some chip sets come with IDE built in, so there may be no savings to be had.
> ...

 

just tried that, no dice.

----------

## azazello

 *Quote:*   

> IDE is not hot swappable by design.

 

IDE is perfectly hot-swappable if supported properly. Don't spread FUD about things you haven't used.

Modern chipsets have IDE hot-swap support. AFAIK to use it, you have to use only one device per bus (which is what laptops do). The software is responsible for powering down the drive and turning off the controller before giving an OK to the user to hot-swap the bay.

Linux certainly doesn't have good IDE hot-swap support (at least from the end user standpoint) compared to, say, Windows XP where such devices work flawlessly. As of 2.6.11, I don't think you can get the kernel to recognize the inserted device by modprobbing if there was no device in the bay at boot.

Here's what I did to get the best hot-swap support available on my IBM Thinkpad T40 with KDE installed:

```

# hdparm functionality for hotswapping Ultrabay devices is broken right now, but this works:

cd /root; wget http://users.ox.ac.uk/~univ1377/hotswap-0.4.0.tar.gz

tar xvzf hotswap-0.4.0.tar.gz; cd hotswap-0.4.0

./configure --disable-motif-frontend --prefix=/usr/kde/3.4/ && make && make install

```

This installs hotswap, which can swap an IDE device (by default /dev/hdc) for you. It has text and graphical front-ends.

```

echo '#!/bin/sh

umount -l /mnt/ntfs

umount -l /mnt/cdrom

hdparm -y /dev/hdc

/usr/kde/3.4/bin/hotswap --ide-controller=1 unregister-ide && echo eject > /proc/acpi/ibm/bay' > /etc/acpi/ubayeject.sh

echo '#!/bin/sh

/usr/kde/3.4/bin/hotswap --ide-controller=1 rescan-ide

/bin/mount -t ntfs -o rw,utf8,umask=0777 /dev/hdc1 /mnt/ntfs

/bin/mount -t iso9660 -o ro /dev/cdroms/cdrom0 /mnt/cdrom' > /etc/acpi/ubayinsert.sh

echo 'event=ibm/bay MSTR 00000003 00000000

action=/etc/acpi/ubayeject.sh' > /etc/acpi/events/ubayeject

echo 'event=ibm/bay MSTR 00000001 00000000

action=/etc/acpi/ubayinsert.sh' > /etc/acpi/events/ubayinsert

```

This is an ACPI script to respond when the user arms the Ultrabay eject lever. (Similar events should fire for other systems if you have proper ACPI support installed; you can get their ACPI event IDs by running

```

tail -f /var/log/acpid

```

and arming/disarming the lever.

Note that the ACPI script above uses hdparm to spin down the HDD (if it's an HDD) before removal (otherwise your HDD will be emergency-powered-off, which is bad for its drive heads) and ibm-acpi to power down the device bay (I don't know how to do that for other systems).

After doing this, I have a nice icon sitting in my tray for swapping out the device as well as all necessary actions firing when I arm the lever. However this support is absolutely not perfect - sometimes the hotswap backend fails because it can't power down the controller for some reason, and obviously if you have busy files on the FS then the unmount will fail.

I can't wait for the day when the kernel maintainers get around to writing proper IDE hotswap support and there's a single standard utility for it and a KDE front-end. It shouldn't be long though, and I'll try to work on it too.

----------

## beatryder

Unfortunatley there is no acpi signal from the device.

I am considering trying to enable firewire support, on the odd chance it will work

----------

## gentuse

 *beatryder wrote:*   

> to my knowledge there are no SATA CD/DVD ROMs out there yet.

 

Technically, not a CD/DVD ROM since they are burners, but here are some SATA optical drives: http://www.newegg.com/Product/ProductList.asp?Manufactory=&PropertyCodeValue=0&PropertyCodeValue=0&PropertyCodeValue=0&PropertyCodeValue=0&PropertyCodeValue=0&PropertyCodeValue=0&PropertyCodeValue=0&PropertyCodeValue=0&PropertyCodeValue=0&PropertyCodeValue=0&PropertyCodeValue=0&PropertyCodeValue=0&PropertyCodeValue=0&PropertyCodeValue=384%3A6820&description=&MinPrice=&MaxPrice=&SubCategory=5&Submit=Property

----------

## beatryder

Yeah, after some more playing around. I have my dvdrw working with no IDE drivers, only scsi and sata

----------

## heilong

I've got ThinkPad R51 and wanted to do the same thing. My partly working solution is to pass "hdc=cdrom" kernel boot parameter. This way, if I boot without cd-rom, I've got a lot of error messages on boot, but the cd-rom works if I insert it later. Problem - CDDA seems to not work.

----------

