Ubuntu

從 USB 機箱移動到內部時無法安裝 SATA 驅動器

  • September 15, 2016

我有 4 個外部驅動器通過 USB 連接到我的 Dell Precision 490 工作站。

它們按 uuid 位於 /etc/fstab 中,並格式化為 UUID。

UUID=04c37bff-b93e-440e-acd0-3d984ddb2ec3 /mnt/drive0 ext4 defaults,nobootwait 0 2
UUID=210765f4-30e5-4863-a40b-aa1fffefe5ca /mnt/drive1 ext4 defaults,nobootwait 0 2
UUID=b981c5e7-249e-4430-9887-96ca674e0733 /mnt/drive2 ext4 defaults,nobootwait 0 2
UUID=22c8a274-3cf9-403f-9558-feb531e407c7 /mnt/drive3 ext4 defaults,nobootwait 0 2

我在裡面放了三個驅動器,但只有一個自動安裝(驅動器3,驅動器2仍然在外部連接)

$ mount | grep /dev/sd
/dev/sdc1 on /boot type ext2 (rw)
/dev/sdb1 on /mnt/drive3 type ext4 (rw)
/dev/sdf1 on /mnt/drive2 type ext4 (rw)

但他們都出現了:

$ sudo fdisk -l
WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sda: 120.0 GB, 120034123776 bytes
<snip>

Disk /dev/sdb: 5001.0 GB, 5000981078016 bytes
255 heads, 63 sectors/track, 608001 cylinders, total 9767541168 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
Disk identifier: 0xdd494cbf

  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1  4294967295  2147483647+  ee  GPT
Partition 1 does not start on physical sector boundary.

Disk /dev/sdd: 5001.0 GB, 5000981078016 bytes
42 heads, 62 sectors/track, 3750975 cylinders, total 9767541168 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
Disk identifier: 0xec15dda8

  Device Boot      Start         End      Blocks   Id  System
/dev/sdd1             256  1220942644   610471194+  83  Linux

Disk /dev/sde: 5001.0 GB, 5000981078016 bytes
255 heads, 63 sectors/track, 608001 cylinders, total 9767541168 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
Disk identifier: 0x4cd5215a

  Device Boot      Start         End      Blocks   Id  System
/dev/sde1              63  1220942644   610471291   83  Linux
Partition 1 does not start on physical sector boundary.

Disk /dev/sdc: 500.1 GB, 500107862016 bytes
<snip>

Disk /dev/sdf: 5001.0 GB, 5000981073920 bytes
255 heads, 63 sectors/track, 76000 cylinders, total 1220942645 sectors
Units = sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x6b6805d9

  Device Boot      Start         End      Blocks   Id  System
/dev/sdf1              63  1220942644   588803032   83  Linux

$ ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sdb  /dev/sdb1  /dev/sdc  /dev/sdc1  /dev/sdc2  /dev/sdc5  /dev/sdd  /dev/sdd1  /dev/sde  /dev/sde1  /dev/sdf  /dev/sdf1

如果我嘗試正常安裝:

$ sudo mkdir /mnt/temp
$ sudo mount -t ext4 /dev/sde1 /mnt/temp                                                                                                    
 mount: wrong fs type, bad option, bad superblock on /dev/sde1,
  missing codepage or helper program, or other error
  In some cases useful info is found in syslog - try
  dmesg | tail  or so
$ dmesg | tail
[87143.301150] EXT4-fs (sde1): VFS: Can't find ext4 filesystem
[87295.537835] EXT4-fs (sde1): VFS: Can't find ext4 filesystem
[87315.780147] EXT4-fs (sde1): VFS: Can't find ext4 filesystem
[87315.780290] EXT4-fs (sde1): VFS: Can't find ext4 filesystem
[87315.780421] EXT4-fs (sde1): VFS: Can't find ext4 filesystem

這台機器有 5 個 SATA 埠,我還買了一個 PCIe SATA 控制器並試了一下。沒有不同。在埠之間移動設備仍然沒有區別。其他兩個驅動器始終掛載。

我用 USB 控制器將它們放回各自的外殼中,它們就可以工作了。儘管當我嘗試使用其中一個直接連接安裝的驅動器時,它無法辨識。

謝謝!

編輯:從 gdisk 添加輸出

$ sudo gdisk /dev/sde
GPT fdisk (gdisk) version 0.8.8

Partition table scan:
 MBR: MBR only
 BSD: not present
 APM: not present
 GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************


Command (? for help): p
Disk /dev/sde: 9767541168 sectors, 4.5 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): 00C22148-8C82-4062-BEC5-6759E7E23856
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 9767541134
Partitions will be aligned on 8-sector boundaries
Total free space is 8546598519 sectors (4.0 TiB)

Number  Start (sector)    End (sector)  Size       Code  Name
  1              63      1220942644   582.2 GiB   8300  Linux filesystem

$ sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.8

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

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/sdb: 9767541168 sectors, 4.5 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): E76C335B-FBA1-4FE0-9DC2-C5CADBECA6B0
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 9767541133
Partitions will be aligned on 8-sector boundaries
Total free space is 0 sectors (0 bytes)

Number  Start (sector)    End (sector)  Size       Code  Name
  1              34      9767541133   4.5 TiB     8300  disk4

有趣的是,看起來不掛載的磁碟使用 MBR 而不是 GPT?

這聽起來像https://superuser.com/questions/679725/how-to-correct-512-byte-sector-mbr-on-a-4096-byte-sector-disk中描述的問題:USB 外殼報告了一個與主機板不同的扇區大小,因此分區表的解釋不同。

我從 USB 機箱移動到內部 SATA 埠的 4TB 磁碟也有類似的問題。顯然 USB 外殼報告了 4k 扇區,因此我能夠使用老式 MBR 分區表來創建 4TB ext4 分區。通過SATA連接磁碟後,再沒有找到ext4分區,顯然是因為現在磁碟訪問了512B扇區。

我使用 Ubuntu 中提供的Testdisk數據恢復工具通過以下步驟解決了這個問題:

  • 為安全起見,創建了原始分區表 ( sfdisk -d /dev/sdb > sfdisk-sdb.txt)的備份
  • 用於testdisk /dev/sdb查找原始 ext4 文件系統
  • 讓 testdisk 將新的 MBR 分區表寫入磁碟
  • 由於 MBR 表不支持 4TB 分區,所以 ext4 分區仍然無法掛載,報錯EXT4-fs (sdb1): bad geometry: block count 976751744 exceeds size of device (536870911 blocks)
  • 用於gdisk /dev/sdb將 MBR 轉換為 GPT 格式,並將 GPT 寫入磁碟
  • 再次用於testdisk /dev/sdb查找原始 ext4 文件系統(它檢測到錯誤的文件系統類型但沒關係),並讓它將新的 GPT 表寫入磁碟
  • 用於gdisk /dev/sdb將錯誤檢測到的文件系統類型更改為8300

也許我很幸運,但是在這個過程之後,可以像往常一樣掛載 ext4 文件系統。fsck -f /dev/sdb1沒有檢測到任何錯誤,blkid /dev/sdb1並且tune2fs /dev/sdb1給出了與使用 USB 外殼時相同的結果。

引用自:https://serverfault.com/questions/764271