Want to HotPlug an IDE device in Linux?
Here is how you go about it:
This can fry your devices as well as your controller. Frying your controller could make your motherboard a lot less useful. If any part of these instructions makes you uncomfortable, I would suggest just rebooting rather than taking the risk. If you are going to do this, I suggest reading this entire section before you use any of the commands..
Commands you need:
Removing an interface -
/dev/hdX needs to be a connected IDE device. It doesn't matter which interface the device is on, it is just used for the IOCTL.. if_number is the interface number - they start at 0. hd[a-b? are on interface 0, hd[b-c? are on interface 1, etc. If you are unsure how your devices are connected, you can look at 'dmesg' output (you may also want /var/log/dmesg, as the dmesg ringbuffer might not have the messages you are looking for anymore).
Be sure to unmount anything mounted on the bus before using this command! I run 'sync' a few times before doing this.. You may also find it helpful to disable dma on all drives using the bus, and put the drives to sleep (see "Doing the actual plugging/unplugging" below).
Adding an interface -
Now you need to know the IO port ranges for the device. You can get this from 'dmesg' output - it will be something like this:
ide0 at 0x1f0-0x1f7,0x3f6 on irq 14
ide1 at 0x170-0x177,0x376 on irq 15
The first numbers are the range of IO ports used. The second is the data IO port, and the third is the IRQ.
There should then be a kernel message along the lines of:
ide1 at 0x170-0x177,0x376 on irq 15
hdc: attached ide-cdrom driver.
hdc: ATAPI 32X CD-ROM CD-R/RW drive, 8192kB Cache
Doing the actual plugging/unplugging -
These are my general rules of thumb:
You want as little activity as possible on the IDE bus you are mucking with. You may wish to put all the drives on the bus to sleep with hdparm -Y. You may also want to disable DMA for all drives on the bus - you can do this with hdparm -d0. (You can turn dma back on after everything is plugged in...)
Always disconnect the power connector before the IDE cable. Be careful not to short any of the pins when plugging/unplugging the power connector, as this will probably cause your power supply to shut itself off or just cause a hard reset.
No page links to IDENotes.