1、[root@localhost~]# fdisk -l //列表查看磁盤分區-默認如果沒有給出設備,那麼使用那些在/proc/partitions (如果存在)提到的,重啓後新的磁盤會被讀入該文件//
Disk/dev/sda: 85.8 GB, 85899345920 bytes
255heads, 63 sectors/track, 10443 cylinders
Units =cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2563 20482875 83 Linux
/dev/sda3 2564 2824 2096482+ 82 Linux swap / Solaris
Disk/dev/sdb: 85.8 GB, 85899345920 bytes
255heads, 63 sectors/track, 10443 cylinders
Units =cylinders of 16065 * 512 = 8225280 bytes
Disk/dev/sdb doesn't contain a valid partition table //系統提示該磁盤不包含有效分區表,需要進行分區//
2、開始爲 /dev/sdb 進行分區
[root@localhost~]# fdisk /dev/sdb //fdisk直接接設備文件,開始規劃分區,進入交互式操作//
Devicecontains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Buildinga new DOS disklabel. Changes will remain in memory only,
untilyou decide to write them. After that, of course, the previous
contentwon't be recoverable.
Thenumber of cylinders for this disk is set to 10443.(這塊磁盤有10443個柱面)
Thereis nothing wrong with that, but this is larger than 1024,
andcould in certain setups cause problems with:
1)software that runs at boot time (e.g., old versions of LILO)
2)booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning:invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command(m for help): m --獲取幫助
Commandaction
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 savingchanges ----不保存修改直接退出(整個交互過程是模擬,還沒有生效,允許撤銷)
s create a new empty Sun disklabel
t change a partition'ssystem id ----修改分區系統ID(不同的文件系統)
u change display/entry units
v verify the partition table
w write table to disk andexit ----保存並退出(一定要想好哦^_^)
x extra functionality (experts only)
Command(m for help): n //開始創建新分區//
Commandaction
e extended ----創建擴展分區
p primary partition (1-4) ----創建主分區
P -----選擇P創建主分區
Partitionnumber (1-4): 1 ----分區編號(可以劃分4個主分區,按正常順序往下延)
Firstcylinder (1-10443, default 1): ----第一個柱面,默認從第一個開始,直接回車,往下順延
Usingdefault value 1
Lastcylinder or +size or +sizeM or +sizeK (1-10443, default 10443): +20G ----選擇最後一個柱面,或者直接指定該分區大小,這裏輸入+20G回車
Command(m for help): n ----以下過程類似,不再贅述
Commandaction
e extended
p primary partition (1-4)
p
Partitionnumber (1-4): 2
First cylinder(2434-10443, default 2434):
Usingdefault value 2434
Lastcylinder or +size or +sizeM or +sizeK (2434-10443, default 10443): +20G
Command(m for help): n ----接下來創建擴展分區,除了上述的兩個主分區,剩餘的空間全部歸它所有
Commandaction
e extended
p primary partition (1-4)
e
Partitionnumber (1-4): 3 ----創建擴展分區爲sbd3
Firstcylinder (4867-10443, default 4867):
Usingdefault value 4867
Lastcylinder or +size or +sizeM or +sizeK (4867-10443, default 10443):
Usingdefault value 10443
3)新建2個邏輯分區,分別爲2GB、10GB
Command(m for help): n
Commandaction
l logical (5 or over)
p primary partition (1-4)
l ----創建邏輯分區爲sbd5 (表示第一個邏輯分區)
Firstcylinder (4867-10443, default 4867):
Usingdefault value 4867
Lastcylinder or +size or +sizeM or +sizeK (4867-10443, default 10443): +2G
Command(m for help): n
Commandaction
l logical (5 or over)
p primary partition (1-4)
l ----創建第二個邏輯分區sbd6
Firstcylinder (5111-10443, default 5111):
Usingdefault value 5111
Lastcylinder or +size or +sizeM or +sizeK (5111-10443, default 10443): +10G
4)將第1個邏輯分區的類型改爲lvm(ID 8e) 注意:如果要創建lvm分區類型必須爲 8e
Command(m for help): t ----修改分區類型
Partitionnumber (1-6): 5 ——修改sbd5的分區類型
Hexcode (type L to list codes): l ——獲取各分區類型ID
0 Empty 1e Hidden W95 FAT1 80 Old Minix bf Solaris
1 FAT12 24 NEC DOS 81 Minix / old Lin c1 DRDOS/sec(FAT-
2 XENIXroot 39 Plan 9 82 Linux swap / So c4 DRDOS/sec (FAT-
3 XENIXusr 3c PartitionMagic 83 Linux c6 DRDOS/sec (FAT-
4 FAT16<32M 40 Venix 80286 84 OS/2 hidden C: c7 Syrinx
5 Extended 41 PPC PReP Boot 85 Linux extended da Non-FS data
6 FAT16 42 SFS 86 NTFS volume set db CP/M / CTOS /.
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set de DellUtility
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext df BootIt
9 AIXbootable 4f QNX4.x 3rd part 8e Linux LVM e1 DOS access
a OS/2Boot Manag 50 OnTrack DM 93 Amoeba e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor
c W95FAT32 (LBA) 52 CP/M 9f BSD/OS eb BeOS fs
e W95FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT
f W95Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys ab Darwinboot fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
Hexcode (type L to list codes): 8e ——選擇8e表示lvm分區
Changedsystem type of partition 5 to 8e (Linux LVM) ----已將分區5的id改爲8e
3、確認分區無誤後,保存退出
Command(m for help): w
Thepartition table has been altered! ----該分區表已經被更改!
Callingioctl() to re-read partition table.
WARNING:If you have created or modified any DOS 6.x
partitions,please see the fdisk manual page for additional
information.
Syncingdisks.
4、使用partprobe識別新的分區表 【最好是重啓一次】
創建分區後,這些分區表還沒有生效,最好通過重啓讀取這些分區表,系統才能使用,也可以使用以下命令:
Partprobe /dev/sdb //強制刷新分區表// --RHEL5系列
[root@localhost~]# partprobe/dev/sdb //強制刷新分區表,使系統能夠識別//
結果驗證
[root@localhost~]# fdisk -l
Disk /dev/sda:85.8 GB, 85899345920 bytes
255heads, 63 sectors/track, 10443 cylinders
Units =cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2563 20482875 83 Linux
/dev/sda3 2564 2824 2096482+ 82 Linux swap / Solaris
Disk/dev/sdb: 85.8 GB,85899345920 bytes
255heads, 63 sectors/track, 10443 cylinders
Units =cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 2433 19543041 83 Linux
/dev/sdb2 2434 4866 19543072+ 83 Linux
/dev/sdb3 4867 10443 44797252+ 5 Extended
/dev/sdb5 4867 5110 1959898+ 8e Linux LVM