linux磁盘分区与格式化分区磁盘

1. 为什么要对linux磁盘进行分区

对磁盘分区可以提升数据的安全性, 有助于数据读取的速度与效能的提升!

2. 如何对磁盘分区

1. 前置条件

语法

fdisk (选项) (参数)

选项

-b<分区大小>:指定每个分区的大小;
-l:列出指定的外围设备的分区表状况;
-s<分区编号>:将指定的分区大小输出到标准输出上,单位为区块;
-u:搭配"-l"参数列表,会用分区数目取代柱面数目,来表示每个分区的起始地址;
-v:显示版本信息。

实例

[root@donl-pc donl]# fdisk /dev/sdb

输入m查看命令(罗列出的为常用的命令)

Command (m for help): m
Command action
   d   delete a partition # 删除分区
   l   list known partition types # 列出分区信息
   m   print this menu # 显示操作帮助
   n   add a new partition # 添加一个新的分区
   p   print the partition table # 显示分区表单
   q   quit without saving changes # 不保存退出
   w   write table to disk and exit # 写入操作并退出
2. 开始分区
  1. p: 查看磁盘分区信息
Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x01aef726

   Device Boot      Start         End      Blocks   Id  System
  1. n: 新建一个分区
Command (m for help): n # 开始新建分区
Command action
   e   extended # 扩展分区
   p   primary partition (1-4) # [1]主分区
p # 输入p创建主分区
Partition number (1-4): 1 # 分区编号
First cylinder (1-652, default 1): 1 # [2]柱面起始编号
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): 300 # 柱面结束编号

注意:
[1] 在linux系统中 扩展分区与主分区个数之和只能是4个, 但是可以使用扩展分区再将其划分为逻辑分区(数量不限)
[2]: 可以使用的柱面编号进行分区, 也可以使用直接给定大小(+1024M)
再次输入p查看分区情况

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x01aef726

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         300     2409718+  83  Linux  # 这是新建的分区
  1. 新建扩展分区
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e # 选择扩展分区
Partition number (1-4): 2
First cylinder (301-652, default 301): 
Using default value 301
Last cylinder, +cylinders or +size{K,M,G} (301-652, default 652): 500

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x01aef726

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         300     2409718+  83  Linux
/dev/sdb2             301         500     1606500    5  Extended # 新建的扩展分区

注意: 新建的扩展分区无法直接格式化使用, 必须先将其划分为逻辑分区才可以使用

  1. 将扩展分区划分为逻辑分区
Command (m for help): n
Command action
   l   logical (5 or over) # 划分为扩展分区后, 此处发生了变化, 表示划分逻辑分区
   p   primary partition (1-4)
l # 选择划分逻辑分区
First cylinder (301-500, default 301): 
Using default value 301
Last cylinder, +cylinders or +size{K,M,G} (301-500, default 500): 500

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x01aef726

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         300     2409718+  83  Linux
/dev/sdb2             301         500     1606500    5  Extended
/dev/sdb5             301         500     1606468+  83  Linux # 新划分的逻辑分区, 其编号是从5开始的
  1. 将下面的分区都划分为了一个主分区, 但是你也可以做其他划分
  2. 保存修改
Command (m for help): w
The partition table has been altered!

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

磁盘格式化

1. 为什么要对磁盘格式化

磁盘分区需要先对其格式化才能正常使用

2. 如何格式化刚分区的磁盘

1. 前置条件

语法

mkfs (选项) (参数)

选项

fs:指定建立文件系统时的参数;
-t<文件系统类型>:指定要建立何种文件系统;
-v:显示版本信息与详细的使用方法;
-V:显示简要的使用方法;
-c:在制做档案系统前,检查该partition是否有坏轨。
2. 格式化分区

先了解一下:
ext2文件系统: 没有日志文件(商业致命缺陷)
ext3文件系统: ext2的升级(健全提高了ext2)
ext4文件系统: ext3的升级 (更加丰富和完善的功能)
点击查看ext2、ext3与ext4的区别
sdb分区信息:

[root@donl-pc donl]# ls -l /dev/sdb*
brw-rw----. 1 root disk 8, 16 3月  23 12:05 /dev/sdb
brw-rw----. 1 root disk 8, 17 3月  23 12:05 /dev/sdb1
brw-rw----. 1 root disk 8, 18 3月  23 12:05 /dev/sdb2
brw-rw----. 1 root disk 8, 19 3月  23 12:05 /dev/sdb3
brw-rw----. 1 root disk 8, 21 3月  23 12:05 /dev/sdb5
  1. /dev/sdb1格式化为ext3
[root@donl-pc donl]mkfs -t ext3 /dev/sdb1
  1. 可以使用Tab Tab查看简单其他命令
[root@donl-pc donl]mkfs # 按两下Tab键, 自动弹出下面的
mkfs          mkfs.ext2     mkfs.ext4     mkfs.msdos    
mkfs.cramfs   mkfs.ext3     mkfs.ext4dev  mkfs.vfat 

使用mkfs.ext4格式化/dev/sdb3(/dev/sdb3逻辑分区)

[root@donl-pc donl]mkfs.ext3 /dev/sdb3
  1. 划分其他的
[root@donl-pc donl]mkfs.ext4 /dev/sdb5
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值