天天看點

linux中fdisk分區方法

當我們通過 fdisk 裝置,進入相應裝置的操作時,會發現有如下的提示;以 fdisk /dev/sda 裝置為例,以下同;

[[email protected] beinan]# fdisk /dev/sda

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 注:l是列出分區類型,以供我們設定相應分區的類型;

m print this menu 注:m 是列出幫助資訊;

n add a new partition 注:添加一個分區;

o create a new empty DOS partition table

p print the partition table 注:p列出分區表;

q quit without saving changes 注:不儲存退出;

s create a new empty Sun disklabel

t change a partition's system id 注:t 改變分區類型;

u change display/entry units

v verify the partition table

w write table to disk and exit 注:把分區表寫入硬碟并退出;

x extra functionality (experts only) 注:擴充應用,專家功能;

通過fdisk的n指令增加一個分區

Command (m for help): p

Disk /dev/sda: 1035 MB, 1035730944 bytes

256 heads, 63 sectors/track, 125 cylinders

Units = cylinders of 16128 * 512 = 8257536 bytes

Device Boot Start End Blocks Id System

/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)

/dev/sda2 26 125 806400 5 Extended

/dev/sda5 26 50 201568+ 83 Linux

Command (m for help): n 注:增加一個分區;

Command action

l logical (5 or over) 注:增加邏輯分區,分區編号要大于5;為什麼要大于5,因為已經有sda5了;

p primary partition (1-4) 注:增加一個主分區;編号從 1-4 ;但sda1 和sda2都被占用,是以隻能從3開始;

p

Partition number (1-4): 3

No free sectors available 注:失敗中,為什麼失敗?

  注:我試圖增加一個主分區,看來是失敗了,為什麼失敗?因為我們看到主分區+擴充分區把整個磁盤都用光了,看擴充分區的End的值,再看一下 p輸出資訊中有125 cylinders;最好還是看前面部份;那裡有提到;

  是以我們隻能增加邏輯分區了

Command (m for help): n

Command action

l logical (5 or over)

p primary partition (1-4)

l 注:在這裡輸入l,就進入劃分邏輯分區階段了;

First cylinder (51-125, default 51): 注:這個就是分區的Start 值;這裡最好直接按回車,如果您輸入了一個非預設的數字,會造成空間浪費;

Using default value 51

Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): +200M 注:這個是定義分區大小的,+200M 就是大小為200M ;當然您也可以根據p提示的機關cylinder的大小來算,然後來指定 End的數值。回頭看看是怎麼算的;還是用+200M這個辦法來添加,這樣能直覺一點。如果您想添加一個10G左右大小的分區,請輸入 +10000M ;

Command (m for help):

  5、通過fdisk的t指令指定分區類型

Command (m for help): t 注:通過t來指定分區類型;

Partition number (1-6): 6 注:要改變哪個分區類型呢?我指定了6,其實也就是sda6

Hex code (type L to list codes):L 注:在這裡輸入L,就可以檢視分區類型的id了;

Hex code (type L to list codes): b 注:如果我想讓這個分區是 W95 FAT32 類型的,通過L檢視得知 b是表示的是,是以輸入了b;

Changed system type of partition 6 to b (W95 FAT32) 注:系統資訊,改變成功;是否是改變了,請用p檢視;

Command (m for help): p

Disk /dev/sda: 1035 MB, 1035730944 bytes

256 heads, 63 sectors/track, 125 cylinders

Units = cylinders of 16128 * 512 = 8257536 bytes

Device Boot Start End Blocks Id System

/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)

/dev/sda2 26 125 806400 5 Extended

/dev/sda5 26 50 201568+ 83 Linux

/dev/sda6 51 75 201568+ b W95 FAT32

  6、fdisk 的退出,用q或者 w

  其中 q是 不儲存退出,w是儲存退出

  Command (m for help): w

  或

  Command (m for help): q

通過fdisk的d指令來删除一個分區

Command (m for help): p 注:列出分區情況;

Disk /dev/sda: 1035 MB, 1035730944 bytes

256 heads, 63 sectors/track, 125 cylinders

Units = cylinders of 16128 * 512 = 8257536 bytes

Device Boot Start End Blocks Id System

/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)

/dev/sda2 26 125 806400 5 Extended

/dev/sda5 26 50 201568+ 83 Linux

/dev/sda6 51 76 200781 83 Linux

Command (m for help): d 注:執行删除分區指定;

Partition number (1-6): 6 注:我想删除 sda6 ,就在這裡輸入 6 ;

Command (m for help): p 注:再檢視一下硬碟分區情況,看是否删除了?

Disk /dev/sda: 1035 MB, 1035730944 bytes

256 heads, 63 sectors/track, 125 cylinders

Units = cylinders of 16128 * 512 = 8257536 bytes

Device Boot Start End Blocks Id System

/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)

/dev/sda2 26 125 806400 5 Extended

/dev/sda5 26 50 201568+ 83 Linux

Command (m for help):

  警告:删除分區時要小心,請看好分區的序号,如果您删除了擴充分區,擴充分區之下的邏輯分區都會删除;是以操作時一定要小心;如果知道自己操作錯了,請不要驚慌,用q不儲存退出;切記切記!!!!在分區操作錯了之時,千萬不要輸入w儲存退出!!!

繼續閱讀