Information wants to be free...

4096 Byte Sector Mount

Using a large hard disk of over 2TB on a USB enclosure, and then attempting to use the same disk on a regular Serial ATA interface may not work at all. The issue lies in the USB enclosure using some trick to convert 512 byte sectors to 4096 byte sectors when displaying the disk to the OS. I present here the solution to mount and read such a disk with Linux.

I have used a 4TB disk with a small partition to experiment.
When the disk is connected to the USB enclosure, Linux reports it with 4096-byte logical blocks:

usb 2-1.2: new high speed USB device using ehci_hcd and address 4
usb 2-1.2: New USB device found, idVendor=174c, idProduct=5106
usb 2-1.2: New USB device strings: Mfr=2, Product=3, SerialNumber=1
usb 2-1.2: Product: USB to ATA/ATAPI bridge
usb 2-1.2: Manufacturer: Asmedia
usb 2-1.2: SerialNumber: 30700000000000000A22
scsi9 : usb-storage 2-1.2:1.0
scsi 9:0:0:0: Direct-Access     WDC WD40 EZRZ-00WN9B0     80.0 PQ: 0 ANSI: 0
sd 9:0:0:0: Attached scsi generic sg6 type 0
sd 9:0:0:0: [sdf] 976754646 4096-byte logical blocks: (4.00 TB/3.63 TiB)
sd 9:0:0:0: [sdf] Write Protect is off
sd 9:0:0:0: [sdf] Mode Sense: 23 00 00 00
sd 9:0:0:0: [sdf] Assuming drive cache: write through
          


But when connected on the SATA interface, Linux reports it with 512-byte logical blocks:

ata6.00: ATA-9: WDC WD40EZRZ-00WN9B0, 80.00A80, max UDMA/133
ata6.00: 7814037168 sectors, multi 0: LBA48 NCQ (depth 0/32)
ata6.00: configured for UDMA/100
ata6: EH complete
scsi 5:0:0:0: Direct-Access     ATA      WDC WD40EZRZ-00W 0A80 PQ: 0 ANSI: 5
sd 5:0:0:0: [sdd] 7814037168 512-byte logical blocks: (4.00 TB/3.64 TiB)
sd 5:0:0:0: [sdd] 4096-byte physical blocks
sd 5:0:0:0: [sdd] Write Protect is off
sd 5:0:0:0: [sdd] Mode Sense: 00 3a 00 00
sd 5:0:0:0: [sdd] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
          


Attempting to mount the partition directly will fail because of the sector (block) mismatch:

# mount /dev/sdd1 /mnt/sdd1
mount: /dev/sdd1 is write-protected, mounting read-only
NTFS signature is missing.
Failed to mount '/dev/sdd1': Invalid argument
The device '/dev/sdd1' doesn't seem to have a valid NTFS.
Maybe the wrong device is used? Or the whole disk instead of a
partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?
          


To get around this, we need to use a loopback device, but first some calculations must be done, based on the start and end sectors of the partition. This data can be gotten with e.g. fdisk:

# fdisk -l /dev/sdd
Disk /dev/sdd: 3.7 TiB, 4000787030016 bytes, 7814037168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x52205024

Device     Boot Start   End Sectors  Size Id Type
/dev/sdd1         256 25855   25600 12.5M 83 Linux
          


Using 4096 byte sectors, we get the start sector at byte: 4096 * 256 = 1048576
And a byte size of: 4096 * 25600 = 104857600

Using these numbers, the partition can be mounted like so:

losetup --verbose --offset 1048576 --sizelimit 104857600 /dev/loop0 /dev/sdd
mount /dev/loop0 /mnt/loop
          


And after use, unmounted like so:

umount /mnt/loop
losetup -d /dev/loop0
          


Topic: Configuration, by Kjetil @ 17/05-2017, Article Link