Solved

How to extend LVM2 Filesystem

Posted on 2010-09-08
14
1,501 Views
Last Modified: 2012-05-10
I have a Database server that is running Fedora.

Yesterday our SQL service wouldn't start and I found out it had ran out of disk space. Since we couldn't delete files to free up space I decided to take the hard drive and clone it to a 1.5TB drive.

It was originally on a 160GB drive (I just started working here... I'm not the idiot who placed a 160GB hard drive in the main database server). So I used Clonezilla to do a disk-to-disk copy. it worked great however the partition sizes are still the same.

I have a couple hundred MB boot filesystem which is ext3 and I tried to use Gparted and parted magic to resize the other partition and it says its LVM2. It says it doesn't have support for that filesystem.

So that partition is 140GB or around there. It's /dev/mapper/VolGroup00-LogVol00

I tried to use lvextend but I'm not really sure how to do that... The free space is unpartitioned because I'm not sure which way I should partition it.

I'm not a linux expert but I'm not the worst in the world... I know just enough to completely ruin everything. So I'm hoping to get some guidance on this issue.

I probably didn't give enough information so please let me know what info you need & what I do in order to find that. (Chances are I'll know how to do it, but just to save time in case I don't).

Thanks all so much!!!
0
Comment
Question by:keith_opswat
14 Comments
 
LVL 8

Expert Comment

by:mustaccio
ID: 33632346
LVM works with the existing disk partition, which was copied by Clonezilla bit by bit and therefore did not increase.

You will need to modify the partition size using fdisk (most likely you'll need to delete the existing partition and create a new, bigger one). You will then resize the physical volume (pvresize), extend the logical volume (lvresize), and grow the file system (resize2fs).

Alternatively, you could create another partition on the disk free space, create a new physical volume, add it to the volume group, then extend the LV etc. However, this will most likely hurt I/O performance.

Google for "LVM how-to".
0
 
LVL 3

Accepted Solution

by:
T1750 earned 500 total points
ID: 33632540
Step 1: Create a new physical volume to take up all that lovely free space

# fdisk -u /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c').

Command (m for help): p

Disk /dev/sdb: 80.0 GB, 80026361856 bytes
164 heads, 27 sectors/track, 35298 cylinders, total 156301488 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: 0x45434952

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1    78295039    39147519+  8e  Linux LVM

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First sector (78295040-156301487, default 78295040):
Using default value 78295040
Last sector, +sectors or +size{K,M,G} (78295040-156301487, default 156301487):
Using default value 156301487

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

Disk /dev/sdb: 80.0 GB, 80026361856 bytes
164 heads, 27 sectors/track, 35298 cylinders, total 156301488 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: 0x45434952

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1    78295039    39147519+  8e  Linux LVM
/dev/sdb2        78295040   156301487    39003224   8e  Linux LVM

Command (m for help): 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 will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks

You can just accept the default values like I did, thats why it shows no reply to some of the questions, I just pressed enter and it will make a new partition that takes up all the space.

Step 2: Create a new PHYSICAL VOLUME for use with your VOLUME GROUP.

bob:~ # pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created

If you receive an error about ignored by filtering, reboot your machine and try again.

Step 3: Add new volume to volume group

bob:~ # vgextend VolGroup00 /dev/sdb2
  Volume group "VolGroup00" successfully extended

(My volume group has a cool name, but I put yours in so you can copy and paste)

Step 4: Add space to the logical volume you want. Probably your root one LogVol00

bob:~ # lvs
  LV   VG   Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  root pc   -wi-ao 53.23g                                      
  swap pc   -wi-ao 12.00g                                      

Those show mine, you want to add space to LogVol00 though so you go:

bob:~ # lvextend -l +100%FREE /dev/mapper/VolGroup00-LogVol00
  Extending logical volume root to 99.72 GiB
  Logical volume root successfully resized

bob:~ # lvs
  LV   VG   Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  root pc   -wi-ao 99.72g                                      
  swap pc   -wi-ao 12.00g                                      
bob:~ #

Your output will look different, because my volume group is called pc and my root is called root. But it will be basically the same.

Step 5: Resize the filesystem to use the new space

You're probably using extX so you can do this:

resize2fs /dev/mapper/VolGroup00-LogVol00

And you can do it while you're online and working too! In fact, unless you got the error about filtering when you tried to do the pvcreate, you can do the whole thing without rebooting.

Congratulations, you now have lots more free space.
0
 
LVL 3

Expert Comment

by:T1750
ID: 33632547
Ignore mustaccio telling you to resize (which means recreate) your partitions with fdisk yes you can do it that way but one screw up and you just lost all your data. Just add another partition, it's a lot safer and makes no difference.
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 3

Expert Comment

by:T1750
ID: 33632560
Oh, and where I say "reboot your machine and try again" you just redo the pvcreate command, don't re-do the fdisk stuff that's why it (might) moan in the first place.

Plain english: If you get an error about filtering, reboot and resume at Step 2 not Step 1
0
 
LVL 3

Expert Comment

by:T1750
ID: 33632589
mustaccio; Look at the names of his partitions, he has used fedora auto creation of disks and everything I think telling him to go manually recreating his partition table was a bit irresponsible.
0
 
LVL 3

Expert Comment

by:T1750
ID: 33632609
Oh and I hope I get a good grading, I'm going to have to undo all that because I did it to my desktop to show you step-by-step and I can only do that by booting from a rescue disk (can't shrink mounted partitions).
0
 
LVL 4

Author Comment

by:keith_opswat
ID: 33632621
Thank you so much. I didn't set this server up. I am the sysadmin for opswat Inc and this is our database for our developers wiki. I just started like two months ago so this stuff was all created years ago by someone else. They've never had someone hired as a sysadmin before me. I will try that tomorrow (not fdksk) because the whole reason I cloned the disk was to save the server exactly as it was. I wouldn't need help if all I was gonna do was reset everything up. Once again thanks so much
0
 
LVL 3

Expert Comment

by:T1750
ID: 33632626
And it won't hurt your I/O if you do it by making a new partition that's rubbish. LVM knows they're both on the same disk.
0
 
LVL 3

Expert Comment

by:T1750
ID: 33634819
You do have to use fdisk to make the extra partition, just don't use it to destroy the old one and make a new bigger one.

If you launch it it sector mode (-u), and make sure the start sector is the same, it "shouldn't" cause any problems to do it that way but why take the risk?

I used to be a sysadmin myself.
0
 
LVL 3

Expert Comment

by:T1750
ID: 33634824
I'd have shown you how to do it the "destroy the old one" way too if I could but I created my partition table with dd :) It starts' on sector 1 and fdisk won't allow you to do that.
0
 
LVL 3

Expert Comment

by:T1750
ID: 33634931
And I wouldn't worry about needing help, I *constantly* need help that's I'm answering questions on here so I can get free premium service :)

You need to constantly learn in this game. Asking for help is a valid shortcut.
0
 
LVL 3

Expert Comment

by:T1750
ID: 33634935
I'd suggest printing off a copy of that whole session I did while you work so you can see where I accepted default answers and where I gave one. It will be obvious.
0
 
LVL 4

Author Closing Comment

by:keith_opswat
ID: 33653622
It appears to work... Seem to be having some issues but I'm gonna give you the grade for it anyways because I'm quite sure it will work. It did once but I accidentally messed something up . So ohwell. Giving it another go!!

Thanks so much for the info though!!
0
 

Expert Comment

by:Firehiwot
ID: 37695043
Could you please, post only valid things. Since we believe it is an open experts forum to discuss and solve problems.
Thanks,
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Each year, investment in cloud platforms grows more than 20% (https://www.immun.io/hubfs/Immunio_2016/Content/Marketing/Cloud-Security-Report-2016.pdf?submissionGuid=a8d80a00-6fee-4b85-81db-a4e28f681762) as an increasing number of companies begin to…
This video teaches viewers how to encrypt an external drive that requires a password to read and edit the drive. All tasks are done in Disk Utility. Plug in the external drive you wish to encrypt: Make sure all previous data on the drive has been …
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question