Other Problems using ext2fs with external USB hard drive that has a sector size of 4096 bytes.

Hallo everybody,

I have just installed FreeBSD on my PC and I am planning to migrate to it. I have a little experience with FreeBSD and have used GNU/Linux for many years.

I have two 1 TB external USB drives that I use for backups. I would like to use them from GNU/Linux and from FreeBSD. The two disks are the same model and were bought in January 2015 and September 2015, respectively. I have used both drives for over a year now with no problem. Before trying to use them on FreeBSD, I ran a check for bad blocks and no problems were detected.

So I have partitioned both disks under GNU/Linux and formatted them with ext2fs. I can mount the first disk on FreeBSD with no problem. When I try to mount the second, I get the following error:

# mount -t ext2fs /dev/da1s1 mnt
mount: /dev/da1s1: Invalid argument


If I try to check the file system I get the following error:

# fsck_ext2fs -f -n -v /dev/da1s1
e2fsck 1.42.13 (17-May-2015)
/sbin/e2fsck: Attempt to read block from filesystem resulted in short read while trying to open /dev/da1s1
Could this be a zero-length partition?


I do not know what this error means I by searching on the web I have not found any relevant information.
Also, dmesg shows that the drive (da1) is recognized correctly, and no error appears in dmesg when I try to mount the drive.

The only difference I have noticed between the two disks is that the bad one has physical sector size 2048 while the good one has physical sector size 512. Both file systems are formatted with inode size 256.

So I have been trying to mount this disk for two days now and I am out of ideas. I would be very thankful if some user of the forum could give me some hint.
 
May be it would be better to run a file system check from Linux since ext2 comes from the Linux world. Does the output of gpart show shows some significant difference? Regarding the physical sector size I have no knowledge if this can make a difference on FreeBSD or not.
 
Hi chrbr,
https://forums.freebsd.org/members/41201/
thanks for the answer.

A file system check on Linux reports no errors.
I tried running fsck_ext2fs on FreeBSD to see if it could access the filesystem at all, but it gives:
Code:
/sbin/e2fsck -f -n /dev/da1
e2fsck 1.43.3 (04-Sep-2016)
/sbin/e2fsck: Attempt to read block from filesystem resulted in short read while trying to open /dev/da1
Could this be a zero-length partition?

The command gpart show on FreeBSD outputs:
Code:
$ sudo gpart show /dev/da0
=>        63  1953525105  da0  MBR  (932G)
          63        1985       - free -  (993K)
        2048  1953518017    1  linux-data  (932G)
  1953520065        5103       - free -  (2.5M)

$ sudo gpart show /dev/da1
=>       63  244190583  da1  MBR  (932G)
         63        193       - free -  (772K)
        256  244190390    1  linux-data  (932G)
where da0 is the good disk (512-byte physical sector size), da1 the bad one (2048-byte physical sector size).

Here is the output of gpart list:
Code:
Geom name: da0
modified: false
state: OK
fwheads: 255
fwsectors: 63
last: 1953525167
first: 63
entries: 4
scheme: MBR
Providers:
1. Name: da0s1
   Mediasize: 1000201224704 (932G)
   Sectorsize: 512
   Stripesize: 4096
   Stripeoffset: 0
   Mode: r1w1e1
   rawtype: 131
   length: 1000201224704
   offset: 1048576
   type: linux-data
   index: 1
   end: 1953520064
   start: 2048
Consumers:
1. Name: da0
   Mediasize: 1000204886016 (932G)
   Sectorsize: 512
   Stripesize: 4096
   Stripeoffset: 0
   Mode: r1w1e2

Geom name: da1
modified: false
state: OK
fwheads: 255
fwsectors: 63
last: 244190645
first: 63
entries: 4
scheme: MBR
Providers:
1. Name: da1s1
   Mediasize: 1000203837440 (932G)
   Sectorsize: 4096
   Stripesize: 0
   Stripeoffset: 1048576
   Mode: r0w0e0
   rawtype: 131
   length: 1000203837440
   offset: 1048576
   type: linux-data
   index: 1
   end: 244190645
   start: 256
Consumers:
1. Name: da1
   Mediasize: 1000204886016 (932G)
   Sectorsize: 4096
   Mode: r0w0e0

Among other things, I do not understand the differences between Stripesize, Stripeoffset, and Mode. I read that Stripesize and Stripeoffset can be related to a RAID. But I have never configured the disks as a RAID: I have bought them separately and repartitioned them several times afterwards.

