如何在Linux上查看分区大小?

如何在Linux上查看分区大小?

我创建了一个 2G 分区,如下所示fdisk

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 
First sector (4196352-16777215, default 4196352): 
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-16777215, default 16777215): +2G
Partition 2 of type Linux and of size 2 GiB is set

Command (m for help): w
The partition table has been altered!

但如果我检查尺寸(再次使用fdisk),它似乎是

fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 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
Disk label type: dos
Disk identifier: 0xe82746a5

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   83  Linux


blockdev --getbsz /dev/sdb2
4096

然后仔细检查:

echo "2097152*4096/1024/1024/1024" | bc
8

(块 * 字节 / 1024^3 应该给出 GB,对吗?)这意味着 8GB 分区。

我怎么算错了?

答案1

忽略“块”列。结束扇区是 8390655,起始扇区是 4196352。因此,该分区跨越的扇区数为 8390655 - 4196351(因为包含第一个扇区),即 4,194,304。每个扇区为 512 字节,因此两个扇区为 1 KB,即 4,194,304 / 2 = 2,097,152 KB。除以 1024**2 得到千兆字节,您就有一个 2 GB 大的分区。

相关内容