磁盤分區

有兩個磁盤,一個是原來的20G的,還有一個是剛添加的硬盤10G的
[root@kylin ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000e719d

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 4605951 2097152 82 Linux swap / Solaris
/dev/sda3 4605952 41943039 18668544 83 Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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

用fdisk /dev/sdb 給磁盤分區
[root@kylin ~]# fdisk /dev/sdb

可以輸入m來查看有哪些用法,用的比較多的是n、p、w、d
n:添加新的分區
p:列出磁盤
w:保存退出
d:刪除磁盤

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)

按n添加分區
p是添加主分區
e是添加擴展分區
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended

p添加主分區
Select (default p): p
Partition number (1-4, default 1):

起始的大小
First sector (2048-20971519, default 2048):
Using default value 2048
第一個分區分2G直接用+就可以了
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +2G
Partition 1 of type Linux and of size 2 GiB is set
用p可以查看一下分區的信息
Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xa328ebda

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux

Command (m for help):

用如上的方法可以再加三個主分區

加了四個主分區之後在添加分區就加不了了,需要刪除一個主分區纔可以添加擴展分區
Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xa328ebda

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 12584959 2097152 83 Linux
/dev/sdb4 12584960 18876415 3145728 83 Linux

Command (m for help): n
If you want to create more than four partitions, you must replace a
primary partition with an extended partition first.

用d刪除一個分區,默認就是刪除第4個
Command (m for help): d
Partition number (1-4, default 4): 4
Partition 4 is deleted

刪完了之後看一下就沒有了第4個主分區了
Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xa328ebda

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 12584959 2097152 83 Linux

這樣就可以添加擴展分區了
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): e
Selected partition 4
First sector (12584960-20971519, default 12584960):
Using default value 12584960
Last sector, +sectors or +size{K,M,G} (12584960-20971519, default 20971519): +3G
Partition 4 of type Extended and of size 3 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xa328ebda

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 12584959 2097152 83 Linux
/dev/sdb4 12584960 18876415 3145728 5 Extended
擴展分區後面的ID和system是和主分區是不一樣的

在創建一個邏輯分區
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (12587008-18876415, default 12587008):
Using default value 12587008
Last sector, +sectors or +size{K,M,G} (12587008-18876415, default 18876415): +1G
Partition 5 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xa328ebda

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 12584959 2097152 83 Linux
/dev/sdb4 12584960 18876415 3145728 5 Extended
/dev/sdb5 12587008 14684159 1048576 83 Linux

Command (m for help):

這樣就有了第五個分區,
第五個邏輯分區是分的sdb4的擴展分區的空間

用p看一下一共各有7個分區
Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0e1cf973

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 12584959 2097152 83 Linux
/dev/sdb4 12584960 18876415 3145728 5 Extended
/dev/sdb5 12587008 14684159 1048576 83 Linux
/dev/sdb6 14686208 16783359 1048576 83 Linux
/dev/sdb7 16785408 18876415 1045504 83 Linux

用d刪除其中一個主分區
刪除第一個分區,再用p看一下是從第二個分區開始的,
Command (m for help): d
Partition number (1-7, default 7): 1
Partition 1 is deleted

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0e1cf973

Device Boot Start End Blocks Id System
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 12584959 2097152 83 Linux
/dev/sdb4 12584960 18876415 3145728 5 Extended
/dev/sdb5 12587008 14684159 1048576 83 Linux
/dev/sdb6 14686208 16783359 1048576 83 Linux
/dev/sdb7 16785408 18876415 1045504 83 Linux

如果刪除一個邏輯分區
刪除一個第五個分區的邏輯分區
還會把第六分區變成第五分區,第七分區變成第六分區,但是現在的第五分區不是原來的第五分區,可以看一下起始值和終止值
Command (m for help): d
Partition number (2-7, default 7): 5
Partition 5 is deleted

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0e1cf973

Device Boot Start End Blocks Id System
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 12584959 2097152 83 Linux
/dev/sdb4 12584960 18876415 3145728 5 Extended
/dev/sdb5 14686208 16783359 1048576 83 Linux
/dev/sdb6 16785408 18876415 1045504 83 Linux

退出不保存的話就按一下q,回車就可以了
然後用fdisk -l來查看一下磁盤分區的情況,因爲沒有保存,所有樹苗分區都沒有
[root@kylin ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000e719d

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 4605951 2097152 82 Linux swap / Solaris
/dev/sda3 4605952 41943039 18668544 83 Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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

重新分區,直接先創建一個擴展分區
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): e
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +3G
Partition 1 of type Extended and of size 3 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xb8e8a5cc

Device Boot Start End Blocks Id System
/dev/sdb1 2048 6293503 3145728 5 Extended

再次創建分區的時候就提示就發生變化了,原來只有p和e,現在在有主分區和擴展分區的基礎啊上會出現一個邏輯分區l,
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)

創建一個主分區,也可以不按順序的來創建,直接創建一個3分區
Select (default p): p
Partition number (2-4, default 2): 3
First sector (6293504-20971519, default 6293504):
Using default value 6293504
Last sector, +sectors or +size{K,M,G} (6293504-20971519, default 20971519): +1G
Partition 3 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xb8e8a5cc

Device Boot Start End Blocks Id System
/dev/sdb1 2048 6293503 3145728 5 Extended
/dev/sdb3 6293504 8390655 1048576 83 Linux

再創建一個邏輯分區,是從5開始的,跳過了2和4,
主分區和擴展分區一共是4個,是從1-4
邏輯分區是從5開始的
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (4096-6293503, default 4096):
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-6293503, default 6293503): +1G
Partition 5 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xb8e8a5cc

Device Boot Start End Blocks Id System
/dev/sdb1 2048 6293503 3145728 5 Extended
/dev/sdb3 6293504 8390655 1048576 83 Linux
/dev/sdb5 4096 2101247 1048576 83 Linux

用w保存退出
就有了剛纔的三個分區
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xb8e8a5cc

Device Boot Start End Blocks Id System
/dev/sdb1 2048 6293503 3145728 5 Extended
/dev/sdb3 6293504 8390655 1048576 83 Linux
/dev/sdb5 4096 2101247 1048576 83 Linux

如果覺的有哪個分區不對的,還是可以刪除了重新改的
[root@kylin ~]# 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.

Command (m for help): d
Partition number (1,3,5, default 5): 1
Partition 1 is deleted

總結:
1、主分區+擴展分區最多有4個
2、擴展分區不寫數據,需要把擴展分區變成邏輯分區後纔可以格式化寫數據,數據是寫在邏輯分區裏面的
3、邏輯分區是從5開始的,是連續的,如果有5678,四個分區,刪除一個6分區,在次查看的時候會是567三個分區,下載的67是原來的78
4、主分區是可以間斷的,如果有1234,4個分區,如果刪除一個3分區,用p查看的時候只會出現124三個分區

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章