歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下fdisk命令操作磁盤詳解--添加、刪除、轉換分區等

Linux下fdisk命令操作磁盤詳解--添加、刪除、轉換分區等

日期:2017/2/28 15:49:41   编辑:Linux教程

linux下fdisk命令操作磁盤詳解--添加、刪除、轉換分區等

fdisk 操作硬盤的命令格式如下:

[root@localhost beinan]# fdisk 設備

比如我們通過 fdisk -l 得知 /dev/hda 或者 /dev/sda 設備;我們如果想再添加或者刪除

一些分區,可以用

[root@localhost beinan]# fdisk /dev/hda

[root@localhost beinan]# fdisk /dev/sda

注 在以後的例子中,我們要以 /dev/sda 設備為例,來講解如何用 fdisk 來操作添加、刪

除分區等動作;

1、fdisk 的說明;

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

設備為例,以下同;

[root@localhost 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) 注:擴展應用,專家功能;

其實我們常用的只有注有中文的,其它的功能我們不常用(呵,主要是我不會用,否則早會

賣弄一下了);x 擴展功能,也不是常用的;一般的情況下只要懂得 d l m p q t w 就行

了;

下面以實例操作來詳述,沒有例子沒有辦法就,新手也看不懂;

2、列出當前操作硬盤的分區情況,用 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 76 200781 83 Linux

3、通過 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 保存退出!!!

4、通過 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 注:增加一個分區;

Copyright © Linux教程網 All Rights Reserved