
fdisk
我正在嘗試使用(util-linux,v2.31.1)對 1440 KiB 軟碟映像進行分割。
然而,無論我使用什麼單位,該工具似乎都添加了一個 512 位元組的扇區,而且我無法分辨為什麼。
這就是我所做的:
Created a new DOS disklabel [...]
Command (m for help): n
[...]
First sector (1-2879, default 1): 2048
Last sector, +sectors or +size{K,M,G,T,P} (63-2879, default 2879): +1K
Created a new partition 1 of type 'Linux' and of size 1.5 KiB.
哇!1.5KB!
我嘗試使用扇區數,得到相同的結果:
Last sector, +sectors [...]: +2
Created a new partition 1 of type 'Linux' and of size 1.5 KiB.
現在,如果我使用足夠大的文件,則fdisk
與第一個表示法的行為不同:
First sector (2048-131071, default 2048): 2048
Last sector, [...]: +1K
Created a new partition 1 of type 'Linux' and of size 1 KiB.
第二個則不然:
Last sector, +sectors [...]: +2
Created a new partition 1 of type 'Linux' and of size 1.5 KiB.
這是預期的行為嗎?我想是的,但是為什麼呢?
答案1
然而,該工具似乎添加了一個 512 位元組扇區,無論我使用什麼單位,
...
現在,如果我使用足夠大的文件,fdisk 的行為與第一個符號不同:
...
這是預期的行為嗎?
顯然是的,並且似乎是“加一”品種的錯誤。
當您為 指定“+N”或“+”(而不是絕對扇區號)時last sector
,該實用程式似乎利用該數量作為新分區中的扇區數(或大小),並將該數字添加到起始扇區號。
換句話說,正確的計算應該是
<last sector> = <start sector> + <sector count> - 1
但顯然,公用事業公司忽略了從這總數中減去一個部門來調整數數到一個移位。
當新分割區的大小很小(即只有兩個磁區)時,這種「加一」的錯誤就相當明顯。
需要檢查實際的原始程式碼以確定為什麼與設備的可用大小存在相關性/依賴性。
解決這個明顯錯誤的方法是使用磁區號明確指定最後一個磁區。
例如,如果起始磁區為 2048,分割區大小為 1K 位元組,則將最後一個磁區指定為 2049。
由於這個“額外”扇區位於新分區的末尾,因此該問題與分區對齊無關。
分區對齊(和保護柱面/磁軌/扇區)將應用於修改新分區的開始。
也就是說,磁區將保留在新分割區的“前面”,而不是任何分割區的一部分。
這些磁區將是未分配的,本質上是浪費的,並且不能被(任何檔案系統)使用。
對齊不會影響新分割區的大小。
您描述的問題與分割區大小有關,而不是其對齊方式。
我正在嘗試對 1440 KiB 軟碟映像進行分區
軟碟不應該被分區。只有一個引導磁區。
MBR 和分割表適用於硬碟(和 SSD)。
附錄
顯然有一些程式碼util-linux-2.31.1/libfdisk/src/dos.c嘗試調整分區的末尾,以便下一個分區將對齊!
static int add_partition(struct fdisk_context *cxt, size_t n,
struct fdisk_partition *pa)
{
...
if (isrel && stop - start < (cxt->grain / fdisk_get_sector_size(cxt))) {
/* Don't try to be smart on very small partitions and don't align so small sizes */
isrel = 0;
if (stop > start)
stop -= 1;
DBG(LABEL, ul_debug("DOS: don't align end of tiny partition [start=%ju, stop=%ju, grain=%lu]",
(uintmax_t)start, (uintmax_t)stop, cxt->grain));
}
if (stop < limit && isrel && alignment_required(cxt)) {
/* the last sector has not been exactly requested (but
* defined by +size{K,M,G} convention), so be smart and
* align the end of the partition. The next partition
* will start at phy.block boundary.
*/
stop = fdisk_align_lba_in_range(cxt, stop, start, limit);
if (stop > start)
stop -= 1;
if (stop > limit)
stop = limit;
DBG(LABEL, ul_debug("DOS: aligned stop: %ju", (uintmax_t) stop));
}
一些調試輸出(即啟用了調試的實用程式版本)將有助於闡明正在發生的情況。