1. 程式人生 > >centos7 新增硬碟和分割槽

centos7 新增硬碟和分割槽



首先檢視系統中的硬碟

[[email protected] ~]# fdisk -l

Disk /dev/sda: 120.0 GB, 120034123776 bytes, 234441648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00033922

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   234440703   116707328   8e  Linux LVM

Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 12.0 GB, 12004098048 bytes, 23445504 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdb: 1999.8 GB, 1999844147200 bytes, 3905945600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 53.8 GB, 53750005760 bytes, 104980480 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

系統中有2塊盤/dev/sda和/dev/sdb. /dev/sda已經做好分割槽。下面對/dev/sdb做分割槽

[[email protected] ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x8626c507.

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
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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)

Command (m for help): n                                                 //新建主分割槽
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-3905945599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-3905945599, default 3905945599): +500G                                 //輸入分割槽大小
Partition 1 of type Linux and of size 500 GiB is set

Command (m for help): p                                                                                                                                    //列印分割槽

Disk /dev/sdb: 1999.8 GB, 1999844147200 bytes, 3905945600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x8626c507

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  1048578047   524288000   83  Linux

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (1048578048-3905945599, default 1048578048):
Using default value 1048578048
Last sector, +sectors or +size{K,M,G} (1048578048-3905945599, default 3905945599): +500G
Partition 2 of type Linux and of size 500 GiB is set

Command (m for help): p

Disk /dev/sdb: 1999.8 GB, 1999844147200 bytes, 3905945600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x8626c507

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  1048578047   524288000   83  Linux
/dev/sdb2      1048578048  2097154047   524288000   83  Linux

Command (m for help): n                                                                                                                           //新建擴充套件分割槽
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): e
Partition number (3,4, default 3):
First sector (2097154048-3905945599, default 2097154048):
Using default value 2097154048
Last sector, +sectors or +size{K,M,G} (2097154048-3905945599, default 3905945599):
Using default value 3905945599
Partition 3 of type Extended and of size 862.5 GiB is set

Command (m for help): p

Disk /dev/sdb: 1999.8 GB, 1999844147200 bytes, 3905945600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x8626c507

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  1048578047   524288000   83  Linux
/dev/sdb2      1048578048  2097154047   524288000   83  Linux
/dev/sdb3      2097154048  3905945599   904395776    5  Extended

Command (m for help): n                                                                                                               //新建邏輯分割槽
Partition type:
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (2097156096-3905945599, default 2097156096):
Using default value 2097156096
Last sector, +sectors or +size{K,M,G} (2097156096-3905945599, default 3905945599):
Using default value 3905945599
Partition 5 of type Linux and of size 862.5 GiB is set

Command (m for help): p

Disk /dev/sdb: 1999.8 GB, 1999844147200 bytes, 3905945600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x8626c507

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  1048578047   524288000   83  Linux
/dev/sdb2      1048578048  2097154047   524288000   83  Linux
/dev/sdb3      2097154048  3905945599   904395776    5  Extended
/dev/sdb5      2097156096  3905945599   904394752   83  Linux

Command (m for help): w                                                                                        //寫入新的分割槽表
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

建立檔案系統
[[email protected] ~]# mkfs -t ext3 /dev/sdb1

[[email protected] /]# mkfs -t ext3 /dev/sdb2

[[email protected] /]# mkfs -t ext3 /dev/sdb5

編輯系統檔案

[[email protected] /]#vi /etc/fstab

新增:

/dev/sdb1                       /u01            ext3    defaults        0 0
/dev/sdb2                       /u02            ext3    defaults        0 0
/dev/sdb5                       /u03            ext3    defaults        0 0

至此,新建的硬碟分割槽在系統重啟時就會自動掛載。

主分割槽,擴充套件分割槽和邏輯分割槽

主分割槽,也稱為主磁碟分割槽,和擴充套件分割槽、邏輯分割槽一樣,是一種分割槽型別。主分割槽中不能再劃分其他型別的分割槽,因此每個主分割槽都相當於一個邏輯磁碟(在這一點上主分割槽和邏輯分割槽很相似,但主分割槽是直接在硬碟上劃分的,邏輯分割槽則必須建立於擴充套件分割槽中)。

1. 一個硬碟可以有1到3個主分割槽和1個擴充套件分割槽,也可以只有主分割槽而沒有擴充套件分割槽,但主分割槽必須至少有1個,擴充套件分割槽則最多隻有1個,且主分割槽+擴充套件分割槽總共不能超過4個。邏輯分割槽可以有若干個。  

(硬碟的第一個扇區最重要,其上面有硬碟主引導記錄(佔用446bytes)和分割槽表(佔用64 bytes),之所以只能有四個主分割槽就是因為分割槽表只有64B,只能裝下4條記錄)

所以只能有四個主分割槽的硬碟的限制,並不是作業系統的限制,而最多隻能有一個拓展分割槽則是作業系統的限制

2. 分出主分割槽後,其餘的部分可以分成擴充套件分割槽,一般是剩下的部分全部分成擴充套件分割槽,也可以不全分,剩下的部分就浪費了。  

3. 擴充套件分割槽不能直接使用,必須分成若干邏輯分割槽。所有的邏輯分割槽都是擴充套件分割槽的一部分。   硬碟的容量=主分割槽的容量+擴充套件分割槽的容量;   擴充套件分割槽的容量=各個邏輯分割槽的容量之和。  

4. 由主分割槽和邏輯分割槽構成的邏輯磁碟稱為驅動器(Drive)或卷(Volume)。

5. 啟用的主分割槽會成為“引導分割槽”(或稱為“啟動分割槽”),引導分割槽會被作業系統和主機板認定為第一個邏輯磁碟(在DOS/Windows中會被識別為“驅動器C:”或“本地磁碟C:”,即通稱的C盤)。有關DOS/Windows啟動的重要檔案,如引導記錄、boot.ini、ntldr、ntdetect.com等,必須放在引導分割槽中。