Linux LVM空间扩容演示

化逐渐成为我们日常运维工作的主要部署策略。在化带来的各种好处中,硬件资源动态调整是传统物理机难以企及的优势方面。针对不同类型的应用和性能需求,我们可以为各个应用系统提供更加个性化的部署方案和资源。而且,当存储、CPU和内存等资源不足的时候,我们是可以快速的提供资源补充给应用。

LVM是一种源自Unix环境,在上广泛应用的逻辑盘存储方案。借助LVM,可以在保证各个目录分区稳定,又可以实现各目录存储资源灵活分配。

本文主要系统介绍环境下,LVM实现资源扩容步骤方法。留待需要朋友待查。

1、环境介绍

笔者使用Linux 6.5进行测试,背景是一台用于测试搭建的服务器,需要转换为正式投产,但是原有可用根节点空间只有50G左右。

[root@Testserver vg_li6]# df -h

Filesystem                          Size  Used Avail Use% Mounted on

/dev/mapper/vg_li6-lv_root  50G  20G  27G  43% /

tmpfs                                3.9G  232K  3.9G  1% /dev/shm

/dev/sda1                            485M  39M  421M  9% /boot

/dev/mapper/vg_li6-lv_home  26G  173M  24G  1% /home

目标是通过外围化环境,增加存储空间,并且将增加的空间转移到/目录下。也就是增加在vg_li6虚拟磁盘组的lv_root逻辑卷下面。

2、增加磁盘空间和分区

联系负责化的同事,为虚拟机增加虚拟磁盘sdb。通过fdisk命令,可以比较清晰的查看到。

[root@Testserver ~]# fdisk -l

Disk /dev/sda: 85.9 GB, 85899345920 bytes

255 heads, 63 sectors/track, 10443 cylinders

(篇幅原因,有省略……)

Disk /dev/sdb: 107.4 GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054 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: 0x00000000

使用fdisk命令进行格式化。

[root@Testserver ~]# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x44e9daf0.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

        switch off the mode (command ‘c') and change display units to

        sectors (command ‘u').

Command (m for help): n –创建新的磁盘组

Command action

  e  extended

  p  primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-13054, default 1): 

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054): 

Using default value 13054

Command (m for help): w –写入磁盘分区信息

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

查看fdisk结果。

[root@Testserver ~]# fdisk -l

Disk /dev/sda: 85.9 GB, 85899345920 bytes

255 heads, 63 sectors/track, 10443 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: 0x00064fe0

  Device Boot      Start        End      Blocks  Id  System

/dev/sda1  *          1          64      512000  83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64      10444    83373056  8e  Linux LVM

(篇幅原因,有省略……)

Disk /dev/sdb: 107.4 GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054 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: 0x44e9daf0

  Device Boot      Start        End      Blocks  Id  System

/dev/sdb1              1      13054  104856223+  83  Linux

3、LVM管理设置

总的步骤应该是这样:首先需要让LVM认可/dev/sdb1是一个可用的PV(Physical Volume),之后将其加入到VG里面去,补充VG资源。最后拓展lv_root磁盘空间。

当前LVM情况如下:

lvm> vgs

  VG              #PV #LV #SN Attr  VSize  VFree

  vg_li6  1  3  0 wz–n- 79.51g    0 

lvm> lvs

  LV      VG              Attr      LSize  Pool Origin Data%  Move Log Cpy%Sync Convert

  lv_home vg_li6 -wi-ao—- 25.63g                                             

  lv_root vg_li6 -wi-ao—- 50.00g                                             

  lv_swap vg_li6 -wi-ao—-  3.88g     

lvm> pvs

  PV        VG              Fmt  Attr PSize  PFree

  /dev/sda2  vg_li6 lvm2 a–  79.51g    0

此时的pv只有一个/dev/sda2,全部用满。首先创建/dev/sdb1作为PV。

[root@Testserver ~]# pvcreate /dev/sdb1

  dev_is_mpath: failed to get device for 8:17

  Physical volume “/dev/sdb1” successfully created

[root@Testserver ~]# pvs

  PV        VG              Fmt  Attr PSize  PFree 

  /dev/sda2  vg_li6 lvm2 a–  79.51g      0 

  /dev/sdb1                  lvm2 a–  100.00g 100.00g

往VG里面增加PV,作为空间拓容。

lvm> vgs

  VG              #PV #LV #SN Attr  VSize  VFree

  vg_li6  1  3  0 wz–n- 79.51g    0

lvm> vgextend vg_li6 /dev/sdb1

  Volume group “vg_li6” successfully extended

lvm> vgs

  VG              #PV #LV #SN Attr  VSize  VFree 

  vg_li6  2  3  0 wz–n- 179.50g 100.00g –剩余空间增加

lvm> pvs

  PV        VG              Fmt  Attr PSize  PFree 

  /dev/sda2  vg_li6 lvm2 a–  79.51g      0 

  /dev/sdb1  vg_li6 lvm2 a–  100.00g 100.00g

拓展lv_root空间。

[root@Testserver vg_li6]# lvextend -L +70G /dev/vg_li6/lv_root 

  Extending logical volume lv_root to 120.00 GiB

  Logical volume lv_root successfully resized

4、文件系统识别

注意:此时文件系统并没有认可本次增加。

[root@Testserver vg_li6]# df -h

Filesystem                          Size  Used Avail Use% Mounted on

/dev/mapper/vg_li6-lv_root  50G  20G  27G  43% /

tmpfs                                3.9G  232K  3.9G  1% /dev/shm

/dev/sda1                            485M  39M  421M  9% /boot

/dev/mapper/vg_li6-lv_home  26G  173M  24G  1% /home

需要使用resize2fs命令进行刷新。

[root@Testserver vg_li6]# resize2fs /dev/vg_li6/lv_root

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/vg_li6/lv_root is mounted on /; on-line resizing required

old desc_blocks = 4, new_desc_blocks = 8

Performing an on-line resize of /dev/vg_li6/lv_root to 31457280 (4k) blocks.

The filesystem on /dev/vg_li6/lv_root is now 31457280 blocks long.

[root@Testserver vg_li6]# df -h

Filesystem                          Size  Used Avail Use% Mounted on

/dev/mapper/vg_li6-lv_root  119G  20G  93G  18% /

tmpfs                                3.9G  232K  3.9G  1% /dev/shm

/dev/sda1                            485M  39M  421M  9% /boot

/dev/mapper/vg_li6-lv_home  26G  173M  24G  1% /home

5、结论

在之前笔者的文章中,比较详细的介绍过LVM的相关内容。本文从操作步骤的角度,逐步介绍增加LVM空间的方法。

  • 在LVM中设置精简资源调配卷(第四部分)
  • 使用条块化I/O管理多个LVM磁盘(第五部分)

转载自:https://www.linuxidc.com/Linux/2015-10/123960.htm

声明: 除非转自他站(如有侵权,请联系处理)外,本文采用 BY-NC-SA 协议进行授权 | 智乐兔
转载请注明:转自《Linux LVM空间扩容演示
本文地址:https://www.zhiletu.com/archives-4894.html
关注公众号:智乐兔

赞赏

wechat pay微信赞赏alipay pay支付宝赞赏

上一篇
下一篇

相关文章

在线留言

你必须 登录后 才能留言!