LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Virtualization and Cloud (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/)
-   -   Grow LVM in extended partition. (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/grow-lvm-in-extended-partition-857896/)

hansaplazt 01-21-2011 07:38 PM

Grow LVM in extended partition.
 
I couldn't find a HOWTO that always works (even with LVM in extended partition).

Here's one...

Code:

First, shut down your VM and increase the disk size.
Then start your VM and go to the console.


# fdisk -u /dev/xvda
(-u shows sectors instead of cylinders. This is important)

(Make a note of the start sector of the LVM partition)
Command (m for help): p

    Device Boot      Start        End      Blocks  Id  System
/dev/xvda1  *        2048      499711      248832  83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2          501758    16775167    8136705    5  Extended
/dev/xvda5          501760    16775167    8136704  8e  Linux LVM

(delete the LVM and/or Extended partition)
Command (m for help): d
Partition number (1-5): 2

(Create a new partition)
Command (m for help): n
Command action
  e  extended
  p  primary partition (1-4)
p (I choose primary but you may choose extended)
Partition number (1-4): 2 (choose one that's available)

(Fill in the start sector of the LVM partition we deleted above)
First sector (63-16777215, default 63): 501760
Last sector, +sectors or +size{K,M,G} (501760-16777215, default 16777215): (Enter)

(change created partition to Linux LVM)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

    Device Boot      Start        End      Blocks  Id  System
/dev/xvda1  *        2048      499711      248832  83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2          501760    16777215    8137728  8e  Linux LVM

Command (m for help): w (write)

# reboot

(Resize physical volume)
# pvresize /dev/xvda2

(make a note of the VG "Free PE")
# vgdisplay

(make a note of the "LV Name" of the LV you want to resize)
# lvdisplay

(Resize LV. Fill in the found "Free PE" and "LV Name" (without the brackets))
# lvresize -l +[Free PE] [LV Name]

(resize the file system)
# resize2fs [LV Name]
# reboot

Thats all..

Hope this is useful to somebody.

sefai 07-20-2011 10:03 AM

It was very useful for me.

Thank you very much.

hansaplazt 07-21-2011 05:16 AM

Glad you liked it.

SwedishViking 12-05-2011 07:29 AM

Unfortunately this doesn't work for me :(

After performing the steps above I get the following message when booting.

Gave up waiting for root device. Common problems:
- Boot args (cat /proc/cmdline)
- Check rootdelay= (did the system wait long enough?)
- Check root= (did the system wait for the right device?)
- Missing modules (cat /proc/modules; ls /dev)
ALERT! /dev/mapper/AhsayOBS-root does not exist. Dropping to a shell!


BusyBox v1.13.3 (Ubuntu 1:1.13.3-1ubuntu11) built-in shell (ash)
Enter 'help' for a list of built-in commands.

(initramfs)


I'm running this Ubuntu 10.04.03 LTS on a XenServer v6.0

Any one else seen this?

hansaplazt 12-05-2011 08:05 AM

I presume you have created snapshot or backup of your VM?
Go back to it and start your VM (it should come up now). Can you post the output of "fdisk -u /dev/xvda" here? Assuming of course that /dev/xvda is the device you want to resize.

SwedishViking 12-06-2011 01:33 AM

Yes, that's correct. But I had to fix the space problem on that server immediately so had to solve it temporarily with mounting another partition into the filesystem to gain space where needed.

Although I've set up a similar Xen VM Guest server to continue tests on and it looked like this.

Disk /dev/xvda: 75.2 GB, 75161927680 bytes
255 heads, 63 sectors/track, 9137 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: 0x00075641

Device Boot Start End Blocks Id System
/dev/xvda1 1 32 248832 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2 32 9138 73148417 5 Extended
/dev/xvda5 32 9138 73148416 8e Linux LVM

hansaplazt 12-06-2011 04:13 AM

You are showing me cylinders instead of sectors. This is important. What unix/linux flavour do you have? Check the fdisk man page for listing sectors (usually this is '-u')

SwedishViking 12-06-2011 05:55 AM

I'm running Ubuntu Lucid Lynx (10.04 LTS)

Okay, changed to sectors inside fdisk instead of on the command line which seems to work better.

Changing display/entry units to sectors

Command (m for help): p

Disk /dev/xvda: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders, total 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00050338

Device Boot Start End Blocks Id System
/dev/xvda1 2048 499711 248832 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2 501758 33552383 16525313 5 Extended
/dev/xvda5 501760 33552383 16525312 8e Linux LVM

hansaplazt 12-06-2011 05:59 AM

That was probably the problem.
If you now follow my first post (exactly of course :)) all should be fine.

johnavp1989 02-10-2016 10:31 AM

Thank You!
 
I know this is a really old post but I've been looking for the answer to this for a couple of days now and couldn't find it until I stumbled upon this! Thank's so much!

pjs67123 02-20-2016 03:42 PM

Thanks hansaplazt for the post! You are awesome!

paranoico 11-27-2016 02:33 PM

Thanks a lot
 
Hello,

Your thread was very useful for me even 6 years before ;)

Just wanted to note that on Debian 8 now some commands has changed that needs complete paths for LV (name is not enough anymore):
  • sudo lvresize -l +[Free PE] [LV Path]
    sudo resize2fs [LV Path]

Thanks for your great post.

Coffee!!! 12-15-2016 11:44 AM

For RHEL 7*

Try running a rescan on the iscsi bus after adding or extending a drive to a VM:

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

Most of the time it will work and prevent you from having to do a reboot.

Since file systems have changed a bit, adding the following command for XFS since it doesn't use resize2fs:

xfs_growfs /dev/mapper/rhel-root00

gingerpower121 04-11-2017 11:41 AM

Still relevant in 2017.

Using Ubuntu 16.04.2 LTS (Server build). Thank you OP!

azidhaka 09-03-2019 06:45 AM

Helped me in 2019, thank you very much!


All times are GMT -5. The time now is 06:34 PM.