Wednesday, June 6, 2012

Why don't we have Target Disk Mode for non-Apple machines?

I'm not an Apple fan, but there's one thing that consistently makes me really jealous about their hardware.

Despite generally scary-buggy EFI firmwares in their Intel CPU based machines, Apple's firmwares support what they call Target Disk Mode. This is a tech support and service dream, and has been supported since Apple moved over to "New World" PowerPC machines with their Forth based OpenFirmware, ie for a very long time.

Target disk mode is great for data recovery, OS repairs, OS reinstalls, disk imaging, backups, accessing data on laptops with broken displays without having to rip the HDD out of them, and lots else. It's just great. Unless you have an Apple you don't get it, and there's no longer any good reason for that.

UPDATE July 2012: Kernel Newbies reports that support for exporting SCSI over USB and FireWire has been merged into the Linux kernel. This will make it much easier to produce bootable USB keys that export the host system's hard drives. Unfortunately it's useless with most machines as it appears to require a USB gadget or OTG port, or a FireWire port.


What the hell is target disk mode?

Hold the "T" key down on the keyboard of a mac during boot, and instead of loading the operating system it'll load a simple firmware that exports any attached hard drive(s) over the Mac's FireWire ports, making the Mac behave like a FireWire external hard drive. Plug any computer into the mac that's in target disk mode and you can see each HDD on the mac over FireWire. You can format and repartition the drives, install the OS onto them (!!), back them up, whatever you want. You can also use the target mac's CD/DVD drive(s) as if they were FireWire external CD/DVD drives, which is great if you have a tiny netbook or similar optical-drive-less machine.

There's simply no equivalent for "Wintel" (non-Apple Intel based) PC hardware. You have to boot an OS, whether Windows, Linux, or something else, and then export the drive(s) over a network protocol block protocol like iSCSI/ATAoE/NBD, or a network file system protocol like SMB/NFS, all via Ethernet. Iif you're lucky and have a FireWire port via firewire-sbp-target using Linux, but you still have to boot an OS and have somewhere to boot it from like a CD or USB key.

The closet a non-Apple machine can come to target disk mode is booting a micro Linux distro off a CD or USB key, one that loads the kernel, initrd, and file system entirely into RAM so it doesn't need to use the storage device after boot. The micro distro can export disks over SMB/CIFS, NFS, NBD, iSCSI, FireWire if you have it, or whatever else you feel like. Alas, booting off USB storage is very flakey on most PCs even today so it won't work half the time, and booting off an optical drive requires that you have one. Both require you to be able to cause the machine to boot from a non-default device, which may not be possible especially when dealing with a broken-display laptop or similar.

Why don't non-Apple PCs have target disk mode?

There's no longer any good reason.

