RPM: Linux Disk expansion

Source: Internet
Author: User
Tags hex code gparted

from:https://www.rootusers.com/how-to-increase-the-size-of-a-linux-lvm-by-expanding-the-virtual-machine-disk/

How to increase the size of a Linux LVM by expanding the virtual machine diskPosted by Jarrod on December, + Leave a comment (181) Go to comments

This post would cover how to increase the disk space for a VMware virtual machine running Linux which is using logical volum E Manager (LVM). Firstly we'll be increasing the size of the actual disk on the VMware Vsan, so at the hardware level–this I s the VM ' s. vmdk file. Once This was complete we'll get to the virtual machine and make the necessary changes through the operating system in Order to take advantage of the additional space, the have been provided by the hard drive being extended. This would involve creating a new partition with the new space, expanding the volume group and logical group, then finally Resizing the file system.

As there is a number of different ways to increase disk space I has also posted some different methods here:

    • Use GParted to increase disk size of a Linux native partition–in this article the virtual disk is expanded, however ther E is no LVM here just a Linux native partition that's expanded with the GParted live CD.
    • How to increase the size of a Linux LVM by adding a new disk–in This article a new virtual disk was added to the virtual Machine, a new partition was created, the volume group and logical volume are both expanded and then the filesystem is Resi Zed.
    • How to decrease the size of a Linux lvm–in this article the file system was shrunk followed by the LVM, allowing your to r Eclaim space in the volume group.

Update 18/04/2015:i has created a video guide of this post in CentOS 7 shown below.

Important Note: Be very careful if working with the commands in this article as they has the potential to cause a lot of damage to your Data. If you is working with virtual machines Make sure do a snapshot of your virtual machine beforehand, or otherwise ha ve some other form of up to date backup before proceeding. Note that a snapshot must not being taken until after the virtual disk have been increased, otherwise you'll not being able to Increase it. It could also is worth cloning the virtual machine first and testing out of this method on the clone.

Prerequisites: As this method uses the additional space to create a primary partition and you must not already has 4 partitions as you'll Not being able to create more than 4. If you don't have space for another partition then you'll need to consider a different method, there is some others in The above list.

Throughout my examples I'll be working with a VMware Vsan running Debian 6, this is set up with a 20GB disk And we'll be the increasing it by 10GB for a total final size of 30GB.

Identifying the partition type

As this method focuses the working with LVM, we'll first confirm, our partition type is actually Linux LVM by running The below command.

Fdisk-l

As can see in the above Image/dev/sda5 are listed as "Linux LVM" and it has the ID of 8e. The 8e hex code shows that it's a Linux LVM, while the shows a Linux native partition. Now, we have confirmed we is working with an LVM we can continue. For increasing the size of a Linux native partition (hex code) see this article.

Below is the disk information showing, we initial setup only have the one 20GB disk currently, which is under the Logi Cal Volume Named/dev/mapper/mega-root–this is what we'll be expanding with the new disk.

Note That/dev/mapper/mega-root are the volume made up from/dev/sda5 currently–this are what we'll be expanding.

Increasing the virtual hard disk

First off we increase the allocated disk space on the virtual machine itself. This is do by right clicking the virtual machine in VSphere, selecting Edit Settings, and then selecting the hard disk. In the below image I had changed the previously set hard disk of 20GB to 30GB while the virtual machine was up and running . Once Complete Click OK, which is all of the needs to being done in the VMware for this process.

If you were not able to modify the size of the disk, the provisioned size setting was greyed out. This can happen if the virtual machine have a snapshot in place, these'll need to be removed prior to making the changes to the disk. Alternatively need to shut down the virtual machine if it does not allow you to add or increase disks on the fly, If this is the case make the and then power it back on.

Detect the new disk space

Once The physical disk has been increased at the hardware level, we need to get into the operating system and create a new partition that makes use of the this space to proceed.

Before we can do this we need to check the new unallocated disk space are detected by the server and you can use "fdisk- L "To list the primary disk. You'll most likely see that the disk space was still showing as the same original size, at this point you can either Rebo OT the server and it would detect the changes on boot or can rescan your devices to avoid rebooting by running the Belo W command. Note need to change host0 depending on your setup.

echo "---" >/sys/class/scsi_host/host0/scan

Below is a image after performing this and confirming the new space is displaying.

Partition the new disk space

As outlined in my previous images the disk in my example that I am working with IS/DEV/SDA, so we use Fdisk to create a n EW primary partition to make use of the new expanded disk space. Note that we don't have a 4 primary partitions already in place, and making this method possible.

Fdisk/dev/sda

We is now using FDISK to create a new partition, the inputs I has entered in is shown below in bold. Note that your can press ' m ' to get a full listing of the Fdisk commands.

' n ' is selected for adding a new partition.

