天天學一個 Linux 命令(78):fdisk

命令簡介

fdisk 命令用於查看磁盤使用狀況和磁盤分區,它可用於建立,刪除和修改磁盤分區。ui

語法格式

disk [-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device

選項說明

-b <大小>      #扇區大小(5十二、102四、2048或4096)
-c[=<模式>]    #兼容模式:「dos」或「nondos」(默認)
-h            #打印此幫助文本
-u[=<單位>]    #顯示單位:「cylinders」(柱面)或「sectors」(扇區,默認)
-v            #打印程序版本
-C <數字>      #指定柱面數
-H <數字>      #指定磁頭數
-S <數字>      #指定每一個磁道的扇區數

應用舉例

選擇要進行操做的磁盤this

[root@localhost ~]$ fdisk /dev/sdb

輸入 m 查看可執行的命令spa

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
   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)

輸入 p 列出磁盤目前的分區狀況code

Command (m for help): p
 
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1           1        8001   8e  Linux LVM
/dev/sdb2               2          26      200812+  83  Linux

輸入 d 而後選擇分區,刪除現有分區ci

Command (m for help): d
Partition number (1-4): 1
 
Command (m for help): d
Selected partition 2

查看分區狀況,確認分區已經刪除it

Command (m for help): print
 
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
 
Command (m for help):

輸入 n 創建新的磁盤分區,首先創建兩個主磁盤分區io

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p    #創建主分區
Partition number (1-4): 1  #分區號
First cylinder (1-391, default 1):  #分區起始位置
Using default value 1
last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100  #分區結束位置,單位爲扇區
 
Command (m for help): n  #再創建一個分區
Command action
   e   extended
   p   primary partition (1-4)
p 
Partition number (1-4): 2  #分區號爲2
First cylinder (101-391, default 101):
Using default value 101
Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M  #分區結束位置,單位爲M

確認分區創建成功table

Command (m for help): p
 
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101         125      200812+  83  Linux

再創建一個邏輯分區ast

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e  #選擇擴展分區
Partition number (1-4): 3
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391):
Using default value 391

確認擴展分區創建成功function

Command (m for help): p
 
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101         125      200812+  83  Linux
/dev/sdb3             126         391     2136645    5  Extended

在擴展分區上創建兩個邏輯分區

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l  #選擇邏輯分區
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M    
 
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (176-391, default 176):
Using default value 176
Last cylinder or +size or +sizeM or +sizeK (176-391, default 391):
Using default value 391

確認邏輯分區創建成功

Command (m for help): p
 
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101         125      200812+  83  Linux
/dev/sdb3             126         391     2136645    5  Extended
/dev/sdb5             126         175      401593+  83  Linux
/dev/sdb6             176         391     1734988+  83  Linux
 
Command (m for help):

保存操做信息

Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.

創建好分區以後咱們還須要對分區進行格式化才能在系統中使用磁盤。這個格式化命令後面的章節會給你們進行詳細講解。

image

相關文章
相關標籤/搜索