LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-10-2013, 09:15 AM   #1
sk_it
LQ Newbie
 
Registered: Aug 2013
Posts: 4

Rep: Reputation: Disabled
Unhappy Need help how to increase volume size


Hi .. I am still newbie and need urgently.

I have VM machine which was running out of space so I increased space from 20GB to 40GB. Now I need help to increase spacce in linux logical volume.

[root@localhost ~]# fdisk -l


Disk /dev/sda: 42.9 GB, 42949672960 bytes

255 heads, 63 sectors/track, 5221 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes


Device Boot Start End Blocks Id System

/dev/sda1 * 1 13 104391 83 Linux

/dev/sda2 14 2610 20860402+ 8e Linux
LVM

Disk /dev/sdb: 8005 MB, 8005787648 bytes


32 heads, 63 sectors/track, 7756 cylinders

Units = cylinders of 2016 * 512 = 1032192 bytes



Device Boot Start End Blocks Id System
/dev/sdb1 * 1 7756 7818016+ b W95 FAT32


[root@localhost ~]#




[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup00-LogVol00
18G 14G 2.7G 84% /

/dev/sda1 99M 18M 77M 19% /boot

tmpfs 467M 0 467M 0% /dev/shm

[root@localhost ~]#



I did try lvresize and lvextend but it throws error.

Thanks.

Last edited by sk_it; 08-10-2013 at 10:35 AM. Reason: incorrect heading
 
Old 08-10-2013, 06:44 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,403

Rep: Reputation: Disabled
You've increased the size of the disk with the Physical Volume, and now you need to extend the partition containing that volume.

Using fdisk, delete and recreate /dev/sda2. Yes, it is safe to delete the partition as long as you recreate it starting at the same sector. No data will be deleted.

Once that is done, run pvresize to update the internal structure of the Physical Volume to reflect the new partition size. Since the PV is a member of a Volume Group, the group automatically gets extended as well.

Then run lvextend to add the available space in the VG to the Logical Volume. Finally, extend the file system with resize2fs (or the appropriate tool for your file system if you're not using ext2/3/4).
 
Old 08-10-2013, 09:54 PM   #3
sk_it
LQ Newbie
 
Registered: Aug 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thank you for the reply 'Ser Olmy'.

I would appreciate is there document or you can give me steps in detail to do all these things. I am just new and not a Linux admin. but trying to learn as much as I can.
 
Old 08-11-2013, 12:46 AM   #4
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,114

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
To learn things like this, and many things in Linux, the easiest and quickest way is typically a Google search. Combine "howto" with what you want to learn.

Example: Do a Google search on "lvm howto"

Someone can explain it all again here, but with the documentation already out there in great detail, it's easier to just search it out yourself. Then come here and ask your remaining questions after you have a basic understanding of things. You will find that depending on the type of filesystem you need to extend, that filesystem might have to be unmounted (or mounted) before you can resize it. You will also learn what "logical volumes" are, what "volume groups" are, what "physical volumes" are, etc. Once you understand these basics it may be obvious to you what you need to do. If not, come ask specific questions here.

At the very least, you should run the "fdisk -l", "pvs", "vgs", "lvs", and "mount" commands and post their output here so we know something about your system so advice can be given.
 
Old 08-11-2013, 08:19 AM   #5
sk_it
LQ Newbie
 
Registered: Aug 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi Haertig .. Thanks for the advice ..

I will search google meanwhile as asked these are the following output. I did try lvresize and lvextend but its giving error

[root@localhost ~]# fdisk -l


Disk /dev/sda: 42.9 GB, 42949672960 bytes

255 heads, 63 sectors/track, 5221 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes


Device Boot Start End Blocks Id System

/dev/sda1 * 1 13 104391 83 Linux

/dev/sda2 14 2610 20860402+ 8e Linux LVM

[root@localhost ~]#

[root@localhost ~]# pvs

PV VG Fmt Attr PSize PFree

/dev/sda2 VolGroup00 lvm2 a- 19.88G 0

[root@localhost ~]#

[root@localhost ~]# vgs

VG #PV #LV #SN Attr VSize VFree

VolGroup00 1 2 0 wz--n- 19.88G 0


[root@localhost ~]# lvs

LV VG Attr LSize Origin Snap% Move Log Copy%

LogVol00 VolGroup00 -wi-ao 17.94G

LogVol01 VolGroup00 -wi-ao 1.94G


[root@localhost ~]# mount

/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

/dev/sda1 on /boot type ext3 (rw)

tmpfs on /dev/shm type tmpfs (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
 
Old 08-11-2013, 10:21 AM   #6
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,403

Rep: Reputation: Disabled
Your root file system is an ext3 file system on an LVM Logical Volume called VolGroup00-LogVol00. Something tells me you didn't change the default values during installation.

The LVM Logical Volume resides in a Volume Group called VolGroup00, which in turn consists of one physical volume; the partition /dev/sda2.

So you have a file system inside a Logical Volume inside a Volume Group consisting of a single Physical Volume (partition):
[ext3 root FS] -> [VolGroup00-LogVol00] -> [VolGroup00] -> /dev/sda2
You've already extended the /dev/sda disk. Next, you have to extend the /dev/sda2 partition, which means deleting and recreating it:
  1. run fdisk /dev/sda
  2. show the partition table with the p command, and make note of the starting sector of the /dev/sda2 partition
  3. delete the second partition with the d command (don't worry, nothing is written to disk until you explicitly do so with the w command)
  4. create a new primary partition no. 2 with tne n command (the default values should be OK)
  5. use the t command to set the partition type of partition #2 to 8e ("Linux LVM")
  6. view the resulting partition table with the p command, and compare the starting sector/track/whatever with the notes from step 2
  7. write the new partition table to disk with the w command if all looks OK, or abort with the q command and start from scratch if you made a misteke or the partition table doesn't look right
A Google search should already have turned up a few documents outlining this exact procedure. Post a message if you run into any problems.

Once you've done this part, the rest is plain sailing.
 
Old 08-11-2013, 01:01 PM   #7
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,114

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
IMPORTANT NOTE: I typed the commands below from memory. I may not have gotten the syntax exactly correct. Verify what I say below before doing it verbatim! Also, read the LVM HowTo so that you understand what the commands below are doing, and why you need to run them. Trying to just copy what I say below, without understanding it, will no doubt lead you to problems. Potentially system-destroying problems!

Rather than try to grow the sda2 partition to take up the remainder of the disk (the unused space), I would create a new sda3 partition that contains the currently unused disk space. I would mark that new sda3 partion as a physical volume, then add it to the existing volume group, then extend the logical volume.

How to do that?

(1) Use fdisk to create a new partition, sda3, that contains the remainder of the unused disk space
(2) Mark it as a physical volume like this "pvcreate /dev/sda3"
(3) Add it to the volume group like this: "vgextend VolGroup00 /dev/sda3"

Now comes the trickier part. The logical volume you want to extend is mounted as / (root). This logical volume uses the ext3 filesystem. In order to extend a logical volume that uses ext3, you must unmount it (other filesystem types can sometimes be extended while they are mounted, but ext3 cannot). But you obviously cannot unmount your root filesystem while the system is running from it.

So in order to extend your root file system, you must first boot the computer from a LiveCD. You cannot do this volume extending while your computer is booted normally from its harddisk.

(4) Boot from a LiveCD (I recommend SysRescueCD)
(5) Make the volume group visible by running "vgchange -ay"
(6) Extend the logical volume by running "lvextend -l +100%VG /dev/VolGroup00/LogVol00"
(7) Verify the existing filesystem is clean with "e2fsck -f /dev/VolGroup00/LogVol00"
(8) Resize the filesystem like this "resize2fs /dev/VolGroup00/LogVol00"
(9) Reboot your system, removing the LiveCD from the drive in the process, so it again boots from the harddrive

You also have a second logical volume, LogVol01, which is 2Gb in size but is not mounted anywhere. I cannot draw any conclusions about that logical volume (is it needed or not?) But, if it is not needed, you could delete it and return that 2Gb of space to the volume group and then reallocate it to LogVol00.

It might also be a prudent move for you to wait for others to post comments on my process above before you attempt it. If I got something wrong, somebody else might catch my error. I have done this exact procedure many many times myself, but that doesn't mean I can document it all perfectly from memory, which is what I am attempting to do here.

Last edited by haertig; 08-11-2013 at 01:54 PM.
 
Old 08-11-2013, 02:06 PM   #8
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,114

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
BTW, when posting output of commands, it is better if you surround that output with [ code ] and [ /code] tags. It makes it much more readable. See below for examples of the same output with and without those tags. Note that there are actually no spaces in the tags, I just had to put those there in this paragraph so that you could see the tags themselves. Leave out the spaces when you really want to use the tags.

Code:
# fdisk -l

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 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: 0x87483e19

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048      206847      102400   83  Linux
/dev/sda2          206848     1230847      512000   83  Linux
/dev/sda3         1230848     5425151     2097152   82  Linux swap / Solaris
/dev/sda4   *     5425152  1953525167   974050008   83  Linux
#
# fdisk -l

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 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: 0x87483e19

Device Boot Start End Blocks Id System
/dev/sda1 2048 206847 102400 83 Linux
/dev/sda2 206848 1230847 512000 83 Linux
/dev/sda3 1230848 5425151 2097152 82 Linux swap / Solaris
/dev/sda4 * 5425152 1953525167 974050008 83 Linux
#
 
Old 08-11-2013, 02:30 PM   #9
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,403

Rep: Reputation: Disabled
Quote:
Originally Posted by haertig View Post
Rather than try to grow the sda2 partition to take up the remainder of the disk (the unused space), I would create a new sda3 partition that contains the currently unused disk space.
This method has the (considerable) advantage of working even when there's a partition right after the current PV partition, but that's not the case here.

It is slightly easier to create a new partition than it is to delete and recreate an existing partition (you save two or three keystrokes), but other than that there's not that much of a difference. And if you have to repeat the process and expand the drive further, you'll eventually end up with a lot of logical partitions inside an extended partition.
 
Old 08-11-2013, 03:17 PM   #10
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,114

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Quote:
Originally Posted by Ser Olmy View Post
And if you have to repeat the process and expand the drive further, you'll eventually end up with a lot of logical partitions inside an extended partition.
How would you "expand the drive further"? Whether you are extending the current partition, or adding a new one, with either method taking up all the remaining unallocated space on the disk, there's no way you can expand that disk further. You can extend the lv further if you add a new harddisk, but that would have nothing to do with the way partitions are set up on the current disk. I'm not sure I understand what you are getting at.
 
Old 08-11-2013, 03:42 PM   #11
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,403

Rep: Reputation: Disabled
Quote:
Originally Posted by haertig View Post
How would you "expand the drive further"? Whether you are extending the current partition, or adding a new one, with either method taking up all the remaining unallocated space on the disk, there's no way you can expand that disk further. You can extend the lv further if you add a new harddisk, but that would have nothing to do with the way partitions are set up on the current disk. I'm not sure I understand what you are getting at.
The OP is asking about extending the LVM partition in a VM. The disk in question is not a physical disk, but a virtual disk that exists as a file or partition on the hypervisor.

He has just expanded this disk, and now needs to extend the LVM PV to match the new disk size. He may want to expand the disk further at a later point.
 
Old 08-11-2013, 06:24 PM   #12
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,114

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Ahhhh, OK. I didn't realize we weren't talking about a physical disk here. My bad. The OP *did* say "VM" in his first post. Don't know how I missed that part. I see it now though.
 
Old 08-11-2013, 09:14 PM   #13
sk_it
LQ Newbie
 
Registered: Aug 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thank you to both of you.

Let me try and I will be back
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I have spce in volume group but it can not increase the size of logical volume anis123 Linux - Newbie 14 04-16-2012 07:23 AM
bacula: volume size tilman1 Linux - Software 1 10-12-2010 07:28 AM
how to mount SAN volume with its increased volume size prvnrk Linux - General 4 03-22-2008 11:48 AM
Used space is more than volume size? krnlg Linux - Desktop 2 12-04-2007 05:36 AM
tar multi-volume (-M): how to specify size? jhwilliams Linux - Software 1 08-16-2007 08:39 PM


All times are GMT -5. The time now is 10:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration