硬盘的分区和格式化

硬盘分区和格式化

MBR/msdos分区模式

1-4个主分区,或者0-3个主分区+1个扩展分区(n个逻辑分区)
最大支持的容量为2.2TB的磁盘
扩展分区不能格式化

GPT分区模式

对于磁盘分区个数没有限制,受操作系统限制
最大支持18EB

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

采用默认的 MBR/msdos 分区模式
第1个分区 /dev/vdb1 的大小为 200MiB
第2个分区 /dev/vdb2 的大小为 2000MiB
第3个分区 /dev/vdb3 的大小为 1000MiB

完成分区后,能够配置开机自动挂载 /dev/vdb2 分区:

文件系统类型为 EXT4
将其挂载到 /mnt/part2 目录

方案:
fdisk分区工具用来建立msdos分区方案,其交互模式中的主要指令如下:

m:列出指令帮助
p:查看当前的分区表信息
n:新建分区
d:删除分区
t:更改分区标识
q:放弃分区更改并退出
w:保存对分区表所做的更改

步骤:
步骤一:新建分区表
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)新建第一个分区/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)新建第二个分区/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)新建第三个分区/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.

6)刷新分区表

    [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、付费专栏及课程。

余额充值