Linux LVM space expansion demonstration

Source: Internet
Author: User

Linux LVM space expansion demonstration

Virtualization has gradually become the main deployment strategy for our daily O & M work. Among the various benefits brought by virtualization, dynamic adjustment of hardware resources is an advantage that traditional physical machines cannot match. For different types of applications and performance requirements, we can provide more personalized deployment and resource solutions for each application system. In addition, when resources such as storage, CPU, and memory are insufficient, we can quickly provide resources for the application.

LVM is a logical virtual disk storage solution widely used in Linux from a Unix environment. With LVM, the Linux directory partitions can be ensured to be stable, and the storage resources of various directories can be flexibly allocated.

This article mainly introduces how to resize resources using LVM in Linux. Waiting for a friend to be checked.

1. Environment Introduction

I used Linux 6.5 for testing. The background is a database server used for testing and construction. It needs to be converted to production, but the original available Root Node space is only about 50 GB.

[Root @ Testserver vg_li6] # df-h

Filesystem Size Used Avail Use % Mounted on

/Dev/mapper/vg_li6-lv_root 20G 20G 27G 43%/

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

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

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

The target is to increase the storage space through the peripheral virtualization environment and transfer the added space to the/directory. That is, it is added to the lv_root logical volume of the vg_li6 Virtual Disk group.

2. Increase disk space and partitions

Contact virtualization colleagues to add Virtual Disk sdb for the virtual machine. The fdisk command can be clearly viewed.

[Root @ Testserver ~] # Fdisk-l

Disk/dev/sda: 85.9 GB, 85899345920 bytes

255 heads, 63 sectors/track, 10443 cylinders

(Space reasons, omitted ......)

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

Use the fdisk command for formatting.

[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 stronugly recommended

Switch off the mode (command 'C') and change display units

Sectors (command 'U ').

Command (m for help): n-create a new disk group

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-write disk partition information

The partition table has been altered!

Calling ioctl () to re-read partition table.

Syncing disks.

View the fdisk result.

[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

(Space reasons, omitted ......)

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 management settings

The general steps should be as follows: First, let LVM recognize/dev/sdb1 as an available PV (Physical Volume), and then add it to VG to supplement VG resources. Expand the lv_root disk space.

The current LVM situation is as follows:

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

At this time, only one pv/dev/sda2 is available, all of which are full. First, create/dev/sdb1 as 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

Add PV to VG as space extension.

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-Increase in the remaining space

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

Expand the lv_root space.

[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. File System Identification

Note: The file system does not accept this increase.

[Root @ Testserver vg_li6] # df-h

Filesystem Size Used Avail Use % Mounted on

/Dev/mapper/vg_li6-lv_root 20G 20G 27G 43%/

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

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

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

You need to use the resize2fs command for Refresh.

[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

Ming an on-line resize of/dev/vg_li6/lv_root to 31457280 (4 k) 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 232 K 3.9G 1%/dev/shm

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

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

5. Conclusion

In my previous articles, I have introduced LVM in detail. This article describes how to increase LVM space from the perspective of operation steps.

  • Use LVM to create elastic disk storage-Part 1
  • Expanding/downgrading LVM in Linux (Part 2)
  • Recording and restoring logical volume snapshots in LVM (part 3)
  • Set a streamlined resource allocation volume in LVM (part 4)
  • Use fragmented I/O to manage multiple LVM disks (Part 5)

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.