Reasons used to be numerous:

  • The old PC BIOS (Award BIOS, Phoenix BIOS, etc) is a horrifying legacy monstrosity that's largely hand written in 16-bit assembler and is limited to using 1MB of the system's RAM. Modifying BIOSes is a black art, and they're mostly just hacked until Windows boots then shipped half-broken and buggy. The addition of extensions like the DMI, and of ACPI, have just made BIOSes scarier. Adding something like target disk mode would be nigh impossible.
  • Most PCs only had plain old host-mode USB ports and Ethernet. No IEEE 1394 (FireWire), no Light Peak ("Thunderbolt"), no USB OTG. Standard USB host mode ports are incapable of being connected to another USB host mode port (in fact, it'll damage them), so you can't plug two computers together over USB without a funky smart cable that bridges the two. Even then it requires drivers because there's no standard USB class driver for a host to export storage to a "gadget", which is what USB calls anything that isn't a host. Needless to say, "target disk mode" was impossible with these hardware limitations.
  • Hard drives used to be IDE/PATA devices without even ATAPI command support that spoke a rather clunky series of PIO/DMA/UDMA protocols that required a lot of interaction from the operating system to work. It wouldn't prevent target disk mode being implemented (Apple did it just fine with IDE hard drives) but it did make it more complicated.
  • Every Ethernet controller had a different and incompatible interface to the host hardware, firmware and OS that required drivers specific to each Ethernet controller. No standard existed for firmware-level drivers; the closest thing was PXE and that was an extremely limited environment focused on network booting. This would've meant yet more engineering effort to support something like target-disk-over-ethernet with a plain old PC BIOS, or the use of hacks like booting to an on-firmware micro Linux OS for the job.

None of those excuses apply to modern PC hardware

  • The PC BIOS is finally dead, and has been replaced with EFI in most new computers, mainly UEFI on PC-like hardware. Most computers (U)EFI firmwares still emulate a regular PC BIOS so they can continue to boot old operating systems; important since Windows 7 is the first Windows to support EFI booting, and while Linux has supported EFI since its introduction that support continues to mature slowly. BIOS is finally dead though; my new Lenovo T420 lets me turn off legacy BIOS entirely in EFI setup, and having done so I can still boot and use Fedora 17 and Windows 7 fine. EFI is still kind of insane since it's an Intel standard from the people who bought us the horror of ACPI, but at least it's a modular firmware written in real C. EFI is perfectly capable of hosting something like target disk mode, and in fact all Intel-based Apple computers have EFI firmwares with target disk mode support.
  • Modern hard drives and CD/DVD drives are all serial ATA (SATA) devices, which speak a relatively sane packetized protocol that's easy to tunnel through USB, FireWire, or whatever other packet protocol you want. Converting between the USB mass storage class protocol and SATA is trivial, so exposing SATA hard drives and CD/DVD drives over USB OTG should be a simple matter.
  • USB's one-way limitation has been partially lifted by USB OTG ("USB On the Go"), a standard that allows a USB device to switch between being a host-mode and gadget-mode device using host negotiation protocol (HNP). This lets device makers do peer-to-peer connectivity without having to add additional expensive, royalty-bearing additional ICs like a 1394(FireWire) controller or LightPeak(Thunderbolt) controller. With USB OTG a PC no longer needs extra-cost FireWire or Thunderbolt ports to be capable of acting as a target disk, though it'll still perform much better if you have such interfaces available.

  • PC firmwares are insanely powerful now. Check out what Intel AMT can do. Target disk over Ethernet seems a no-brainer in comparison.





  • UEFI specifies a standard driver interface for Ethernet. Every Ethernet part should come with a UEFI driver now, and the EFI firmware doesn't have to care what specific Ethernet controller is on a board so long as a driver exists. This makes it much easier for firmware developers to offer functionality over Ethernet. It isn't as good as the originally planned requirement for all Ethernet cards to implement a common interface - like VESA for video or AHCI for storage controllers - but it's good enough to make adding network functionality to firmwares easy.

Yet we still don't have target disk mode

The hardware is capable, or can be made to be capable with simple changes to the USB host controllers that are part of every standard chipset made by Intel, nVidia, VIA, SiS and AMD. The firmware is capable, all it needs is a suitable EFI module. Yet no target disk mode do we have, and it's way past time.

Remaining barriers

USB3 OTG isn't widely adopted and there's no full-size, USB-A backward compatible mechanically robust connector

Part of the problem is the slow adoption of USB OTG. Most laptop and desktop chipsets don't have USB OTG support built in, and I've never seen a laptop or desktop with a USB OTG capable Micro-AB USB connector. USB OTG remains largely restricted to phones and tablets. Having at least one USB OTG capable Micro-AB plug isn't too much of an ask, and even makes more sense than full-size A type ports on space-sensitive small laptops. It's a real pity that USB OTG doesn't support the full size A-type connector and cable because these are way more mechanically robust than the tiny little Micro-AB connector is, and are already universally adopted. They couldn't retrofit it backward compatibly which is a shame, but they could've at least specified a full size AB USB3 connector that'd be backward compatible with old A plugs and keep the mechanical robustness of the full size sockets.

Ethernet isn't well suited for exposing raw block devices

While we could have something like target disk now over the built-in Ethernet port on basically every laptop, Ethernet isn't very good for the job. There's no simple, widely adopted standard for exposing block devices over Ethernet, bandwidth isn't great, security is a concern, and it isn't really designed for direct peer-to-peer links.

  • Block Protocols: iSCSI is widely adopted, but it's not simple to configure or use. It's a big complicated spec that'd make it hard to implement a simple iSCSI target in firmware. AoE / ATA-over-Ethernet is simple, low overhead, and fast, but not particularly widely adopted (in particular, there aren't any drivers built in to Microsoft Windows) and it's a loose de-facto standard pushed by one company. The NBD protocol is a largely Linux-specific protocol with no client support for Windows at all. I'd love to see ATAoE adopted for target disk over Ethernet, but it's not widely known or accepted so there'd be some resistance there.
  • File protocols like SMB/CIFS, NFS, etc aren't well suited for firmware level "target disk" because they don't offer raw block-by-block access, and the firmware has to understand the file system(s) on the disk in order to export the protocol.
  • Even now, not all Ethernet MAC/PHY implementations support auto-MDIX, which is required to allow two computers to be connected directly via an ordinary Ethernet cable. Unless at least one of the computers supports Auto-MDIX you need a special crossover Ethernet cable with different wiring to connect the two computers together!
  • Because 10/100/1000 (Gigabit) Ethernet is power-hungry and somewhat more expensive to make, it's commonplace for power-sensitive devices like laptops to only have 10/100 Fast Ethernet ports. Sometimes they have a Gigabit ethernet controller on the chipset, but only a 100 megabit capable PHY to save power. 10/100 Ethernet can only transfer 8-10 megabytes of data per second, which isn't much good for something like target disk mode.

