fdisk -l 后面不跟设备名称,列出当前所有分区
fdisk [设备名字] 进入磁盘进行分区
#fdisk -l 【查看目前系统的磁盘分区情况】
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000938b3
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 13 274 2097152 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 274 2611 18770944 83 Linux
关闭虚拟机增加一个10G的磁盘之后
# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000938b3
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 13 274 2097152 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 274 2611 18770944 83 Linux
【相比之前,多出了10G的硬盘】
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
#dfisk -l /dev/sda 【指定查看sda磁盘的情况】
#fdisk /dev/sdb 【进入sdb磁盘进行分区】
Command (m for help) m
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)
NOTE: 若磁盘≥2T, fdisk不能对该磁盘进行分区。patred /dev/sdb 此命令适合大于2T的磁盘
:n
e extended 【拓展分区】
p primary partition (1-4) 【主分区,磁盘特性最多分四个主分区】
NOTE:若分区大于四个,则需要将一个主分区更改成拓展分区,然后在拓展分区里面新建逻辑分区。拓展分区数量+主分区数量≤4
:p
Partition number (1-4): 1 【主分区名称】
First cylinder (1-1305, default 1):1 【分区大小】
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): 2G 【熟悉的单位大小】【此处注意加好,应该是 +2G】
:p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xed05782d
Device Boot Start End Blocks Id System
/dev/sdb1 1 2 16033+ 83 Linux
:n
:e
Partition number (1-4): 2
First cylinder (3-1305, default 3): 【直接回车,默认大小】
Last cylinder, +cylinders or +size{K,M,G} (3-1305, default 1305): +5G
:p
Device Boot Start End Blocks Id System
/dev/sdb1 1 2 16033+ 83 Linux
/dev/sdb2 3 656 5253255 5 Extended
:n
l logical (5 or over) 【已经有了拓展分区,可以再拓展分区里面建立逻辑分区】
p primary partition (1-4)
:l
First cylinder (3-656, default 3): 【回车默认】
Last cylinder, +cylinders or +size{K,M,G} (3-656, default 656): +2G
:p
Device Boot Start End Blocks Id System
/dev/sdb1 1 2 16033+ 83 Linux
/dev/sdb2 3 656 5253255 5 Extended
/dev/sdb5 3 264 2104483+ 83 Linux
:w 【保存】
:q 【退出】
NOTE:
一、id可以用命令 l 查看
5 拓展分区 83普通主分区和逻辑分区 82交换分区 8e LVM分区
二、当分完三个主分区之后,第四个扩展分区需要把剩余的磁盘空间全部划分给扩展分区,不然会浪费剩余的空间。因为分完拓展分区之后,再划分新的分区时是在已经划分的拓展分区里面来分的。拓展分区不可以格式化,可以把拓展分区看成空壳,能使用的是里面的逻辑分区。
三、删除分区
command (m for help): d 【delet】
Partition number (1-5) : 3 【此处输入分区的数值即可删除】
假设sdb4是拓展分区,sdb5是逻辑分区,此时出入拓展分区4,即可把sdb4,和sdb5一同删除。
四、Most Important
对服务器进行分区操作的时候,需要很谨慎,一不留神有可能把服务器上的数据全部分没了。
编辑回复