Hotplugging and using IEEE 1394 (firewire) disks on Linux September 16, 2002 Hardware: Dell Optiplex Maxtor 1394 PCI Adapter Card (PN K01PC1394A) ($40) or SIIG 1394 3-Port PCI i/e (PN NN-440012) -- ($48) (same results with each) Maxtor IEEE 1394 disk drive (previously formatted with EXT2 filesystem) [Note: also works on emperor where it appears as /dev/sda1]. Software: RedHat Linux 7.3 Kernel 2.4.18-3 hotplug-2002_04_01-3 hotplug resources: http://linux-hotplug.sourceforge.net/ Overview: From "man hotplug(8)" /proc/sys/kernel/hotplug -- specifies hotplug program path /sbin/hotplug -- hotplug program (default path name) /etc/hotplug/* -- hotplug files /etc/hotplug/NAME.agent -- hotplug system-specific agents X /etc/hotplug/NAME* -- subsystem-specific files, for agents X /etc/hotplug/NAME/* -- driver setup scripts, invoked by agents X /etc/init.d/hotplug -- hotplug system service script The above files marked X do not exist, or do not exist for ieee1394. /proc/sys/kernel/hotplug contains the name of the program to invoke when something is hotplugged. This contains "/sbin/hotplug". /sbin/hotplug is a BASH script. When an IEEE1394 device is plugged/ unplugged, this script invokes /etc/hotplug/ieee1394.agent. /etc/hotplug/ contains hotplug modules for USB, PCI, ieee1394, etc. /etc/hotplug/ieee1394.agent is a BASH script. It is invoked with parameters describing the action to take, and vendor ID and other particulars of the device involved. When a disk is connected, it is invoked with action "add". When the disk is disconnected, it is invoked with action "remove". (for testing purposes, I added a line to ieee1394.agent so that it logs the action each time it is called. The following modules are used to access the disk. Noted in the order they are loaded. ieee1394 ohci1394 sbp2(?) Connecting and recognizing the disk. After system fresh system reboot, kernel doesn't know anything about ieee1394 disks -- whether or not any devices are connected. If drive is not connected: #modprobe -v ohci1394 This loads both ieee1394 and ohci1394. /var/log/messages shows: kernel: ohci1394: $Revision: 1.80 $ Ben Collins kernel: ohci1394_0: OHCI-1394 1.0 (PCI): IRQ=[9] MMIO=[fafff000-fb000000] Max Packet=[2048] Now, apply power to disk drive, then connect firewire data cable. /var/log/messages shows (1st line is from my mod. to ieee1394.agent): logger: ieee1394.agent: action is add /etc/hotplug/ieee1394.agent: Setup sbp2 for IEEE1394 product 0x0010b9/0x00609e/0x010483 kernel: ieee1394: sbp2: Driver forced to serialize I/O (serialize_io = 1) kernel: ieee1394: sbp2: Node 0:1023: Max speed [S400] - Max payload [2048] kernel: scsi2 : IEEE-1394 SBP-2 protocol driver kernel: Vendor: Maxtor Model: 1394 storage Rev: v1.0 kernel: Type: Direct-Access ANSI SCSI revision: 06 kernel: Attached scsi disk sdb at scsi2, channel 0, id 0, lun 0 kernel: SCSI device sdb: 120103200 512-byte hdwr sectors (61493 MB) kernel: sdb: sdb1 #cat /proc/scsi/scsi shows that the maxtor disk has been seen and is available (as /dev/sdb in this case). Disk can now be accessed, formatted with fdisk, mounted, exercised, etc. (Note: running "parted /dev/sdb" causes system to hang, then crash. Note 1: If disk is connected before we load ohci1394, then everything is the same -- when ohci1394 is loaded, it immediately reognizes the disk, sets up the sbp2 driver, and adds it to /proc/scsi/scsi. Note 2: If we manually load ieee1394 by itself, there are no messages in /var/log/messages (or in dmesg). If we then connect the disk, there are still no messages. ohci1394 must be loaded before anything interesting seems to happen. Disconnecting and unrecognizing a disk: After umounting the disk, we want to remove it. First, disconnect data cable. /var/log/messages shows that ieee1396.agent was called with argument "remove" (my addition to ieee1394.agent). #cat /proc/scsi/scsi still shows the disk as present #modprobe -r -v ohci1394 unloads ohci1394 #cat /proc/scsi/scsi shows disk is gone #modprobe -r -v ieee1394 refuses: device or resource busy Reconnect data cable #modprobe -v ohci1394 /var/log/messages shows that ieee1396.agent was called with argument "remove" #cat /proc/scsi/scsi fails to find disk. System must be rebooted to find disk. ------------------------------------- Working toward automation: if we put this in /etc/fstab: /dev/sdb1 /local/fire vfat user Then any user can mount/umount the vfat disk -- all files will be readable by world, writable only by user. On system startup, /dev/sdb1 does not exist. Mount gives an error message, but continues with no problem. ------------------------------- IEEE1394 and WIndows 2000: Installed Maxtor PCI card in Mason (Dell Dimension, WIndows 2000) Log on to Mason Connect a firewire drive previously formatted and loaded on another PC Window pops up showing drive H: All files are accessible USE ICON IN TRAY IN LOWER RIGHT to stop disk before disconnecting! ------------------------------- Linux/Windows interoperability and formatting issues: Maxtor HDs come formatted with a single Windows VFAT32 partition. This can be read and written from linux, but: -> file ownership/protection doesn't really exist in the unix sense Still, I would stay with vfat for maximum flexibility for synchrotron trips. It is easy enough to repartition the disk for linux ext3 filesystem, (but see caveats below): Use "fdisk /dev/sdb" to invoke fdisk (assuming sdb is correct) Use "p" to print current partition list Use "t" to change a partition. -- tell it "1" to change partition 1 -- tell it "83" which is the hex ID for linux partition Use "w" to write partition table and exit Use "mkfs -t ext3 /dev/sdb1" to create an ext3 filesystem CAVEATS: 1) You can probably use sfdisk or cfdisk instead, but DO NOT use parted, which will hang/crash the system. 2) The reformatted disk won't be recognized on a W2K system. You can't even reformat the disk on W2K, because W2K will refuse to acknowledge that it exists. Bringing us to the next section: Reformatting the disk for Windows. -- We want to use the FAT32 filesystem, for maximum interoperability between windows and linux. On the linux system, use the repartitioning method described above, except use "b" instead of "83" for the hex partition code. Now, you can : # mkfs.vfat -F 32 -v /dev/sdb1 This takes a few seconds. Now you can mount and access the disk. I tried using the flag "-S 8192" to override the default sector size of 512. Mount did not work, and I did not explore the options for mount. Using the defaults, creating a 1GB file took 10MB/sec, reading it was 20MB/sec. Note that after reformatting the disk with fdisk, I could no longer list the partition table with "fdisk -l /dev/sdb1", but I could run fdisk to change parameters. You can now move the disk drive to a W2K system, which will recognize the filesystem. Reading and writing both go at about 20MB/sec. You can reformat the hard drive as FAT32. Quick format does not work. Regular format takes about 40 minutes. Then it says, "unable to complete the format."