Filesystems

“錯誤:磁碟外不能有分區!”即使扇區數很好

  • March 21, 2018

我正在查看一個圖像文件,該文件是使用dd帶有 Raspbian(我不久前編譯的 Qt 5.7)作為輸入的 SD 卡創建的。呼叫時

sudo parted raspbian_jessie_qt5.7_all_modules.img unit s print

我明白了

Error: Can't have a partition outside the disk!

fdisk我使用using檢查了分區

sudo fdisk -lu rasp_jessie_qt5.7.img

具有以下輸出

Disk rasp_jessie_qt5.7.img: 7.8 GiB, 8328838656 bytes, 16267263 sectors
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: 0x65a3fac2

Device                 Boot  Start      End  Sectors  Size Id Type
rasp_jessie_qt5.7.img1        8192   131071   122880   60M  c W95 FAT32 (LBA)
rasp_jessie_qt5.7.img2      131072 16267263 16136192  7.7G 83 Linux

當我看到這個時,我有16267263 個扇區作為上限,而 Rasbian 所在的 FS 在第16267263 個扇區結束(即在可用上限的邊緣)。扇區總數為16136192

我可以使用ddwithif=/dev/zeros來擴展映像,然後在其中擴展 Linux FS,但 1)我不確定這是否能解決問題和 2)。我真的很想堅持大約原始圖像的大小。7.7GB。

我忽略了什麼以及如何解決它的任何想法?

請注意,我將圖像寫入 SD 卡、啟動我的 Rasbian(SD 卡總共 32GB)並使用它沒有問題。

您的映像有 16267263 個扇區,但起始扇區和結束扇區從 0 開始計數,因此您的分區在映像末尾之外擴展了一個扇區。由於圖像看起來工作正常,您可以通過向其附加 512 個字節來修復它。

我遇到了同樣的問題並使用相同的技術解決了它(使用ddwithif=/dev/zeros來擴展圖像)。我發布命令僅供將來參考:

user@host $  sudo fdisk -l -u=sectors hdd.img
Disk hdd.img: 465.8 GiB, 500107861504 bytes, 976773167 sectors
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: 0x8342379a

Device   Boot     Start       End   Sectors  Size Id Type
hdd.img1 *         2048    718847    716800  350M  7 HPFS/NTFS/exFAT
hdd.img2         718848 210434047 209715200  100G  7 HPFS/NTFS/exFAT
hdd.img3      210434048 211435519   1001472  489M 83 Linux
hdd.img4      211435520 976773167 765337648  365G 8e Linux LVM

user@host $  sudo parted hdd.img unit s print
Error: Can't have a partition outside the disk!
Ignore/Cancel? Ignore                                                     
Error: Can't have a partition outside the disk!
Ignore/Cancel? Ignore                                                     
Model:  (file)
Disk hdd.img: 976773167s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start       End         Size        Type     File system  Flags
1      2048s       718847s     716800s     primary  ntfs         boot
2      718848s     210434047s  209715200s  primary  ntfs
3      210434048s  211435519s  1001472s    primary  ext2
4      211435520s  976773167s  765337648s  primary               lvm

用於dd添加一個 512 字節的扇區:

dd if=/dev/zero bs=512 count=1 >> hdd.img

之後parted確實停止給出錯誤:

user@host $  sudo fdisk -lu hdd.img
Disk hdd.img: 465.8 GiB, 500107862016 bytes, 976773168 sectors
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: 0x8342379a

Device   Boot     Start       End   Sectors  Size Id Type
hdd.img1 *         2048    718847    716800  350M  7 HPFS/NTFS/exFAT
hdd.img2         718848 210434047 209715200  100G  7 HPFS/NTFS/exFAT
hdd.img3      210434048 211435519   1001472  489M 83 Linux
hdd.img4      211435520 976773167 765337648  365G 8e Linux LVM

user@host $  sudo hdd.img unit s print
Model:  (file)
Disk hdd.img: 976773168s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start       End         Size        Type     File system  Flags
1      2048s       718847s     716800s     primary  ntfs         boot
2      718848s     210434047s  209715200s  primary  ntfs
3      210434048s  211435519s  1001472s    primary  ext2
4      211435520s  976773167s  765337648s  primary               lvm

引用自:https://unix.stackexchange.com/questions/319922