root@ubuntu:~# free -m
total used free shared buff/cache available
Mem: 3870 660 2636 13 573 2968
Swap: 2047 0 2047
root@ubuntu:~# fdisk -l | grep sdc
Disk /dev/sdc: 120 GiB, 128849018880 bytes, 251658240 sectors
/dev/sdc1 34 976562 976529 476.8M Linux filesystem
/dev/sdc2 978944 97656831 96677888 46.1G Linux filesystem
第一种 GPT格式 磁盘分区 创建 swap 交换分区
# 进入创建分区磁盘
root@ubuntu:~# parted /dev/sdc
GNU Parted 3.4
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p # 打印磁盘分区信息
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 500MB 500MB ext4 primary
2 501MB 50.0GB 49.5GB ntfs logical
# 创建主分区
(parted) mkpart primary 50001 52000
(parted) p # 打印分区信息
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 500MB 500MB ext4 primary
2 501MB 50.0GB 49.5GB ntfs logical
3 50.0GB 52.0GB 1999MB primary
# 创建 swap 交换分区
(parted) t
Partition number? 3
Flag to Invert? swap
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 500MB 500MB ext4 primary
2 501MB 50.0GB 49.5GB ntfs logical
3 50.0GB 52.0GB 1999MB primary swap
(parted) q # 退出
Information: You may need to update /etc/fstab.
root@ubuntu:~# fdisk -l | grep sdc
Disk /dev/sdc: 120 GiB, 128849018880 bytes, 251658240 sectors
/dev/sdc1 34 976562 976529 476.8M Linux filesystem
/dev/sdc2 978944 97656831 96677888 46.1G Linux filesystem
/dev/sdc3 97658880 101562367 3903488 1.9G Linux swap
root@ubuntu:~# parted /dev/sdc
GNU Parted 3.4
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 500MB 500MB ext4 primary
2 501MB 50.0GB 49.5GB ntfs logical
3 50.0GB 52.0GB 1999MB primary swap
(parted) q
# 对 /dev/sdc3 分区进行 swap 格式化
root@ubuntu:~# mkswap /dev/sdc3
Setting up swapspace version 1, size = 1.9 GiB (1998581760 bytes)
no label, UUID=6afd7ed9-2ff8-4306-8721-9030287a5609
# 查看磁盘分区信息
root@ubuntu:~# parted /dev/sdc
GNU Parted 3.4
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 500MB 500MB ext4 primary
2 501MB 50.0GB 49.5GB ntfs logical
3 50.0GB 52.0GB 1999MB linux-swap(v1) primary swap
root@ubuntu:~# fdisk -l | grep sdc
Disk /dev/sdc: 120 GiB, 128849018880 bytes, 251658240 sectors
/dev/sdc1 34 976562 976529 476.8M Linux filesystem
/dev/sdc2 978944 97656831 96677888 46.1G Linux filesystem
/dev/sdc3 97658880 101562367 3903488 1.9G Linux swap
第二中 MBR格式 磁盘分区 创建 swap 交换分区
root@ubuntu:~# fdisk -l | grep sd
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 1054719 1050624 513M EFI System
/dev/sda3 1054720 209713151 208658432 99.5G Linux filesystem
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk /dev/sdc: 120 GiB, 128849018880 bytes, 251658240 sectors
/dev/sdc1 34 976562 976529 476.8M Linux filesystem
/dev/sdc2 978944 97656831 96677888 46.1G Linux filesystem
/dev/sdc3 97658880 101562367 3903488 1.9G Linux swap
root@ubuntu:~# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.37.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: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: VMware Virtual S
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: dos
Disk identifier: 0xf4813d41
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-209715199, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-209715199, default 209715199): +500M
Created a new partition 1 of type 'Linux' and of size 500 MiB.
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 pri