Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5G
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
查看内核是否真正的读取分区表
1
2
3
4
5
6
7
# cat /proc/partitions
major minor #blocks name
8 0 20971520 sda
8 1 409600 sda1
8 2 20560896 sda2
8 16 20971520 sdb
8 17 5253223 sdb1
4.格式化分区
1
# mkfs.ext4 /dev/sdb1
5.设定卷标
1
# e2label /dev/sdb1 myfirst
6.编辑/etc/fstab文件,添加如下内容
1
2
# vim /etc/fstab
LABEL=myfirst /mnt/firstsdb ext4 defaults 0 0
7.新建一个挂载点
1
# mkdir /mnt/firstsdb
8.挂载文件系统
1
# mount /dev/sdb1 /mnt/firstsdb/
查看是否挂载成功
1
2
3
4
5
6
7
8
# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sdb1 on /mnt/firstsdb type ext4 (rw)
在挂载目录下,会生成一个lost+found目录
1
2
3
# cd /mnt/firstsdb/
# ls
lost+found
按前面的步骤又新建一个磁盘
1
2
3
4
# fdisk -cu /dev/sdb
Device Boot Start End Blocks Id System
/dev/sdb1 63 10506509 5253223+ 83 Linux
/dev/sdb2 10506510 14700813 2097152 83 Linux
查看时,没有识别sdb2分区
1
2
3
4
5
6
7
# cat /proc/partitions
major minor #blocks name
8 0 20971520 sda
8 1 409600 sda1
8 2 20560896 sda2
8 16 20971520 sdb
8 17 5253223 sdb1
此时可以使用partx识别
1
2
3
4
5
6
7
8
9
10
11
# partx -a /dev/sdb
BLKPG: Device or resource busy
error adding partition 1
# cat /proc/partitions
major minor #blocks name
8 0 20971520 sda
8 1 409600 sda1
8 2 20560896 sda2
8 16 20971520 sdb
8 17 5253223 sdb1
8 18 2097152 sdb2
之后再进行相应的挂载工作
查看卷标,用e2label 磁盘名
1
2
# e2label /dev/sdb1
myfirst
创建一个1G的交换分区
1
2
3
4
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 82
/dev/sdb3 916 1046 1048576 82 Linux swap / Solaris