码迷,mamicode.com
首页 > 其他好文 > 详细

磁盘分区

时间:2018-04-10 03:14:23      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:磁盘管理

磁盘分区
1、虚拟机添加磁盘:
在VMware workstation上添加一块硬盘步骤:虚拟机---设置---添加---选择硬盘---下一步---SCSI---创建新虚拟磁盘---最大磁盘大小分10GB---指定磁盘文件---完成
(服务器支持热拔插,虚拟机不支持)

2、fdisk -l命令:查看系统的磁盘都有哪些
[root@linux-01 ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x0008547b

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 62914559 29154304 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

3、fdisk命令可以给磁盘划分分区:
[root@linux-01 ~]# 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 0x84e97bfb.

Command (m for help):

4、常用选项:n p w d
-n:增加一个新的分区
-p:列出来所有分区
-w:保存
-d:删除一个分区
公式:主分区+扩展分区<=4

5、查看各选项的意思:
Command (m for help): m //输入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): 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: 0x84e97bfb

Device Boot Start End Blocks Id System

6、首先添加主分区:
Command (m for help): n //添加一个新分区
Partition type:
p primary (0 primary, 0 extended, 4 free) //输入p添加主分区(0个主分区,0个扩展分区,4个空闲分区)
e extended //输入e添加扩展分区
Select (default p): p //这里首先添加主分区,所以输入p
Partition number (1-4, default 1): 1 //默认分区号是从1开始的,第一个主分区
First sector (2048-20971519, default 2048): //直接回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +2G //输入+2G
Partition 1 of type Linux and of size 2 GiB is set //添加完成提示主分区1是Linux类型,大小为2G

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: 0x84e97bfb

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux //显示出第一个主分区

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): //直接回车,第二个主分区
First sector (4196352-20971519, default 4196352): //直接回车
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-20971519, default 20971519): +2G //添加第二主分区为2G
Partition 2 of type Linux and of size 2 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: 0x84e97bfb

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

Command (m for help): n //添加第三个主分区
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): //直接回车,默认数是3
First sector (8390656-20971519, default 8390656): //直接回车
Using default value 8390656
Last sector, +sectors or +size{K,M,G} (8390656-20971519, default 20971519): +1G //分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: 0x84e97bfb

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

Command (m for help): n //添加第四块主分区
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): p
Selected partition 4
First sector (10487808-20971519, default 10487808): //直接回车
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-20971519, default 20971519): +1G //给第四分区分1G主分区
Partition 4 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: 0x84e97bfb

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

Command (m for help): n
If you want to create more than four partitions, you must replace a //提示超过4个主分区
primary partition with an extended partition first.

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: 0x84e97bfb

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

Command (m for help): d //删除一个主分区,默认从后往前删除
Partition number (1-4, default 4): 4 //输入4删除第四主分区
Partition 4 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: 0x84e97bfb

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

7、添加一个扩展分区:
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 (10487808-20971519, default 10487808):
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-20971519, default 20971519): +5G
Value out of range.
Last sector, +sectors or +size{K,M,G} (10487808-20971519, default 20971519): +4G //扩展分区分4G
Partition 4 of type Extended and of size 4 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: 0x84e97bfb

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 10487807 1048576 83 Linux
/dev/sdb4 10487808 18876415 4194304 5 Extended

8、添加两个逻辑分区:
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (10489856-18876415, default 10489856): //直接回车
Using default value 10489856
Last sector, +sectors or +size{K,M,G} (10489856-18876415, default 18876415): +1G //为逻辑分区5分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: 0x84e97bfb

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 10487807 1048576 83 Linux
/dev/sdb4 10487808 18876415 4194304 5 Extended
/dev/sdb5 10489856 12587007 1048576 83 Linux

Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (12589056-18876415, default 12589056): //直接回车
Using default value 12589056
Last sector, +sectors or +size{K,M,G} (12589056-18876415, default 18876415): +1G //为逻辑分区6
Partition 6 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: 0x84e97bfb

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 10487807 1048576 83 Linux
/dev/sdb4 10487808 18876415 4194304 5 Extended
/dev/sdb5 10489856 12587007 1048576 83 Linux
/dev/sdb6 12589056 14686207 1048576 83 Linux
(小技巧:添加分区时命令输错可以使用Ctrl+u来删除输错的字符)

9、d删除主分区时,指定分区删除
d删除逻辑分区时,比如逻辑分区有sdb5 sdb6,删除sdb5,使用p查看时sdb5还在,实际是把sdb5删除了,sdb6名称改为sdb5
实例:
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: 0x84e97bfb

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 10487807 1048576 83 Linux
/dev/sdb4 10487808 18876415 4194304 5 Extended
/dev/sdb5 10489856 12587007 1048576 83 Linux
/dev/sdb6 12589056 14686207 1048576 83 Linux

Command (m for help): d
Partition number (1-6, default 6): 1 //删除sdb1主分区
Partition 1 is deleted

Command (m for help): p //可以查看到sdb1被删除了

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: 0x84e97bfb

Device Boot Start End Blocks Id System
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 10487807 1048576 83 Linux
/dev/sdb4 10487808 18876415 4194304 5 Extended
/dev/sdb5 10489856 12587007 1048576 83 Linux
/dev/sdb6 12589056 14686207 1048576 83 Linux

Command (m for help): d
Partition number (2-6, default 6): 5 //删除逻辑分区sdb5
Partition 5 is deleted

Command (m for help): p //可以查看到sdb5依然在,其实是之前sdb5被删,sdb6改名为sdb5

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: 0x84e97bfb

Device Boot Start End Blocks Id System
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 10487807 1048576 83 Linux
/dev/sdb4 10487808 18876415 4194304 5 Extended
/dev/sdb5 12589056 14686207 1048576 83 Linux

10、逻辑分区从第5个分区号开始,而且必须是连续的,例如sdb5 sdb6 sdb7,而不能是sdb5 sdb7

(使用q可以退出来)
Command (m for help): q
[root@linux-01 ~]#

11、扩展分区仅仅是一个壳子,不能直接写数据,而是在逻辑分区下去写数据

磁盘分区

标签:磁盘管理

原文地址:http://blog.51cto.com/13669226/2096313

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!