首先查看系統中的硬盤
[root@svnhost ~]# 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做分區
[root@svnhost ~]# 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.
創建文件系統
[root@svnhost ~]# mkfs -t ext3 /dev/sdb1
[root@svnhost /]# mkfs -t ext3 /dev/sdb2
[root@svnhost /]# mkfs -t ext3 /dev/sdb5
編輯系統文件
[root@svnhost /]#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等,必須放在引導分區中。