Resizing server hard disks through LVM

Source: Internet
Author: User
Tags hex code
After several years of operation, the company's FTP server has encountered insufficient space and decided to use LVM to resize the server. Idea: first copy the data, purchase a large-capacity hard disk and add it to the server, and then convert the existing common partition into a physical volume, finally, you can use physical volumes to create logical volume groups to expand the capacity. Implementation Process: A. Check system

After several years of operation, the company's FTP server has encountered insufficient space and decided to use LVM to resize the server.

Idea: first copy the data, purchase a large-capacity hard disk and add it to the server, and then convert the existing common partition into a physical volume, finally, you can use physical volumes to create logical volume groups to expand the capacity.

Implementation process:

A. Check whether the LVM tool is installed in the system. if it is not installed, download and install it.

[Root @ linuxas ~] # Rpm-qa | grep lvm

System-config-lvm-1.0.22-1.0.el5

Lvm2-2.02.16-3.el5

B. create and manage LVM

1. create or convert a partition

[Root @ linuxas ~] # Fdisk/dev/sda

The number of cylinders for this disk is set to 1044.

There is nothing wrong with that, but this is larger than1024,

And coshould in certain setups cause problems:

1) software that runs at boot time (e.g., old versions ofLILO)

2) booting and partitioning software from other OSs

(E.g., dos fdisk, OS/2 FDISK)

Command (m for help): p (view partition information)

Disk/dev/sda: 8589 MB, 8589934592 bytes

255 heads, 63 sectors/track, 1044 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

/Dev/sda1*1 25 200781 83 Linux

/Dev/sda2 26 535 4096575 83 Linux

/Dev/sda3 536 854 2562367 + 83 Linux

/Dev/sda4 855 1044 1526175 5 Extended

/Dev/sda5 855 905 409626 82 Linux swap/Solaris

/Dev/sda6 906 1044 1116486 83 Linux

Command (m for help): t (change partition type)

Partition number (1-6): 6 (convert 6th partitions to LVM)

Hex code (type L to list codes): 8e (specify the partition type as "8e" or LVM)

Changed system type of partition 6 to 8e (Linux LVM)

Command (m for help): w (save)

The partition table has been altered!

Calling ioctl () to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Scared ?? Bi? Why? ?.

The kernel still uses the old table.

The new table will be used at the next reboot.

Syncing disks.

2. create a physical volume

[Root @ linuxas/] # pvcreate/dev/sda6

Can't open/dev/sda6 exclusively. Mounted filesystem?

The above error occurs because the partition file is in use and umount is required.

[Root @ linuxas/] # pvcreate/dev/sda6

Physical volume "/dev/sda6" successfully created

After creating a physical volume, you can run the "pvdisplay" command to view the physical volume status.

[Root @ linuxas/] # pvdisplay

--- NEW Physical volume ---

PV Name/dev/sda6

VG Name

PVs Size 1.06 GB

Allocatable NO

PE Size (KByte) 0

Total PE 0

Free PE 0

Allocated PE 0

Pvuuid N2LgeT-RB4Y-8YEP-lO2J-tDWu-UeCT-4Obl8p

3. create a logical volume Group

[Root @ linuxas/] # vgcreate tgt/dev/sda6

Volume group "tgt" successfully created

You have new mail in/var/spool/mail/root

View logical volume groups

[Root @ linuxas/] # vgdisplay

--- Volume group ---

VG Name tgt

System ID

Format lvm2

Metadata Areas 1

Metadata Sequence No 1

VG Access read/write

VG Status resizable

Max lv 0

Cur LV 0

Open LV 0

Max PV 0

Cur PV 1

Act PV 1

VG Size 1.06 GB (VG is the Size of the logical volume group)

PE Size 4.00 MB (PE is the minimum storage unit of the logical volume group)

Total PE 272

Alloc PE/Size 0/0

Free PE/Size 272/1 .06 GB

Vg uuid g33wzW-yCvX-gc64-YQuD-LYeP-zgra-TGAa8G

4. activate a logical volume Group

[Root @ linuxas/] # vgchange-a y tgt

0 logical volume (s) in volume group "tgt" now active

5. create a logical volume

[Root @ linuxas/] # lvcreate-L 1000 M-n lvm tgt (-L specifies the size,-n specifies the name of the logical volume)

Logical volume "lvm" created

6. create a file system

[Root @ linuxas/] # mkfs-j/dev/tgt/lvm

Mke2fs 1.39 (29-may-2006)

Filesystem label =

OS type: Linux

Block size = 4096 (log = 2)

Fragment size = 4096 (log = 2)

128000 inodes, 256000 blocks

12800 blocks (5.00%) reserved for the super user

First data block = 0

Maximum filesystem blocks = 264241152

8 block groups

32768 blocks per group, 32768 fragments per group

16000 inodes per group

Superblock backups stored on blocks:

32768,983 04, 163840,229 376

Writing inode tables: done

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mountsor

180 days, whichever comes first. Use tune2fs-c or-I tooverride.

7. Mount a file system

[Root @ linuxas/] # mount-t ext3/dev/tgt/lvm/home

C. resizing LVM

1. add a new hard disk and perform partitioning, and specify it as LVM.

[Root @ linuxas/] # fdisk-l

Disk/dev/sda: 8589 MB, 8589934592 bytes

255 heads, 63 sectors/track, 1044 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

/Dev/sda1*1 25 200781 83 Linux

/Dev/sda2 26 535 4096575 83 Linux

/Dev/sda3 536 854 2562367 + 83 Linux

/Dev/sda4 855 1044 1526175 5 Extended

/Dev/sda5 855 905 409626 82 Linux swap/Solaris

/Dev/sda6 906 1044 1116486 8e Linux LVM

Disk/dev/sdb: 5368 MB, 5368709120 bytes

255 heads, 63 sectors/track, 652 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

/Dev/sdb1 1 652 5237158 + 8e Linux LVM

2. create a physical volume

[Root @ linuxas/] # pvcreate/dev/sdb1

Physical volume "/dev/sdb1" successfully created

3. add the new physical volume to the existing logical volume group.

[Root @ linuxas/] # vgextend tgt/dev/sdb1

Volume group "tgt" successfully extended

4. resizing LVM

[Root @ linuxas/] # lvextend-L 5368 M/dev/tgt/lvm (this command sets the total capacity of this volume to 5368 M)

Extending logical volume lvm to 5.24 GB

Logical volume lvm successfully resized

Alternatively, use [root @ linuxas/] # lvextend-L + 1000 M/dev/tgt/lvm (this command increases the total capacity of this volume by 1000 M)

[Root @ linuxas/] # e2fsck-f/dev/tgt/lvm (check the relationship between inode and block of the LVM device)

[Root @ linuxas/] # resize2fs/dev/tgt/lvm (for effective capacity)

Related Article

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.