Warning:dos-compatible mode is deprecated. It ' s strongly recommended to         switch off the mode (command ' C ') and change display units to         n

' P ' is then selected as we are making a primary partition.

Command action   L   logical (5 or over)   p   Primary partition (1-4)p

As I already have/dev/sda1 and/dev/sda2 as shown in previous images, I has gone with using ' 3 ' for this new partition W Hich'll be created As/dev/sda3

3

We just press ENTER twice above as by default the first and last cylinders of the unallocated space should is correct. After this partition are then ready.

"Enter" "Enter" Using Default Value 3916

' t ' is selected-to-a partition ' s system ID, in this case we change to ' 3 ' which is the one we just created.

T 3

The hex code ' 8e ' was entered as this is the code for a Linux LVM which are what we want this partition to be, as we'll b E joining it with the Original/dev/sda5 Linux LVM.

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

' W ' is used-to-write the table to disk and exit, basically all the changes that has been done would be saved and then you 'll is exited from Fdisk.

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 is being used atthe next reboot or after you run Partprobe (8) or KPARTX (8) Syncing disks.

You'll see a warning which basically means on order to use the new table with the changes a system reboot is required. If you can't see the new partition using "Fdisk-l", you can be able to run "partprobe-s" to rescan the partitions. In my test I did not require either of those things at the This stage (I do a reboot later on), straight after pressing ' w ' in Fdisk I was able to see the New/dev/sda3 partition of my 10gb for space as displayed in the below image.

For Centos/rhel run a "partx-a/dev/sda3" to avoid rebooting later on.

That's all for partitioning, we are now having a new partition which is making use of the previously unallocated disk space from The increase in VMware.

Increasing the logical volume

We use the pvcreate command which creates a physical volume for later use by the Logical Volume Manager (LVM). The physical volume would be our NEW/DEV/SDA3 partition.

Pvcreate/dev/sda3  Device/dev/sda3 not found (or ignored by filtering).

In order to get around this can either reboot, or use Partprobe/partx as previously mentioned to avoid a reboot, as in This instance the disk does not appear to being there correctly despite showing in "Fdisk-l". After a reboot or PARTPROBE/PARTX use the same command which would succeed.

Pvcreate/dev/sda3  Physical volume "/dev/sda3" successfully created

Next we need to confirm the name of the current volume group using the Vgdisplay command. The name would vary depending on your setup, for me it is the name of the My test server. Vgdisplay provides lots of information on the volume group, I has only shown the name and the current size of it Example.

Vgdisplay  ---Volume Group---  VG Name               Mega ... VG Size               19.76 GiB

Now we extend the ' Mega ' volume group by adding in the physical volume Of/dev/sda3 which we created using the Pvcreate Co Mmand earlier.

vgextend Mega/dev/sda3  Volume Group "Mega" successfully extended

Using The Pvscan command we scan all disks for physical volumes, this should confirm the ORIGINAL/DEV/SDA5 partition and The newly created physical Volume/dev/sda3

Pvscan  PV/DEV/SDA5   VG Mega   lvm2 [19.76 gib/0 free    ]  pv/dev/sda3   VG mega   lvm2 [10.00 gib/10.00 G IB Free]  total:2 [29.75 Gib]/in Use:2 [29.75 GiB]/in no vg:0 [0   ]

Next we need to increase the logical volume (rather than the physical volume) which basically means we'll be taking our Original logical volume and extending it over our new partition/physical volume Of/dev/sda3.

Firstly confirm the path of the logical volume using Lvdisplay. This path name is vary depending on your setup.

Lvdisplay  ---Logical volume---  LV Path                /dev/mega/root

The logical volume is then extended using the Lvextend command.

Lvextend/dev/mega/root/dev/sda3  Extending logical volume ROOT to 28.90 GiB  Logical Volume root successfully resized

There is then one final step which was to resize the file system so it can take advantage of this additional space, th IS is do using the RESIZE2FS command for ext based file systems. Note that this is some time to complete and it took about the seconds for my additional space.

resize2fs/dev/mega/rootresize2fs 1.41.12 (17-may-2010) Filesystem at/dev/mega/root is mounted on/;  On-line resizing Requiredold desc_blocks = 2, new_desc_blocks = 2Performing an on-line resize of/dev/mega/root to 7576576 (4k) blocks. The filesystem on/dev/mega/root is now 7576576 blocks long.

Alternatively if you ' re running the XFS file system (default as of Redhat/centos 7) You can grow the file system with "XFS _growfs/dev/mega/root ".

That's it, now with the ' DF ' command we can see this total available disk space has been increased.

Summary

With this method we had increased the virtual disk drive through VMware, created a new partition out of this newly unallo cated space within the guest OS, turned it into a physical volume, extended the volume group, and then finally extended th E original logical volume over the newer physical volume resulting in overall disk space being increased successfully.

RPM: Linux Disk expansion

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.