Linux fdisk 设置分区类型
时间: 2023-09-03 18:10:06 浏览: 174
以下是Linux中fdisk命令设置分区类型的示例:
1. 首先,使用fdisk命令打开磁盘分区表。例如,使用以下命令打开/dev/sda磁盘的分区表:
```
sudo fdisk /dev/sda
```
2. 使用p命令查看当前分区表的信息:
```
Command (m for help): p
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sda1 2048 83888127 41943040 83 Linux
/dev/sda2 83888128 1953523711 936818792 5 Extended
/dev/sda5 83890176 167780351 41945088 83 Linux
/dev/sda6 167782400 251674623 41946012 83 Linux
/dev/sda7 251676672 335568895 41946012 83 Linux
/dev/sda8 335570944 419463167 41946012 83 Linux
/dev/sda9 419465216 503357439 41946012 83 Linux
/dev/sda10 503359488 587251711 41946012 83 Linux
/dev/sda11 587253760 671145983 41946012 83 Linux
/dev/sda12 671148032 755040255 41946012 83 Linux
/dev/sda13 755042304 838934527 41946012 83 Linux
/dev/sda14 838936576 922828799 41946012 83 Linux
/dev/sda15 922830848 1000218623 39019488 83 Linux
```
可以看到,当前磁盘/dev/sda上已经有了多个分区,每个分区都有一个Id和System类型。
3. 使用t命令更改指定分区的类型。例如,将/dev/sda2分区的类型更改为FAT32,可以按照以下步骤操作:
```
Command (m for help): t
Partition number (1-15): 2
Hex code (type L to list all codes): b
Changed system type of partition 2 to b (W95 FAT32)
```
注意,这里输入的b是FAT32分区类型的代号。在输入代号之后,系统会提示“Changed system type of partition 2 to b (W95 FAT32)”表示分区类型已经修改成功。
4. 最后,使用w命令保存分区表更改并退出fdisk工具:
```
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
```
提示信息中的“WARNING”表示重读分区表失败,但这不影响分区类型的更改。最后一行“Syncing disks.”表示系统已经将更改的分区表保存并同步到磁盘中。
阅读全文