![“错误:磁盘外不能有分区!”即使扇区数量很好](https://linux22.com/image/97586/%E2%80%9C%E9%94%99%E8%AF%AF%EF%BC%9A%E7%A3%81%E7%9B%98%E5%A4%96%E4%B8%8D%E8%83%BD%E6%9C%89%E5%88%86%E5%8C%BA%EF%BC%81%E2%80%9D%E5%8D%B3%E4%BD%BF%E6%89%87%E5%8C%BA%E6%95%B0%E9%87%8F%E5%BE%88%E5%A5%BD.png)
我正在查看一个使用dd
SD 卡创建的图像文件,并以 Raspbian(上面有我不久前编译的 Qt 5.7)作为输入。调用时
sudo parted raspbian_jessie_qt5.7_all_modules.img unit s print
我明白了
Error: Can't have a partition outside the disk!
fdisk
我使用以下命令检查了分区
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。
我可以使用dd
withif=/dev/zeros
来扩展映像,然后扩展其中的 Linux FS,但是 1) 我不确定这是否会解决问题,2)。我真的很想坚持原始图像的大小约为。 7.7GB。
我忽略了什么想法以及如何解决它?
请注意,将映像写入 SD 卡、启动 Rasbian(SD 卡总共 32 GB)并使用它没有任何问题。
答案1
您的映像有 16267263 个扇区,但起始和结束扇区从 0 开始计数,因此您的分区将一个扇区延伸到映像末尾之外。由于图像看起来工作正常,您可以通过向其附加 512 字节来修复它。
答案2
我遇到了同样的问题,并使用相同的技术解决了它(使用dd
withif=/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