更改分区 ID 类型

如前文所述,创建新分区时,分区 ID 类型自动默认为 Linux (83)。
我们还可以选择稍后更改分区类型。

为了更改分区类型,我们需要更改 ID。
这将允许我们在多个不同选项之间更改类型。
在本例中,我们将更改 /dev/sdb1 的类型 ID。
使用选项 t 更改分区 ID 类型。
我们可以使用 L 选项列出可用的分区 ID 类型。

# 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: 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: 0x96151d76
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux
Command (m for help): t
Selected partition 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'

最后,使用 write/quit 命令 (w) 保存并退出 fdisk。
注意:执行此命令后,更改将是永久性的。

Command (m for help): w

主分区与扩展分区

PC 硬盘的原始分区方案只允许有四个分区,称为主分区。

要创建四个以上的分区,可以将这四个分区之一划分为许多较小的分区,称为逻辑分区。
当主分区以这种方式细分时,它被称为扩展分区。

什么是磁盘分区

分区将磁盘驱动器划分为一个或者多个逻辑磁盘。
每个分区都被视为具有自己文件系统的单独磁盘。
分区信息存储在分区表中。
可以使用 fdisk 实用程序创建两种类型的分区:

  • 主分区
  • 扩展分区
Linux/UNIX:如何使用 fdisk 创建主分区
之路教程 https://onitr oad .com

使用 fdisk 创建主分区

fdisk 实用程序是 Linux 的常用分区表操作器。
使用“fdisk -l”列出分区表。
我们假设我们正在修改系统上的第一个驱动器。

  1. 首先使用 (n) 命令选项在驱动器上创建一个新分区:
# 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 0x96151d76.
Command (m for help): n
  1. 在下一步中,或者按 p 或者按 ENTER,这将采用默认值 p(主分区)。
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
  1. 接下来我们可以为主分区选择一个分区号。
    默认情况下,如果我们按 ENTER,它将自动选择驱动器上的下一个可用分区。
Select (default p): p
Partition number (1-4, default 1): 1
  1. 确定分区的起始点,默认会选择驱动器上的下一个可用柱面。
    在下一步中,选择新分区的大小,例如,要创建 1 GB 的分区,我们可以将命令设置为 +1024M。
First sector (2048-41943039, default 2048):     ### press ENTER here
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +1024M
Partition 1 of type Linux and of size 1 GiB is set
  1. 这将带我们返回命令行,我们可以其中查看新创建的分区。
    使用选项 p 打印出分区表。
Command (m for help): p
Disk /dev/sdb: 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: 0x96151d76
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux

我们可以看到新创建的分区以块而不是兆字节列出,并且分区 ID 类型自动默认为 Linux,这将允许我们在该分区上创建文件系统。

  1. 最后使用 write/quit 命令 (w ) 保存并退出 fdisk。
    执行此命令后,更改将是永久性的。
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

7、运行partprobe命令扫描新修改的分区表:

# partprobe

如果 partprobe 未识别新修改的表,则需要重新启动。
我们还可以运行命令“fdisk -l”来验证新分区。

# fdisk -l
Disk /dev/sdb: 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: 0x96151d76
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux
日期:2020-09-17 00:13:27 来源:oir作者:oir