# [solved] Bad behavior on external USB disk

## Irre

Today I bought a 9.1 TiB external USB 3.1 disk. (My PC has USB 3.0)

Initial partition table was:

```
Disk /dev/sdb: 9.1 TiB, 10000831348736 bytes, 19532873728 sectors

Disk model: d2 Professional

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: gpt

Disk identifier: 6609F4FC-D2D2-4CB9-B59F-5E689E3218B3

Device      Start         End     Sectors  Size Type

/dev/sdb1      34      262177      262144  128M Microsoft reserved

/dev/sdb2  264192 19532871679 19532607488  9.1T Microsoft basic data

Partition 1 does not start on physical sector boundary.
```

Note the strange Start address for partition /dev/sdb1 

I changed this to:

```
Disk /dev/sdb: 9.1 TiB, 10000831348736 bytes, 19532873728 sectors

Disk model: d2 Professional

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: gpt

Disk identifier: 6609F4FC-D2D2-4CB9-B59F-5E689E3218B3

Device           Start         End     Sectors Size Type

/dev/sdb1         2048    41945087    41943040  20G Linux filesystem

/dev/sdb2     41945088   104859647    62914560  30G Linux filesystem

/dev/sdb3    104859648 19432212479 19327352832   9T Linux filesystem

/dev/sdb4  19432212480 19474155519    41943040  20G Linux filesystem

/dev/sdb5  19474155520 19516098559    41943040  20G Linux filesystem

/dev/sdb6  19516098560 19526584319    10485760   5G Linux swap

/dev/sdb7  19526584320 19532873694     6289375   3G Linux swap

```

dmesg tells me that Optimal transfer size is 33553920 bytes 

```
[16642.972860] sd 6:0:0:0: Attached scsi generic sg2 type 0

[16642.973156] sd 6:0:0:0: [sdb] Spinning up disk...

[16643.991697] .

[16644.696050] ACPI Debug:  "---------------------------- AC _PSR"

[16644.697630] ACPI Debug:  "---------------------------- AC on line"

[16645.015698] .........

[16653.720976] ACPI Debug:  "---------------------------- AC _PSR"

[16653.722906] ACPI Debug:  "---------------------------- AC on line"

[16654.231698] .........

[16662.742392] ACPI Debug:  "---------------------------- AC _PSR"

[16662.743787] ACPI Debug:  "---------------------------- AC on line"

[16663.447697] ....ready

[16666.528148] sd 6:0:0:0: [sdb] 19532873728 512-byte logical blocks: (10.0 TB/9.10 TiB)

[16666.528160] sd 6:0:0:0: [sdb] 4096-byte physical blocks

[16666.528290] sd 6:0:0:0: [sdb] Write Protect is off

[16666.528291] sd 6:0:0:0: [sdb] Mode Sense: 43 00 00 00

[16666.528555] sd 6:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA

[16666.529025] sd 6:0:0:0: [sdb] Optimal transfer size 33553920 bytes not a multiple of physical block size (4096 bytes)

[16666.596246]  sdb: sdb1 sdb2 sdb3 sdb4 sdb5 sdb6 sdb7

[16666.597936] sd 6:0:0:0: [sdb] Attached SCSI disk

```

I started to fill each partition with zeroes. This was the result with and without bs=33553920. Without bs the disk was extremely slow! Except for the last partition!

