为啥Linux的fdisk分区时First Sector是63或2048?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为啥Linux的fdisk分区时First Sector是63或2048?相关的知识,希望对你有一定的参考价值。
To understand why not 1, I need to describe some PC history. A long time ago, when the PC was first provided with hard drives, the first block on the drive was used by the Master Boot Record. Thats still true today, the first partition always began on Cylinder 0, Head 1, Sector 0, under the Cylinder/Head/Sector addressing scheme, whic is all there was than. To add to the interest, hard drives actually had differing numbers of sectors per track then and you had to describe the real geometry of the drive to the Bios. There was no auto dectect or Logical Block Addressing as used today. The Cylinder/Head/Sector addressing scheme broke permently when hard drives reached 4Gb but its legacy lives on. The largest numbers that fit in the CHS addressing scheme is 255 heads and 63 sectors per track. Hence until recently, the first partition always started at sector 63. Thats head 1, sector 0. //CHS方式寻址时,扇区号是从1开始的。但是实际的物理扇区是从0开始的,对于LBA寻址方式来说扇区号也是从0开始。这里出现的secotr 0是指物理扇区号。Over the years, boot loaders have used some of the 'unallocated' space between the MBR and the start of the first partition. With the death of the legacy BIOS (ok, its not quite dead yet) and its replacement with EFI BIOS, a special boot partitionis needed to allow EFI systems to boot in EFI mode. Starting the first partition at sector 2048 leaves 1Mb for the EFI boot code. Modern partitioning tools do this anyway and fdisk has been updated to follow suit. You can force some tools to give you back most of this 1Mb but its usually a bad idea. Your 2Tb drive will use 4k physical sectors. Its very important that you create partitions that are aligned on 4kb boundaries or your read/write speeds will be very poor. That is, partition starts must be a multiple of eight sectors. Notice that 63 is not a multiple of 8 but that 2048 is. As you really need to leave some space for grub, you should not start your first partition before sector 64. If you know how big grub is, you can make that smaller but its not worth the effort. 参考技术A To understand why not 1, I need to describe some PC history. A long time ago, when the PC was first provided with hard drives, the first block on the drive was used by the Master Boot Record. Thats still true today, the first partition always began on Cylinder 0, Head 1, Sector 0, under the Cylinder/Head/Sector addressing scheme, whic is all there was than. To add to the interest, hard drives actually had differing numbers of sectors per track then and you had to describe the real geometry of the drive to the BIOS. There was no auto dectect or Logical Block Addressing as used today. The Cylinder/Head/Sector addressing scheme broke permently when hard drives reached 4Gb but its legacy lives on. The largest numbers that fit in the CHS addressing scheme is 255 heads and 63 sectors per track. Hence until recently, the first partition always started at sector 63. Thats head 1, sector 0. //CHS方式寻址时,扇区号是从1开始的。但是实际的物理扇区是从0开始的,对于LBA寻址方式来说扇区号也是从0开始。这里出现的secotr 0是指物理扇区号。Over the years, boot loaders have used some of the 'unallocated' space between the MBR and the start of the first partition. With the death of the legacy BIOS (ok, its not quite dead yet) and its replacement with EFI BIOS, a special boot partitionis needed to allow EFI systems to boot in EFI mode. Starting the first partition at sector 2048 leaves 1Mb for the EFI boot code. Modern partitioning tools do this anyway and fdisk has been updated to follow suit. You can force some tools to give you back most of this 1Mb but its usually a bad idea. Your 2Tb drive will use 4k physical sectors. Its very important that you create partitions that are aligned on 4kb boundaries or your read/write speeds will be very poor. That is, partition starts must be a multiple of eight sectors. Notice that 63 is not a multiple of 8 but that 2048 is. As you really need to leave some space for grub, you should not start your first partition before sector 64. If you know how big grub is, you can make that smaller but its not worth the effort.Linux文件系统管理 fdisk分区命令
概述
我们在安装操作系统的过程中已经对系统硬盘进行了分区,但是如果我新添加了一块硬盘,想要正常使用时,在Linux中有专门的分区命令 fdisk 和 parted。其中 fdisk 命令较为常用,但不支持大于 2TB 的分区;如果需要支持大于 2TB 的分区,则需要使用 parted 命令,当然 parted 命令也能分配较小的分区。我们先来看看如何使用 fdisk 命令进行分区。
fdisk命令
fdisk 命令的格式如下:#列出系统分区 [[email protected] ~]# fdisk -l #给硬盘分区 [[email protected] ~]# fdisk 设备文件名
通过fdisk -l 命令可以得到以下信息
#查询本机可以识别的硬盘和分区 [[email protected] ~]# fdisk -l #硬盘文件名和硬盘大小 Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x0007be9f Device Boot Start End Blocks ld System /dev/sda1 * 2048 411647 204800 83 Linux /dev/sda2 411648 41943039 20765696 8e Linux LVM
信息的下半部分是分区的信息,共 7 列,含义如下:
Device | Boot | Start | End | Blocks | id | System |
分区的设备文件名 | 是否为启动引导分区,在这里/dev/sda1为启动引导分区 | 起始柱面,代表分区从哪里开始 | 终止柱面,代表分区到哪里结束 | 分区的大小,单位是 KB | 分区内文件系统的 ID。在fdisk 命令中,可以使用"i"查看 | 分区内安装的系统 |
如果这个分区并没有占满整块硬盘,就会提示 "Partition 1 does not end on cyl inder boundary",表示第一个分区没有到硬盘的结束柱面。
假如有一个新的硬盘 /dev/sdb,使用命令给硬盘 /dev/sdb分区,命令如下:
注意这里的分区命令是"fdisk/dev/sdb",这是因为我们的硬盘现在并没有分区,使用 fdisk 命令的目的就是建立分区,所以"1~59"这些数字还不存在。
在 fdisk 交互界面中输入m可以得到帮助,帮助里列出了 fdisk 可以识别的交互命令,我们来解释一下这些命令,如下所示。
#给/dev/sdb分区 [[email protected] ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xed7e8bc7. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won‘t be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated.it‘s strongly recommended to switch off the mode (command ‘c‘) and change display units to sectors (command ‘u‘). Command (m for help):m #交互界面的等待输入指令的位置,输入 m 得到帮助 Command action #可用指令 a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition I list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition‘s system id u change display/entry units v verity the partition table w write table to disk and exit x extra functionality (experts only)
在 fdisk 交互界面中输入m可以得到帮助,帮助里列出了 fdisk 可以识别的交互命令,我们来解释一下这些命令,如下所示。
命令 | 说 明 |
---|---|
a | 设置可引导标记 |
b | 编辑 bsd 磁盘标签 |
c | 设置 DOS 操作系统兼容标记 |
d | 删除一个分区 |
1 | 显示已知的文件系统类型。82 为 Linux swap 分区,83 为 Linux 分区 |
m | 显示帮助菜单 |
n | 新建分区 |
0 | 建立空白 DOS 分区表 |
P | 显示分区列表 |
q | 不保存退出 |
s | 新建空白 SUN 磁盘标签 |
t | 改变一个分区的系统 ID |
u | 改变显示记录单位 |
V | 验证分区表 |
w | 保存退出 |
X | 附加功能(仅专家) |
以上是关于为啥Linux的fdisk分区时First Sector是63或2048?的主要内容,如果未能解决你的问题,请参考以下文章
为什么Linux的Fdisk分区时First Sector为2048?