Error accessing 3TB SATA disk via USB

My Dreambox DM7080HD's internal flash chip died after 11 years, and after purchasing a DM900 I wanted to copy the movies from the old 3.5" 3 TB hard disk to the new 2.5" 5 TB SATA disk installed inside the new satellite TV receiver.

I attached the disk to my rusty old SATA-to-USB-adapter (JMicron JM20337 USB to ATA/ATAPI Bridge, USB ID 152d:2338) and connected it to the dreambox. The disk was recognized, but no partitions would be found. dmesg showed that the disk size was only 700 gigabytes instead of 3 terabytes:

usb 3-2.2: USB disconnect, device number 17
usb 3-2.2: new high-speed USB device number 18 using xhci_hcd
usb 3-2.2: New USB device found, idVendor=152d, idProduct=2338, bcdDevice= 1.00
usb 3-2.2: New USB device strings: Mfr=1, Product=2, SerialNumber=5
usb 3-2.2: Product: USB to ATA/ATAPI Bridge
usb 3-2.2: Manufacturer: JMicron
usb 3-2.2: SerialNumber: 7CC48306C0E5
usb-storage 3-2.2:1.0: USB Mass Storage device detected
scsi host0: usb-storage 3-2.2:1.0
scsi 0:0:0:0: Direct-Access     WDC WD30  WD-WCC4N30LCPEU 0A80 PQ: 0 ANSI: 2 CCS
sd 0:0:0:0: Attached scsi generic sg0 type 0
sd 0:0:0:0: [sda] 1565565872 512-byte logical blocks: (802 GB/747 GiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Mode Sense: 00 38 00 00
sd 0:0:0:0: [sda] Asking for cache data failed
sd 0:0:0:0: [sda] Assuming drive cache: write through
sd 0:0:0:0: [sda] Attached SCSI disk

fdisk also told me that the hard drive was smaller than I expected, but the partition on it was larger - but only 2TB instead of 3:

root@frm:~> fdisk -l /dev/sda
Disk /dev/sda: 746,52 GiB, 801569726464 bytes, 1565565872 sectors
Disk model:  WD-WCC4N30LCPEU
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start        End    Sectors Size Id Type
/dev/sda1           1 4294967295 4294967295   2T ee GPT

I unplugged the disk, attached it to my laptop and installed gdisk, a fdisk for GPT partitions:

root@frm:~> gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.10

Warning! Disk size is smaller than the main header indicates! Loading
secondary header from the last sector of the disk! You should use 'v' to
verify disk integrity, and perhaps options on the experts' menu to repair
the disk.
Caution: invalid backup GPT header, but valid main header; regenerating
backup header from main header.

Warning! One or more CRCs don't match. You should repair the disk!
Main header: OK
Backup header: ERROR
Main partition table: OK
Backup partition table: ERROR

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: damaged

****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************

Command (? for help): p
Disk /dev/sda: 1565565872 sectors, 746.5 GiB
Model:  WD-WCC4N30LCPEU
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): AFB7463D-B5C2-409F-86BB-C113231DDDB2
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 5860533134
Partitions will be aligned on 8-sector boundaries
Total free space is 3933 sectors (1.9 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      5858436016   2.7 TiB     0700  primary
   2      5858436017      5860531215   1023.0 MiB  8200  primary

This was when I stopped experimenting on my laptop and searched for an explanation of the wrongly reported hard drive size. I found it in an answer by Rod Smith on Ask Ubuntu:

External USB enclosures often impose 32-bit limitations on disk sector values. 2^32 sectors, times a 512-byte sector size, means that these enclosures can handle, at most, 2 TiB disks.

Frequently, the symptom of using a disk bigger than this is that the disk size is reported as the disk's true size modulo 2 TiB -- that is, your 2.73 TiB disk is reported as 0.73 TiB.

This was the problem. The JM20337 SATA-to-USB adapter was from 2003, and just doesn't support disks larger than 2TB.

Connecting the drive to a more recent 4TB video backup harddisk adapter did work, and dmesg showed the real drive size. The partition table was broken, but I could recover it with TestDisk.

Written by Christian Weiske.

Comments? Please send an e-mail.