磁盘分区

有两个磁盘,一个是原来的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三个分区

转载于:https://blog.51cto.com/huazi1991/2073253

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值