root@slackware:/# fdisk /dev/sda
Welcome to fdisk (util-linux 2.38.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
现在我们告诉 fdisk 我们希望分区。输入 m 来获取帮助。
Command (m for help): m
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
在最小情况下,你需要一个 / 分区、 /boot 分区、 /boot/efi 分区、以及一个 swap 分区。你可能也像单独分出 /home 分区用来存放用户文件(这对于之后升级和安装不同的 Linux 操作系统而要保持用户文件很容易)。首先创建 GPT 分区输入 g,然后创建一个新的分区可以输入 n 。
Command (m for help): g
Created a new GPT disklabel (GUID: B88F50AB-2DF8-6A49-BF74-DD28B2BE0E2E).
Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-250069646, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-250069646, default 250068991): +100M
Created a new partition 1 of type 'Linux filesystem' and of size 100 MiB.
Command (m for help): n
Partition number (2-128, default 2):
First sector (206848-250069646, default 206848):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (206848-250069646, default 250068991): +200M
Created a new partition 2 of type 'Linux filesystem' and of size 200 MiB.
Command (m for help): n
Partition number (3-128, default 3):
First sector (616448-250069646, default 616448):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (616448-250069646, default 250068991): +8G
Created a new partition 3 of type 'Linux filesystem' and of size 8 GiB.
Command (m for help): n
Partition number (4-128, default 4):
First sector (17393664-250069646, default 17393664):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (17393664-250069646, default 250068991): +40G
Created a new partition 4 of type 'Linux filesystem' and of size 40 GiB.
这里我们创建了四个分区,分别为 100M、200M、8G、40G,可以输入 p 来查看。
Command (m for help): p
Disk /dev/sda: 119.24 GiB, 128035676160 bytes, 250069680 sectors
Disk model: aigo SSD S500 12
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: B88F50AB-2DF8-6A49-BF74-DD28B2BE0E2E
Device Start End Sectors Size Type
/dev/sda1 2048 206847 204800 100M Linux filesystem
/dev/sda2 206848 616447 409600 200M Linux filesystem
/dev/sda3 616448 17393663 16777216 8G Linux filesystem
/dev/sda4 17393664 101279743 83886080 40G Linux filesystem
这四个分区类型都是 Linux 文件系统。我们需要改变 /dev/sda1 为 EFI System(id 为 1),改变 /dev/sda3 为 Linux swap(id 为 19)。
Command (m for help): t
Partition number (1-4, default 4): 1
Partition type or alias (type L to list all): 1
Changed type of partition 'Linux filesystem' to 'EFI System'.
Command (m for help): t
Partition number (1-4, default 4): 3
Partition type or alias (type L to list all): 19
Changed type of partition 'Linux filesystem' to 'Linux swap'.
Command (m for help): p
Disk /dev/sda: 119.24 GiB, 128035676160 bytes, 250069680 sectors
Disk model: aigo SSD S500 12
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: B88F50AB-2DF8-6A49-BF74-DD28B2BE0E2E
Device Start End Sectors Size Type
/dev/sda1 2048 206847 204800 100M EFI System
/dev/sda2 206848 616447 409600 200M Linux filesystem
/dev/sda3 616448 17393663 16777216 8G Linux swap
/dev/sda4 17393664 101279743 83886080 40G Linux filesystem
Command (m for help): n
Partition number (5-128, default 5):
First sector (101279744-250069646, default 101279744):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (101279744-250069646, default 250068991): +30G
Created a new partition 5 of type 'Linux filesystem' and of size 30 GiB.
现在我们可以将修改写入。
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
root@slackware:/#