萬盛學電腦網

 萬盛學電腦網 >> Linux教程 >> Linux利用fdisk工具建立分區的方法

Linux利用fdisk工具建立分區的方法

  當Linux系統硬盤還有不少空間的時候,我們能夠使用fdisk工具對系統進行分區,以滿足個人需求,那麼fdisk工具要如何使用呢?下面小編就給大家介紹下Linux使用fdisk建立分區的方法,感興趣的朋友可以來了解下。

 Linux利用fdisk工具建立分區的方法

  首先查看硬盤信息

  fdisk -l 如果有硬盤有剩余空間就可以對其進行分區

  [root@bogon 桌面]# fdisk -l

  Disk /dev/sda: 85.9 GB, 85899345920 bytes

  255 heads, 63 sectors/track, 10443 cylinders

  Units = cylinders of 16065 * 512 = 8225280 bytes

  Sector size (logical/physical): 512 bytes / 512 bytes

  I/O size (minimum/optimal): 512 bytes / 512 bytes

  Disk identifier: 0x000471ad

  Device Boot Start End Blocks Id System

  /dev/sda1 * 1 26 204800 83 Linux

  Partition 1 does not end on cylinder boundary.

  /dev/sda2 26 3851 30720000 83 Linux

  /dev/sda3 3851 4106 2048000 82 Linux swap / Solaris

  /dev/sda4 4106 10444 50912256 5 Extended

  /dev/sda5 4106 10444 50911232 83 Linux

  Disk /dev/sdb: 21.5 GB, 21474836480 bytes

  255 heads, 63 sectors/track, 2610 cylinders

  Units = cylinders of 16065 * 512 = 8225280 bytes

  Sector size (logical/physical): 512 bytes / 512 bytes

  I/O size (minimum/optimal): 512 bytes / 512 bytes

  Disk identifier: 0x00000000

  #從上面看出/dev/sda空間已經用完了,/dev/sdb沒有使用。

  下面我們對/dev/sdb 進行分區

  [root@bogon 桌面]# fdisk /dev/sdb

  Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

  Building a new DOS disklabel with disk identifier 0xfaa2aa49.

  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)

  WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to

  switch off the mode (command ‘c’) and change display units to

  sectors (command ‘u’)。

  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)

上一頁1234下一頁共4頁

  fdisk選中/dev/sdb 輸入m所有基本選項都出現,輸入n新建分區

  Command (m for help): n

  Command action

  e extended

  p primary partition (1-4)

  有擴展分區和主分區,邏輯分區在擴展分區中建立。注意到括號中的1-4,最多只能建四個主分區(包括擴展分區)。先建一個主分區:

  Command (m for help): n

  Command action

  e extended

  p primary partition (1-4)

  p #建主分區

  Partition number (1-4): 1 #分區號為1

  First cylinder (1-2610, default 1): #直接回車默認從第一個柱面開始劃分

  Using default value 1

  Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G #加空間大小,這裡有很多種選擇:+後面單位可以接M,G,K(記得要大寫)表示劃分你所加的空間,也可以是柱面數。不管怎樣都不能超過該磁盤剩余的空間否則無效。

  Command (m for help): p #分好後查看分區信息,剛所做的所有一目了然。

  Disk /dev/sdb: 21.5 GB, 21474836480 bytes

  255 heads, 63 sectors/track, 2610 cylinders

  Units = cylinders of 16065 * 512 = 8225280 bytes

  Sector size (logical/physical): 512 bytes / 512 bytes

  I/O size (minimum/optimal): 512 bytes / 512 bytes

  Disk identifier: 0xfaa2aa49

  Device Boot Start End Blocks Id System

  /dev/sdb1 1 262 2104483+ 83 Linux

  同上所述建立擴展分區:

  Command (m for help): n

  Command action

  e extended

  p primary partition (1-4)

  e #建立擴展分區

  Partition number (1-4): 4

  First cylinder (263-2610, default 263):

  Using default value 263

  Last cylinder, +cylinders or +size{K,M,G} (263-2610, default 2610): +4G

  Command (m for help): p

  Disk /dev/sdb: 21.5 GB, 21474836480 bytes

  255 heads, 63 sectors/track, 2610 cylinders

  Units = cylinders of 16065 * 512 = 8225280 bytes

  Sector size (logical/physical): 512 bytes / 512 bytes

  I/O size (minimum/optimal): 512 bytes / 512 bytes

  Disk identifier: 0xfaa2aa49

  Device Boot Start End Blocks Id System

  /dev/sdb1 1 262 2104483+ 83 Linux

  /dev/sdb4 263 785 4200997+ 5 Extended

上一頁12 34下一頁共4頁

  擴展分區建好我們就可以在擴展分區建立邏輯分區

  Command (m for help): n

  Command action

  l logical (5 or over)

  p primary partition (1-4)

  l #建邏輯分區

  First cylinder (263-785, default 263):

  Using default value 263

  Last cylinder, +cylinders or +size{K,M,G} (263-785, default 785): +2G

  Command (m for help): p

  Disk /dev/sdb: 21.5 GB, 21474836480 bytes

  255 heads, 63 sectors/track, 2610 cylinders

  Units = cylinders of 16065 * 512 = 8225280 bytes

  Sector size (logical/physical): 512 bytes / 512 bytes

  I/O size (minimum/optimal): 512 bytes / 512 bytes

  Disk identifier: 0xfaa2aa49

  Device Boot Start End Blocks Id System

  /dev/sdb1 1 262 2104483+ 83 Linux

  /dev/sdb4 263 785 4200997+ 5 Extended

  /dev/sdb5 263 524 2104483+ 83 Linux

  上面顯示已經建好一個主分區,一個邏輯分區,但是這些現在還沒有生效我們需要保存退出。

  Command (m for help): w #保存退出

  The partition table has been altered!

  Calling ioctl() to re-read partition table.

  Syncing disks.

  [root@bogon 桌面]# fdisk -l

  Disk /dev/sda: 85.9 GB, 85899345920 bytes

  255 heads, 63 sectors/track, 10443 cylinders

  Units = cylinders of 16065 * 512 = 8225280 bytes

  Sector size (logical/physical): 512 bytes / 512 bytes

  I/O size (minimum/optimal): 512 bytes / 512 bytes

  Disk identifier: 0x000471ad

  Device Boot Start End

copyright © 萬盛學電腦網 all rights reserved