Linux磁盤分區

柱面:每一個盤片相同的同心圓環組成的一個立體結構app

扇區:扇形區域ide

磁頭:讀取數據工具

 

磁盤在Linux上屬於文件ui

通常HD開頭(IDE接口的硬盤)或者SD(SATA接口的硬盤)開頭this

a、b、c標示第幾塊磁盤spa

通常都是sda、sdb等code

sda1表示第一塊硬盤的第一塊分區blog

 

磁盤的分區接口

主流的分區機制有MBR和GPTci

1:MBR:主引導記錄。一般應用在使用BIOS的PC上(蘋果機不是的),該機制會佔用磁盤的頭512個字節用來存放引導代碼和分區表和啓動標示55AA(其餘的BIOS不能引導)

    缺點:支持的分區有限;只支持小於2T的硬盤(由於於尋址空間是32)

    分區:

     1:主分區最多4個,能夠直接使用

     2:擴展分區,該擴展分區會佔用一個主分區位置,以後必須建立邏輯分區纔可使用

2:GPT分區機制(64位尋址空間)

GPT分區機制:必須支持UEFI硬件才能使用,必須64位

 

磁盤分區的工具

1:fdisk,應用普遍,甚至包括救援模式下的Linux,可是不支持GPT模式

分區試驗:

1:先在虛擬機中添加一塊硬盤

2:

[root@gechong ~]# ll /dev | grep sd
brw-rw----. 1 root disk      8,   0 11月  5 16:15 sda
brw-rw----. 1 root disk      8,   1 11月  5 16:15 sda1
brw-rw----. 1 root disk      8,   2 11月  5 16:15 sda2
[root@gechong ~]# fdisk -l

Disk /dev/sda: 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: 0x000ee95c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM

Disk /dev/mapper/vg_gechong-lv_root: 17.7 GB, 17725128704 bytes
255 heads, 63 sectors/track, 2154 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
能夠看到有一塊磁盤sda,有兩個分區sda1和sda2
255 heads磁頭, 63 sectors/track扇區, 2610 cylinders柱面
 
 
Start起始柱面         End結束柱面
 

添加一塊磁盤後從新用fdisk -l命令查看:會顯示多了一塊磁盤

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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

可是其下面並無分區,由於咱們還沒有分區,分完以後會顯示在該、塊硬盤的下面

[root@gechong ~]# 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 0xb8fdd7dd.
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)

 

 

進入交互式界面只需按照提示一步一步建立分區便可

n爲建立新的分區

w保存後退出,不然不會生效

 

Command (m for help): n
Command action
e extended
p primary partition (1-4)

 

e爲擴展分區

p爲主分區

通常爲先創建主分區,以後創建擴展分區再在擴展分區上創建邏輯分區

注意:主分區ID爲1-4  邏輯分區必須大於等於5

 

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): +2G

Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 5
Value out of range.
Partition number (1-4): 3
First cylinder (263-1044, default 263):
Using default value 263
Last cylinder, +cylinders or +size{K,M,G} (263-1044, default 1044): +2G

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (263-524, default 263):
Using default value 263
Last cylinder, +cylinders or +size{K,M,G} (263-524, default 524): +2G

[root@gechong ~]# fdisk -l | grep sdb
Disk /dev/sdb: 8589 MB, 8589934592 bytes
/dev/sdb1               1         262     2104483+  83  Linux
/dev/sdb2             263         524     2104515    5  Extended
/dev/sdb5             263         524     2104483+  83  Linux

 若是沒有顯示,可使用partprobe命令更新內核後從新查看

 

[root@gechong ~]# cat /proc/partitions
major minor  #blocks  name

   8        0   20971520 sda
   8        1     512000 sda1
   8        2   20458496 sda2
   8       16    8388608 sdb
   8       17    2104483 sdb1
   8       18          1 sdb2
   8       21    2104483 sdb5
 252        0   17309696 dm-0
 252        1    3145728 dm-1

或者

[root@gechong ~]# ll /dev/sd*
brw-rw----. 1 root disk 8,  0 11月  5 16:59 /dev/sda
brw-rw----. 1 root disk 8,  1 11月  5 16:40 /dev/sda1
brw-rw----. 1 root disk 8,  2 11月  5 16:40 /dev/sda2
brw-rw----. 1 root disk 8, 16 11月  5 16:59 /dev/sdb
brw-rw----. 1 root disk 8, 17 11月  5 16:59 /dev/sdb1
brw-rw----. 1 root disk 8, 18 11月  5 16:59 /dev/sdb2
brw-rw----. 1 root disk 8, 21 11月  5 16:59 /dev/sdb5
相關文章
相關標籤/搜索