I hope this information can help.
 
I might have found your post on stackoverflow and I can contribute only little. The output of gpart show and gpart list shows nothing suspicious to me. For curiosity I have tried gpart list on my system where I have two disks where one holds just a spare system. I have seem that
Code:
Mode: r0w0e0
is reported for an unmounted file system.
Code:
Mode: r1w0e1
when I mount read-only and
Code:
Mode: r1w1e2
when I mount a file system read-write. This should be better than nothing. If nothing else helps you can copy the good disk to the strange one using dd(1) as the last resort. Then they should be similar.
 
Hi,

thanks for the info. The funny thing is that I can format the "bad" disk (da1) with ufs and it works. Only extfs does not. Also, I have discovered that the two disks are completely different models: the company selling the disks just repackages different hardware using the same case. I got this information using smartctl -i:
Code:
$ sudo smartctl -i /dev/da0
smartctl 6.5 2016-05-07 r4318 [FreeBSD 11.0-RELEASE-p1 amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Seagate Samsung SpinPoint M8 (AF)
Device Model:     ST1000LM024 HN-M101MBB
Serial Number:    S31CJ9EDC00407
LU WWN Device Id: 5 0004cf 20c1a97cc
Firmware Version: 2BA30001
User Capacity:    1,000,204,886,016 bytes [1.00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    5400 rpm
Form Factor:      2.5 inches
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ATA8-ACS T13/1699-D revision 6
SATA Version is:  SATA 3.0, 6.0 Gb/s (current: 3.0 Gb/s)
Local Time is:    Sat Nov 12 11:53:54 2016 CET
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

$ sudo smartctl -i /dev/da1
smartctl 6.5 2016-05-07 r4318 [FreeBSD 11.0-RELEASE-p1 amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Western Digital Blue Mobile
Device Model:     WDC WD10JPVX-00JC3T0
Serial Number:    WD-WXQ1E945D4NJ
LU WWN Device Id: 5 0014ee 65add21b2
Firmware Version: 01.01A01
User Capacity:    1,000,204,886,016 bytes [1.00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    5400 rpm
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ACS-2 (minor revision not indicated)
SATA Version is:  SATA 3.0, 6.0 Gb/s (current: 3.0 Gb/s)
Local Time is:    Sat Nov 12 11:53:56 2016 CET
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

This info puzzles me even more: both have logical sector size 512? All other tools report 512 byte logical sector size on the good disk (da0) but for the bad disk (da1) they report 2048-byte logical sector size (fdisk on Linux) or they say they cannot detect the sector size (fdisk on FreeBSD) or they report 2048 byte sector (logical / physical?) sector size (gpart on FreeBSD).

So it seems there is something wrong with how sector size is handled / recognized on the second disk.
 
So I made another test. I have partitioned the bad disk da1 and formatted it with ufs and ext2fs. The partitioning and formatting was done entirely under FreeBSD.

After partitioning with gpart I had the following schema:
Code:
$ sudo gpart show /dev/da1
=>       63  244190583  da1  MBR  (932G)
         63        252       - free -  (1.0M)
        315  131071941    1  freebsd  (500G)
  131072256  113118201    2  linux-data  (432G)
  244190457        189       - free -  (756K)

$ sudo gpart show /dev/da1s1
=>        0  131071941  da1s1  BSD  (500G)
          0  131071941      1  freebsd-ufs  (500G)
So the ufs partition is /dev/da1s1a and the ext2fs slice is /dev/da1s2.

I formatted with
Code:
$ sudo newfs /dev/da1s1a
[output omitted]

$ sudo mke2fs /dev/da1s2
mke2fs 1.43.3 (04-Sep-2016)
Warning: could not erase sector 2: Attempt to write block to filesystem resulted in short write
Creating filesystem with 113118201 4k blocks and 28286976 inodes
Filesystem UUID: 63f9633e-2ca7-496f-bf12-f4663ba4ef45
Superblock backups stored on blocks:
   32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
   4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
   102400000

Allocating group tables: done                          
Warning: could not read block 0: Attempt to read block from filesystem resulted in short read
Warning: could not erase sector 0: Attempt to write block to filesystem resulted in short write
Writing inode tables: done                          
Writing superblocks and filesystem accounting information:    0/3453
Warning, had trouble writing out superblocks.
So, formatting with ext2fs gave warnings but seemed to complete successfully.

When I checked both filesystems I got:
Code:
$ sudo fsck_ufs -f -n /dev/da1s1a
** /dev/da1s1a (NO WRITE)
** Last Mounted on
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
2 files, 2 used, 126955735 free (23 frags, 15869464 blocks, 0.0% fragmentation)

$ sudo fsck_ext2fs -f -n /dev/da1s2 
e2fsck 1.43.3 (04-Sep-2016)
/sbin/e2fsck: Attempt to read block from filesystem resulted in short read while trying to open /dev/da1s2
Could this be a zero-length partition?

So, the ufs filesystem works ok (I have mounted it, copied a few GB of videos to it and played them) but the ext2fs keeps giving errors.

Summarizing, here is what I have found out about this disk.

Partitioning and formatting with ext2fs on Linux: OK. Afterwards: Linux can read and write while FreeBSD can neither read nor write.

Partitioning and formatting with ufs on FreeBSD: OK. Afterwards: FreeBSD can both read and write.

Partitioning and formatting with ext2fs on FreeBSD: with warnings. Afterwards: FreeBSD can neither read nor write.
 
This might be dumb question. If I understood the disk is using MBR partitions. What Linux fdisk shows for partition type ? Is it correct ?

If there are no valuable data, there is something you might try to get some clues. Try making two slices on the disk instead of one. See what happens.
 
Dear giorgiob,
this is an interesting test. May be there is some small difference in the implementation of the FreeBSD ext2fs software to the Linux version. Beside the dd(1) try I am running out of ideas.
 
This might be dumb question. If I understood the disk is using MBR partitions. What Linux fdisk shows for partition type ? Is it correct ?

If there are no valuable data, there is something you might try to get some clues. Try making two slices on the disk instead of one. See what happens.
In my last test I made two MBR partitions (slices, in FreeBSD terms, if I understand correctly) using gpart under FreeBSD. These were shown in FreeBSD as /dev/da1s1 and /dev/da1s2. Then I added a partition (/dev/da1s1a) to the first slice and formatted it using ufs. Then I tried to format the second slice (/dev/da1s2) as ext2fs under FreeBSD and it did not work.

I then rebooted to Linux and checked the disk with fdisk. Both slices were detected as /dev/sde1 (with type a5 / FreeBSD) and /dev/sde2 (with type 83 / Linux). However, both under Linux and FreeBSD the ext2fs filesystem on the second partition / slice was unreadable.

My conclusions up to now.

1. The drive works both under Linux and FreeBSD: both can partition it and format it with a native filesystem.
2. Both systems can partition the drive in a way that the other system can recognize, i.e. gpart / FreeBSD partitioning is recognized by fdisk / Linux and vice versa.
3. FreeBSD can neither create an ext2fs on this drive, nor access an ext2fs created by Linux.
4. The problem with ext2fs is restricted to this drive, since I am successfully using ext2fs under FreeBSD with another external USB drive and with an internal hard disk. Both drives have been formatted under Linux and can be accessed with no problems under FreeBSD.

The only difference that I have noticed is that the "bad" disk is reported to have a logical / physical sector size of 2048 bytes / sector. The other USB drive and the internal drive are reported to have 512 byte sectors. See also my previous posts.

So, since I know nothing about the implementations of ext2 I can only try to guess: maybe the FreeBSD implementation gets the sector size wrong and then tries to read / write on the wrong sectors. This would explain the warnings given by mkfs_ext2fs: they may be caused by using sectors out of range. Afterwards, the result is completely corrupt and unreadable to both Linux and FreeBSD.
 
Dear giorgiob,
this is an interesting test. May be there is some small difference in the implementation of the FreeBSD ext2fs software to the Linux version. Beside the dd(1) try I am running out of ideas.
I wanted to try the dd experiment but FreeBSD won't let me do it: apparently the system protects the user from overwriting a disk in this way. I may try this tonight: since it takes some time to clone a 1G disk, I may let it run during the night.
 
Copying the complete disk with dd(1) should be possible as root. None slice/partition of the disks should be mounted. I think the command should be dd if=/dev/da0 of=/dev/da1 bs=64k. Please be careful that the disks appear as intended by verification with gpart list or similar. The da1 should be similar to da0 beside the different hardware. The former content of da1 content is overwritten.
 
I suggested two slices/partitions because you mentioned bad allocation unit. One of the slices will contain bad allocation unit and the other will not. Perhaps one might behave correctly and other might not.

Also make sure that you haven't marked partition as A5 (FreeBSD) instead of 83 (Linux).
 
Back
Top