1 2种分区结构简介

MBR分区

  • 硬盘主引导记录MBR由4个部分组成
  • 主引导程序(偏移地址0000H--0088H),它负责从活动分区中装载,并运行系统引导程序。
  • 出错信息数据区,偏移地址0089H--00E1H为出错信息,00E2H--01BDH全为0字节。
  • 分区表(DPT,Disk Partition Table)含4个分区项,偏移地
  • 址01BEH--01FDH,每个分区表项长16个字节,共64字节为分区项1、分区项2、分区项3、分区项4
  • 结束标志字,偏移地址01FE--01FF的2个字节值为结束标志55AA

GPT分区

  • GPT:GUID(Globals Unique Identifiers) partitiontable 支持128个分区,使用64位,支持8Z(512Byte/block )64Z ( 4096Byte/block)
  • 使用128位UUID(Universally Unique Identifier) 表示磁盘和分区 GPT分区表自动备份在头和尾两份,并有CRC校验位
  • UEFI (统一扩展固件接口)硬件支持GPT,使操作系统启动

2 fdisk的使用

2.1 fdisk命令的基础

[root@centos7 mnt]$ dd if=/dev/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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xc0e6470d.

Command (m for help): m
Command action
   a   toggle a bootable flag                                   # 切换可启动标志
   b   edit bsd disklabel                           # 编辑磁盘标记
   c   toggle the dos compatibility flag               # 切换dos兼容标志
   d   delete a partition                        # 删除一个分区
   g   create a new empty GPT partition table                  # 创建一个空的GPT分区表
   G   create an IRIX (SGI) partition table                    # 创建一个IRIX分区表
   l   list known partition types                   # 列出已知的分区类型
   m   print this menu                          # 打印菜单                   
   n   add a new partition                                       # 添加一个分区
   o   create a new empty DOS partition table                    # 创建一个空的DOS分区表
   p   print the partition table                                 # 打印分区表
   q   quit without saving changes                               # 退出不保存
   s   create a new empty Sun disklabel                          # 创建一个空的sun磁盘标签
   t   change a partition's system id                            # 改变一个分区的类型
   u   change display/entry units                                # 改变显示的单位
   v   verify the partition table                                # 验证分区表
   w   write table to disk and exit                              # 写分区表并退出
   x   extra functionality (experts only)                        # 高级功能

Command (m for help): 

2.2 fdisk实战

例子: 使用fdisk工具给/dev/sdb(100G)分区满足下面几个要求

  • 3个主分区一个扩展分区
  • /dev/sdb1分区类型为Linux LVM,大小为30G
  • /dev/sdb2分区类型为swap,大小为20G
  • /dev/sdb3分区类型为Linux, 大小为10G
  • /dev/sdb5分区类型为linux,大小为10G
  • 保留40G留作后用
[root@centos7 mnt]$ 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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x2fd8d812.

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

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 (62916608-209715199, default 62916608): 
Using default value 62916608
Last sector, +sectors or +size{K,M,G} (62916608-209715199, default 209715199): +20G
Partition 2 of type Linux and of size 20 GiB is set

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

Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e
Selected partition 4
First sector (125831168-209715199, default 125831168): 
Using default value 125831168
Last sector, +sectors or +size{K,M,G} (125831168-209715199, default 209715199): 
Using default value 209715199
Partition 4 of type Extended and of size 40 GiB is set

Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (125833216-209715199, default 125833216): 
Using default value 125833216
Last sector, +sectors or +size{K,M,G} (125833216-209715199, default 209715199): +10G
Partition 5 of type Linux and of size 10 GiB is set

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x2fd8d812

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    62916607    31457280   83  Linux
/dev/sdb2        62916608   104859647    20971520   83  Linux
/dev/sdb3       104859648   125831167    10485760   83  Linux
/dev/sdb4       125831168   209715199    41942016    5  Extended
/dev/sdb5       125833216   146804735    10485760   83  Linux

Command (m for help): t
Partition number (1-5, default 5): 1
Hex code (type L to list all codes): L  

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): t
Partition number (1-5, default 5): 2
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x2fd8d812

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    62916607    31457280   8e  Linux LVM
/dev/sdb2        62916608   104859647    20971520   82  Linux swap / Solaris
/dev/sdb3       104859648   125831167    10485760   83  Linux
/dev/sdb4       125831168   209715199    41942016    5  Extended
/dev/sdb5       125833216   146804735    10485760   83  Linux
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
View Code

相关文章:

  • 2022-12-23
  • 2021-10-02
  • 2021-11-11
  • 2021-07-27
  • 2022-12-23
  • 2021-09-23
  • 2021-08-18
猜你喜欢
  • 2021-12-02
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
相关资源
相似解决方案