硬盘分区及格式化

1案例1:硬盘分区及格式化
1.1 问题

本例要求熟悉硬盘分区结构,使用fdisk分区工具在磁盘/dev/vdb上按以下要求建立分区:

  1. 采用默认msdos分区模式
  2. 第一个分区/dev/vdb1的大小为200MiB
  3. 第二个分区/dev/vdb2的大小为2000MiB
  4. 第三个分区/dev/vdb3的大小为1000MiB
    完成分区后,能够配置开机自动挂载/dev/vdb2分区:
  5. 文件系统类型为EXT4
  6. 将其挂载到/mnt/part2目录
1.2 方案

实现此案例需要按照如下步骤进行。

步骤一:新建分区表

1)打开fdisk工具,操作磁盘/dev/vdb

[root@server0 ~]# fdisk  /dev/vdb
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 0x9ac1bc10.
Command (m for help):                         //交互操作提示信息

2)新建第1个分区/dev/vdb1

Command (m for help): n                                  //新建分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
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): +200M  
Partition 1 of type Linux and of size 200 MiB is set      //结束位置+200MiB大小
Command (m for help): p                                  //确认当前分区表
.. ..
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      411647      204800   83  Linux

3)新建第2个分区/dev/vdb2

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p                                 //类型为p(主分区)
Partition number (2-4, default 2): 2                    //分区编号2
First sector (411648-20971519, default 411648):         //起始位置默认
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-20971519, default 20971519): +2000M
Partition 2 of type Linux and of size 2 GiB is set       //结束位置+2000MiB大小
Command (m for help): p                                  //确认当前分区表
.. ..
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      411647      204800   83  Linux
/dev/vdb2          411648     4507647     2048000   83  Linux

4)新建第3个分区/dev/vdb3

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 (4507648-20971519, default 4507648): 
Using default value 4507648
Last sector, +sectors or +size{K,M,G} (4507648-20971519, default 20971519): +1000M
Partition 3 of type Linux and of size 1000 MiB is set
Command (m for help): p                                  //确认当前分区表
.. ..
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      411647      204800   83  Linux
/dev/vdb2          411648     4507647     2048000   83  Linux
/dev/vdb3         4507648     6555647     1024000   83  Linux

5)调整分区类型标识(可选)
将/dev/vdb1的类型(默认为83,表示EXT2/3/4分区)修改为8e(LVM设备):

Command (m for help): t                                  //修改分区类型标识
Partition number (1-3, default 3): 1                     //指定第1个分区
Hex code (type L to list all codes): 8e                 //类型改为8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p                                  //确认当前分区表
.. ..
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      411647      204800   8e  Linux LVM
/dev/vdb2          411648     4507647     2048000   83  Linux
/dev/vdb3         4507648     6555647     1024000   83  Linux

6)保存分区更改,退出fdisk分区工具

Command (m for help): w                                  //保存并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

7)刷新分区表

[root@server0 ~]# partprobe  /dev/vdb         //重新检测磁盘分区
//或者
[root@server0 ~]# reboot                     //对已使用中磁盘的分区调整,应该重启一次
.. ..

步骤二:格式化及挂载

1)将分区/dev/vdb2格式化为EXT4文件系统

[root@server0 ~]# mkfs.ext4  /dev/vdb2
.. .. 
Allocating group tables: done  
Writing inode tables: done 
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

2)配置开机自动挂载

[root@server0 ~]# vim  /etc/fstab
.. ..
/dev/vdb2       /mnt/part2      ext4    defaults        0 0

3)创建挂载点,并验证挂载配置

[root@server0 ~]# mkdir  /mnt/part2                 //创建挂载点
[root@server0 ~]# mount  -a                         //挂载fstab中的可用设备
[root@server0 ~]# df  -hT  /mnt/part2/                 //检查文档所在的文件系统及设备
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/vdb2      ext4  1.9G  5.9M  1.8G   1% /mnt/part2
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值