LightPeak/Thunderbolt may be royalty free, but it isn't cheap

Unlike FireWire, the new Intel Thunderbolt / Light Peak has no per-port, per-host or per-chip royalties. The only barrier to adoption is the high cost of the controller chip and ports. Alas, right now that cost is high enough that we won't be seeing the new interface appearing on everything for quite some time yet.

What's going to be needed is for Intel to integrate Light Peak onto its host chipsets, the same core parts that provide USB support. Until adding Light Peak is a low marginal cost for OEMs, they're not going to do it. I doubt that Intel can cost-effectively integrate Light Peak onto its main chipsets yet, but if it isn't working on it I'll be amazed.

For now, no target disk

My three-year old Intel-motherboard PC should be capable of target disk mode but for the lack of USB OTG, FireWire, or Light Peak. There's no reason it couldn't export its HDD and DVD drive over the Ethernet port with iSCSI, which every modern Windows OS and any non-prehistoric Linux supports connecting to. It could easily support FireWire if an add-in FireWire PCI/PCIe card was detected, since almost all FireWire cards have the standard FireWire OHCI host interface so no card-specific drivers are required. It is an EFI firmware machine; I'm running 64-bit Windows 7 and Fedora 17 on it with GPT partition tables and EFI boot. All it needs is the firmware support for target disk, even for this somewhat older PC.

My new Lenovo T420 arrived today. It has a full EFI firmware and even lets me turn off legacy BIOS entirely. Suspend and resume are instant. It supports EFI applications. DisplayPort is supported. It's a seriously modern laptop (except for the weird lack of USB3 support) ... but it has no USB OTG Micro-AB port, no FireWire, no Light Peak, and no firmware support for any kind of target disk. You know what it does have, though? A F***ing VGA port! What a shameful waste of space that could've been turned to something useful.

Intel, pull your thumb out and start including target disk in the EFI firmwares you provide for OEMs (and use in your own products). It's past time.

3 comments:

  1. There is such a solution...Paragon Software is evaluation UEFI iSCSI target:
    http://blog.paragon-software.com/?p=2405

    ReplyDelete
    Replies
    1. Ivan: That's very cool, and great to know about.

      It illustrates the unfortunate limitations of (U)EFI, though, in that step 2 of your process is "Boot from Paragon uEFI iSCSI Target recovery USB stick". Vendors make it difficult or impossible to add UEFI applications to the firmware's storage, they have to be on a disk somewhere, which is a PITA.

      Additionally, as noted above iSCSI is kind of crap for this sort of work, not least because it relies on Ethernet. It's a fantastic facility to have, but not that different to what Intel are already offering with vPro/AMT, and it's worlds different from the plug-and-go of target disk mode. It also doesn't usually work well if you want to use another machine's CD/DVD-ROM or other non-HDD devices, and one of the shiny things about Apple's target disk mode is that you can use another machine's optical drives etc as if they were your own externals.

      A very handy option to know about though, thanks.

      Delete
  2. Great article- I've always wondered about this. I support a 50/50 mix of Windows and Apple machines and the lack of target disk mode on PCs is terribly frustrating. Especially when it's a Fort Knox of a laptop you have to tear the hard drive out of!

    ReplyDelete