调整现有磁盘分区

3 案例3:调整现有磁盘的分区
3.1 问题

本例要求沿用前一天案例,对磁盘/dev/vdb的分区表进行调整,要求如下:不更改原有分区,利用剩余空间新增三个分区,大小依次为:500MIB、2000MIB、512MIB
然后再基于刚建立的2000MIB分区构建新的LVM存储:

  1. 新的逻辑卷命名为database,大小为50个物理扩展单元(Physical Extent),属于datastore卷组
  2. 在datastore卷组中的所有逻辑卷,其物理扩展单元(Physical Extent)的大小为16MIB
  3. 使用ext3文件系统对逻辑卷database格式化,此逻辑卷应该在开机时自动挂载到/mnt/database目录
3.2 方案

创建卷组时,可以通过-s选项指定PE的大小
在给新建的逻辑卷分配空间时,空间大小只能是PE大小的倍数

3.3 步骤

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

步骤一:调整现有磁盘分区

1)新建扩展分区(使用剩余可用空间)

[root@server0 ~]# fdisk  /dev/vdb
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
Command (m for help): n                                 //新建分区
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e                                 //类型指定为e(扩展分区)
Selected partition 4                                     //只一个可用编号,自动选取
First sector (6555648-20971519, default 6555648):          //起始位置默认
Using default value 6555648
Last sector, +sectors or +size{K,M,G} (6555648-20971519, default 20971519): 
Using default value 20971519                             //结束位置默认
Partition 4 of type Extended and of size 6.9 GiB is set
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
/dev/vdb4         6555648    20971519     7207936    5  Extended

2)在扩展分区中新建3个逻辑分区
创建第1个逻辑卷(由于主分区编号已用完,分区类型自动选I逻辑分区):

Command (m for help): n 
All primary partitions are in use
Adding logical partition 5                              //分区编号5
First sector (6557696-20971519, default 6557696):          //起始位置默认
Using default value 6557696
Last sector, +sectors or +size{K,M,G} (6557696-20971519, default 20971519): +500M
                                                      //结束位置默认
Partition 5 of type Linux and of size 500 MiB is set

创建第2个逻辑卷:

Command (m for help): n
All primary partitions are in use
Adding logical partition 6                              //分区编号6
First sector (7583744-20971519, default 7583744):          //起始位置默认
Using default value 7583744
Last sector, +sectors or +size{K,M,G} (7583744-20971519, default 20971519): +2000M
                                                      //结束位置默认
Partition 6 of type Linux and of size 2 GiB is set

创建第3个逻辑卷:

Command (m for help): n
All primary partitions are in use
Adding logical partition 7                              //分区编号7
First sector (11681792-20971519, default 11681792):      //起始位置默认
Using default value 11681792
Last sector, +sectors or +size{K,M,G} (11681792-20971519, default 20971519): +512M
                                                      //结束位置默认
Partition 7 of type Linux and of size 512 MiB is set

根据预计的用途调整分区类型(可选):

Command (m for help): t                                 //修改
Partition number (1-7, default 7): 5                     //第5个分区
Hex code (type L to list all codes): 8e                 //类型为8e(LVM)
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): t                                 //修改
Partition number (1-7, default 7): 6                     //第6个分区
Hex code (type L to list all codes): 8e                 //类型为8e(LVM)
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): t                                 //修改
Partition number (1-7, default 7): 7                     //第7个分区
Hex code (type L to list all codes): 82                 //类型为82(交换分区)
Changed type of partition 'Linux' to 'Linux swap / Solaris'

确认分区结果并保存:

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
/dev/vdb4         6555648    20971519     7207936    5  Extended
/dev/vdb5         6557696     7581695      512000   8e  Linux LVM
/dev/vdb6         7583744    11679743     2048000   8e  Linux LVM
/dev/vdb7        11681792    12730367      524288   82  Linux swap / Solaris
Command (m for help): w                                 //保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.                                         //提示重启

3)刷新分区表

[root@server0 ~]# partprobe  /dev/vdb
[root@server0 ~]# reboot

步骤二:新建卷组、逻辑卷

1)新建卷组datastore,指定PE大小为16MIB

[root@server0 ~]# lvcreate  -l 50  -n  database  datastore
  Logical volume "database" created
[root@server0 ~]# lvscan                                  //确认新建的逻辑卷
  ACTIVE            '/dev/systemvg/vo' [180.00 MiB] inherit
  ACTIVE            '/dev/datastore/database' [800.00 MiB] inherit

步骤三:格式化及使用逻辑卷

1)格式化逻辑卷/dev/datastore/database

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

2)配置开机挂载

[root@server0 ~]# mkdir  /mnt/database                     //创建挂载点
[root@server0 ~]# vim  /etc/fstab
.. ..
/dev/datastore/database         /mnt/database   ext3    defaults    0 0

3)验证挂载配置

[root@server0 ~]# mount  -a
[root@server0 ~]# df  -hT  /mnt/database/                 //确认挂载点设备
Filesystem                     Type  Size  Used Avail Use% Mounted on
/dev/mapper/datastore-database ext3  772M  828K  715M   1% /mnt/database
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值