我正在尝试自动创建原始磁盘映像。我不太关心 C/H/S,但块大小应该是 512 字节的粗略标准。但是,我无法指定分区的正确尺寸,以便 sfdisk 可以导入它们。
我首先创建了一个32MB的空白文件:
$dd if=/dev/zero of=disk.img bs=1M count=32
然后我使用 cfdisk 对其进行分区:
$cfdisk -h 255 -s 63 -c 4 disk.img
- 验证 cfdisk 是否看到 C/H/S 开关(在屏幕顶部)
- 创建新分区 32.5MB,结尾磁盘(为稍后的启动留出空间)
- 写
- 辞职
然后我输出一个 sfdisk 转储:
$sfdisk -H 255 -S 63 -C 4 -d disk.img > disk.parts
并得到以下内容(在 disk.parts 中):
# partition table of disk.img
unit: sectors
disk.img1 : start= 1276, size= 64260, Id=83, bootable
disk.img2 : start= 0, size= 0, Id= 0
disk.img3 : start= 0, size= 0, Id= 0
disk.img4 : start= 0, size= 0, Id= 0
但是,当我尝试将其重新加载到映像中(作为测试)时,sfdisk 似乎首先在读取原始分区表时接受 C/H/S 开关,然后在尝试计算新分区表时将它们丢弃:
$sfdisk -H 255 -S 63 -C 4 disk.img < disk.parts
Warning: disk.img is not a block device
Disk disk.img: cannot get geometry
Disk disk.img: 4 cylinders, 255 heads, 63 sectors/track
Old situation:
Warning: The partition table looks like it was made
for C/H/S=*/21/16 (instead of 4/255/63).
For this listing I'll assume that geometry.
Units = cylinders of 172032 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start End #cyls #blocks Id System
disk.img1 * 3+ 195- 192- 32130 83 Linux
start: (c,h,s) expected (3,16,13) found (0,20,17)
end: (c,h,s) expected (195,0,16) found (4,20,16)
disk.img2 0 - 0 0 0 Empty
disk.img3 0 - 0 0 0 Empty
disk.img4 0 - 0 0 0 Empty
New situation:
Warning: The partition table looks like it was made
for C/H/S=*/21/16 (instead of 4/255/63).
For this listing I'll assume that geometry.
Units = sectors of 512 bytes, counting from 0
Device Boot Start End #sectors Id System
disk.img1 * 1276 65535 64260 83 Linux
start: (c,h,s) expected (3,16,13) found (0,20,17)
end: (c,h,s) expected (195,0,16) found (4,20,16)
disk.img2 0 - 0 0 Empty
disk.img3 0 - 0 0 Empty
disk.img4 0 - 0 0 Empty
Warning: partition 1 does not end at a cylinder boundary
end of partition 1 has impossible value for cylinders: 4 (should be in 0-3)
sfdisk: I don't like these partitions - nothing changed.
(If you really want this, use the --force option.)
看起来这两部分是有冲突的:
Warning: The partition table looks like it was made
for C/H/S=*/21/16 (instead of 4/255/63).
For this listing I'll assume that geometry.
Units = cylinders of 172032 bytes, blocks of 1024 bytes, counting from 0
和
For this listing I'll assume that geometry.
Units = sectors of 512 bytes, counting from 0
然后用以下语句来强化它:
end of partition 1 has impossible value for cylinders: 4 (should be in 0-3)
我尝试了 -f(强制),它给出了完全相同的输出。:-(
为什么 sfdisk 不能正确处理它自己的转储格式,特别是当我已经给它提供了它需要的所有信息时?为什么它在读取时会处理 C/H/S,但在写入时却不会?C/H/S 不在文件中,那么为什么它会说它看起来是为*/21/16?
更重要的是,我该如何解决这个问题,以便我可以在脚本中生成分区表?
答案1
C/H/S 已经过时了,不应该使用。我对 sfdisk 不是很熟悉,但任何最近的分区工具都应该允许您以 512 字节扇区的形式指定分区边界,并且出于性能原因,它们应该始终是 4k 对齐的(因此可以被 8 整除)。
您似乎遇到的具体问题是 sfdisk 无法检测图像文件上的 C/H/S(因为它不是块设备)并最终得到虚假值。