3.1 fdisk命令分区
fdisk分区_第1张图片
n是代表添加新分区
p打印分区表
d删除分区
m打印菜单
q退出
w保存
l查看分区类型
t 指定类型分区

fdisk分区

e=扩展分区
p=主分区

[root@KING ~]# fdisk -cu /dev/sdb =》进入第二个磁盘
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x5cffaf5f.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p =>查看磁盘是否有分区

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5cffaf5f

Device Boot Start End Blocks Id System

Command (m for help): n =》建立一个分区
Command action
e extended =》扩展分区
p primary partition (1-4) =》主分区
p =》选择主分区
Partition number (1-4): 1 =》建立第一个主分区
First sector (2048-208895, default 2048): =》第一个起始按回车从2048字节开始分区
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895): +10M =》结束分区10M,分给第一个分区10M
+size可以加K,M,G为单位来添加
这里是从2048字节开始到哪里结束

Command (m for help): p =》查看分区

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5cffaf5f

Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux =》第一个分区

Command (m for help): n =》输入n在次分区
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2 =>第二个分区
First sector (22528-208895, default 22528): =》起始
Using default value 22528
Last sector, +sectors or +size{K,M,G} (22528-208895, default 208895): +10M =》空间给10M

Command (m for help): p =》查看分区情况

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5cffaf5f

Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 43007 10240 83 Linux =》共2个主分区

Command (m for help): n =》第三次添加主分区
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3 =》第三主分区给数字3
First sector (43008-208895, default 43008):
Using default value 43008
Last sector, +sectors or +size{K,M,G} (43008-208895, default 208895): +10M =》同样10M

Command (m for help): p =》查看分区

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5cffaf5f

Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 43007 10240 83 Linux
/dev/sdb3 43008 63487 10240 83 Linux =》共3个主分区

Command (m for help): n =》再次添加分区
Command action
e extended
p primary partition (1-4)
e =》第四次给逻辑分区
Selected partition 4
First sector (63488-208895, default 63488):
Using default value 63488
Last sector, +sectors or +size{K,M,G} (63488-208895, default 208895): =》把剩余的空间全部给逻辑分区
Using default value 208895

Command (m for help): p =》查看分区

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5cffaf5f

Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 43007 10240 83 Linux
/dev/sdb3 43008 63487 10240 83 Linux
/dev/sdb4 63488 208895 72704 5 Extended =共4个分区

Command (m for help): n 第五次分区给逻辑分区分区
First sector (65536-208895, default 65536): 起始按回车
Using default value 65536
Last sector, +sectors or +size{K,M,G} (65536-208895, default 208895): +10M 结束给10M

Command (m for help): p =》查看分区

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5cffaf5f

Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 43007 10240 83 Linux
/dev/sdb3 43008 63487 10240 83 Linux
/dev/sdb4 63488 208895 72704 5 Extended
/dev/sdb5 65536 86015 10240 83 Linux =》sdb5逻辑分区的第一个分区

Command (m for help): d =》删除分区
Partition number (1-5): 3 =》选择1至5的分区,删除第三个主分区

Command (m for help): p =》查看分区

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5cffaf5f

Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 43007 10240 83 Linux =》第三个主分区已经删除掉
/dev/sdb4 63488 208895 72704 5 Extended
/dev/sdb5 65536 86015 10240 83 Linux

Command (m for help): L 查看分区类型(把第六个分区指定为LVM 8e)

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1

Command (m for help): t =》添加指定类型分区
Partition number (1-6): 6 =》第6个分区
Hex code (type L to list codes): 8e =》为8e (8e是LVM分区可以通过L查看到)
Changed system type of partition 6 to 8e (Linux LVM) =》提示分区成功为LVM

Command (m for help): p =》查看分区

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5cffaf5f

Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 43007 10240 83 Linux
/dev/sdb3 43008 63487 10240 83 Linux
/dev/sdb4 63488 208895 72704 5 Extended
/dev/sdb5 65536 86015 10240 83 Linux
/dev/sdb6 88064 108543 10240 8e Linux LVM =》第6个为LVM分区(id为8e)

Command (m for help): w =》保存
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[root@KING ~]# ll /dev/sd* =》查看分区表
brw-rw---- 1 root disk 8, 0 Nov 30 21:51 /dev/sda
brw-rw---- 1 root disk 8, 1 Nov 30 21:51 /dev/sda1
brw-rw---- 1 root disk 8, 2 Nov 30 21:51 /dev/sda2
brw-rw---- 1 root disk 8, 3 Nov 30 21:51 /dev/sda3
brw-rw---- 1 root disk 8, 16 Nov 30 22:58 /dev/sdb
brw-rw---- 1 root disk 8, 17 Nov 30 22:58 /dev/sdb1
brw-rw---- 1 root disk 8, 18 Nov 30 22:58 /dev/sdb2
brw-rw---- 1 root disk 8, 19 Nov 30 22:58 /dev/sdb3
brw-rw---- 1 root disk 8, 20 Nov 30 22:58 /dev/sdb4
brw-rw---- 1 root disk 8, 21 Nov 30 22:58 /dev/sdb5
brw-rw---- 1 root disk 8, 22 Nov 30 22:58 /dev/sdb6
但是现在操作系统还不知道你分好区了
[root@KING ~]# partprobe /dev/sdb =》这个命令通知操作系统的内核分区表发生改变了,不需要重启服务器