```
localhost ~ # dd bs=33553920 if=/dev/zero of=/dev/sdb1

dd: error writing '/dev/sdb1': No space left on device

641+0 records in

640+0 records out

21474836480 bytes (21 GB, 20 GiB) copied, 170.059 s, 126 MB/s

localhost ~ # dd  if=/dev/zero of=/dev/sdb1

dd: writing to '/dev/sdb1': No space left on device

41943041+0 records in

41943040+0 records out

21474836480 bytes (21 GB, 20 GiB) copied, 831.845 s, 25.8 MB/s

localhost ~ # dd bs=33553920 if=/dev/zero of=/dev/sdb2

dd: error writing '/dev/sdb2': No space left on device

961+0 records in

960+0 records out

32212254720 bytes (32 GB, 30 GiB) copied, 255.287 s, 126 MB/s

localhost ~ # dd if=/dev/zero of=/dev/sdb2

dd: writing to '/dev/sdb2': No space left on device

62914561+0 records in

62914560+0 records out

32212254720 bytes (32 GB, 30 GiB) copied, 1248.82 s, 25.8 MB/s

localhost ~ # dd bs=33553920 if=/dev/zero of=/dev/sdb3

^C893+0 records in

893+0 records out

29963650560 bytes (30 GB, 28 GiB) copied, 236.366 s, 127 MB/s

localhost ~ # dd if=/dev/zero of=/dev/sdb3

^C13910345+0 records in

13910345+0 records out

7122096640 bytes (7.1 GB, 6.6 GiB) copied, 276.562 s, 25.8 MB/s

localhost ~ # dd bs=33553920 if=/dev/zero of=/dev/sdb4

dd: error writing '/dev/sdb4': No space left on device

641+0 records in

640+0 records out

21474836480 bytes (21 GB, 20 GiB) copied, 199.714 s, 108 MB/s

localhost ~ # dd if=/dev/zero of=/dev/sdb4

dd: writing to '/dev/sdb4': No space left on device

41943041+0 records in

41943040+0 records out

21474836480 bytes (21 GB, 20 GiB) copied, 868.269 s, 24.7 MB/s

localhost ~ # dd bs=33553920 if=/dev/zero of=/dev/sdb5

dd: error writing '/dev/sdb5': No space left on device

641+0 records in

640+0 records out

21474836480 bytes (21 GB, 20 GiB) copied, 200.542 s, 107 MB/s

localhost ~ # dd bs=33553920 if=/dev/zero of=/dev/sdb6

dd: error writing '/dev/sdb6': No space left on device

161+0 records in

160+0 records out

5368709120 bytes (5.4 GB, 5.0 GiB) copied, 50.32 s, 107 MB/s

localhost ~ # dd bs=33553920 if=/dev/zero of=/dev/sdb7

dd: error writing '/dev/sdb7': No space left on device

96+0 records in

95+0 records out

3220160000 bytes (3.2 GB, 3.0 GiB) copied, 28.7831 s, 112 MB/s

localhost ~ # dd  if=/dev/zero of=/dev/sdb7

dd: writing to '/dev/sdb7': No space left on device

6289376+0 records in

6289375+0 records out

3220160000 bytes (3.2 GB, 3.0 GiB) copied, 29.5778 s, 109 MB/s

```

I have three important questions: 

1) Should I change Start from 2048 to 34?

2) How come last partition is "fast" even without bs=33553920? I tested several times.

3) I will use ext4 file system. Can I specify optimal  transfer size 33553920 somewhere?

Less important: 

4) Should I have kept original /dev/sdb1 partition in order to be able to install Grub boot loader?

5) Does LILO boot loader work on an external gpt-disk?Last edited by Irre on Sat Aug 24, 2019 5:03 pm; edited 1 time in total

----------

## NeddySeagoon

Irre,

 *Irre wrote:*   

> I have three important questions:
> 
> 1) Should I change Start from 2048 to 34?
> 
> 2) How come last partition is "fast" even without bs=33553920? I tested several times.
> ...

 

1) Your gpt partition table ends at block 2047. Hopefully, nothing will let you assign blocks beloy 2048 to a partition. 

The original

```
 Device      Start         End     Sectors  Size Type

/dev/sdb1      34      262177      262144  128M Microsoft reserved
```

Is Microsof doing their embrace, extend, extinguish thing.

2) Without bs=1M (or more) dd is very slow. It spends all its time making syscalls. With a 1M blocksize, the speed levels off and you see the block device speed limit.

3) The optimal transfer size reported by dmesg is not for the entire data pipe, thats why its not a integral number of physical blocks.

The kernel will do the right thing.  You can help by enabling UAS in the kernel, so you get speedups like DMA and overlapping commands. With USB3, you don't need to use USB bulk mode. 

4) You need an EFI partiton or a 2Mb raw partition if you want to install grub.

If you want EFI booting, you need a vfat filesystem for the things that the EFI firmware will read. Grub will go here too.

For BIOS booting, the  2Mb raw partition is required but mixing BIOS and GPT is a challenge.

5) As far as I know lilo does not support gpt at all.

----------

## Irre

Thank you very much NeddySeagoon. I redo everything but keep Start at 2048. I reserve two smaller partitions /dev/sdb1 and /dev/sdb2 to be used in the future for Grub and EFI experiments.   :Very Happy: 

----------

