Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora Resources > Guides & Solutions (No Questions)
FedoraForum Search

Forgot Password? Join Us!

Guides & Solutions (No Questions) Post your guides here (No links to Blogs accepted). You can also append your comments/questions to a guide, but don't start a new thread to ask a question. Use another forum for that.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 7th May 2007, 11:26 AM
sideways Offline
Retired User
 
Join Date: Oct 2004
Location: London, UK
Posts: 4,999
How To extend root / partition 'on-the-fly', ext3/LVM only

This turned out to be easier than expected, so I'm posting this short how-to. The restriction to ext3 is due to the man page for resize2fs claiming this is the only fs that can be resized without unmounting.

The scenario: you have an ext3 partition LogVol00 mounted on / and a swap partition LogVol01 in a logical volume group VolGroup00 (the default install), but you're running out of space in /, there's no room left in the volume group but you have a brand new disk drive with lots of free space. How to add some space to the / partition?

The usual problem is that / can't be unmounted, there are guides out there which involve using a livecd or dual booting into another os that recognizes logical volumes, but in this case you can do it 'on-the-fly' in Fedora.

WARNING: If you have important data in any directory under / then backup before attempting this.

I'll assume the spare disk is called /dev/sdb

1. Create a new partition of appropriate size using fdisk
Code:
fdisk /dev/sdb
n   (create new partition, select start and end cylinders, all free space is selected by default)
w  (save partition table and exit)
At this point you may be told that a reboot is necessary, I found it was unnecessary, but for safety you should probably reboot. Type fdisk -l again to check the new partition, I'll assume /dev/sdb1 was created ~10G in size

2. Create an ext3 filesystem in the partition (this step is optional, just a quick test that all is well)
Code:
mkfs.ext3 /dev/sdb1
3. Initialise the partition for use as a physical volume in lvm and add it to VolGroup00
Code:
pvcreate /dev/sdb1
vgextend VolGroup00 /dev/sdb1
4. Extend LogVol00 (use 'df /' to check that / is mounted on LogVol00) as required (by 10G here)
Code:
lvextend -L +10G /dev/VolGroup00/LogVol00
If you receive errors about not enough physical extents, then reduce the size of the extension a little until it fits.

5. Finally, resize the filesystem (this part normally would require unmounting /, but for ext3 and 2.6 Kernels it works while the partition is mounted)
Code:
resize2fs /dev/VolGroup00/LogVol00
Type 'df -h /', to check it worked, there should be an extra 10G available
(you can use vgdisplay, pvdisplay and lvdisplay (as root) to see detailed info, pvscan for a summary)



Note.
I've seen horror stories with lvm manipulation whereby an 'unknown uuid' error occurs for a partition, and the VolGroup can no longer be found, which prevents booting. This can be due to using e2label, mkfs etc on the partition after it has been initialised as a pv and added to the group. The error is fixable if you haven't rebooted: you need to edit /etc/lvm/backup/VolGroup00 and delete the lines referring to the unrecognized partition (they'll be a few between braces {}, the unknown uuid will be at the beginning, something like:

Code:
 pv1 {
                        id = "gAMCGW-jdaH-VXse-HR2j-PA24-AIbb-aHMjKl"
                        device = "/dev/sdb1"   # Hint only

                        status = ["ALLOCATABLE"]
                        dev_size = 20482812     # 9.76697 Gigabytes
                        pe_start = 384
                        pe_count = 312  # 9.75 Gigabytes
                }
Remove all these lines, save the file, then run
Code:
vgcfgrestore -f /etc/lvm/backup/VolGroup00 VolGroup00
vgscan
vgscan should report all is ok (you can now try reinitialising the 'bad' partition using pvcreate, and then add it back to the VolGroup with vgextend)

Last edited by sideways; 9th May 2007 at 10:32 PM.
Reply With Quote
  #2  
Old 9th May 2007, 09:32 PM
option Offline
Registered User
 
Join Date: Mar 2006
Posts: 11
thanks for the howto, sideways. worked perfectly for adding a 300GB drive to my existing partition of a single 500GB drive in my mythtv box (i set up the LVM during setup as a partition for all of my media related recordings and videos, knowing that i was going to expand it eventually). I think I found a typo though- right after using fdisk and making the filesystem, mkf2s.ext3 didnt work for me; but mkfs.ext3 did. maybe you confused that command with resize2fs? anyway, great how-to nonetheless!
Reply With Quote
  #3  
Old 9th May 2007, 10:37 PM
sideways Offline
Retired User
 
Join Date: Oct 2004
Location: London, UK
Posts: 4,999
Quote:
Originally Posted by option
thanks for the howto, sideways. worked perfectly for adding a 300GB drive to my existing partition of a single 500GB drive in my mythtv box (i set up the LVM during setup as a partition for all of my media related recordings and videos, knowing that i was going to expand it eventually). I think I found a typo though- right after using fdisk and making the filesystem, mkf2s.ext3 didnt work for me; but mkfs.ext3 did. maybe you confused that command with resize2fs? anyway, great how-to nonetheless!
oops, absolutely right, I edited to correct the typo. ( That section is skippable though )

Glad it worked for you, I wasn't a fan of lvm, but I had this machine in need of space and was surprisingly impressed how easy this was to do.

A thumbs up for lvm
Reply With Quote
  #4  
Old 1st August 2007, 05:08 PM
Hobb3s Offline
Registered User
 
Join Date: Aug 2007
Location: Ottawa, Ontario, Canada
Age: 36
Posts: 6
Thanks for this! I was just looking how to do this exactly. Worked great. I appreciate your help!
__________________
Fedora 2.6.21-1.3194.fc7
Reply With Quote
  #5  
Old 1st August 2007, 06:38 PM
SlowJet Offline
Registered User
 
Join Date: Jan 2005
Posts: 5,048
Are you sure step 2. is needed for an extend.
I always thoht the pv had to be created first, and the formating is on the lv level.

The extend operation, I think, just formated the new partition area again.

EDIT: actually, step 5 formatted the extended lv area.
SJ
__________________
Do the Math

Last edited by SlowJet; 1st August 2007 at 06:55 PM. Reason: actually, step 5 formatted the extended lv area.
Reply With Quote
  #6  
Old 18th February 2011, 06:52 PM
axet Offline
Registered User
 
Join Date: Jul 2008
Posts: 378
macosfirefox
Re: How To extend root / partition 'on-the-fly', ext3/LVM only

"Online resizing of ext4 works in a similar manner as ext3, using either resize2fs or ext2resize"

https://ext4.wiki.kernel.org/index.p..._filesystem.3F
Reply With Quote
  #7  
Old 16th December 2011, 12:06 PM
Gödel Offline
Registered User
 
Join Date: Jul 2009
Location: London,England
Posts: 1,102
linuxfirefox
Re: How To extend root / partition 'on-the-fly', ext3/LVM only

Yes, these instructions still work in latest fedoras with ext4, but the logical volume naming has slightly changed, also I would recommend installing gparted ('yum install gparted') to create the initial ext4 partition.

I decided to delete the 10G recovery partition /dev/sda2 (which I never use) on a dell laptop, convert it to ext4 and add it to my root partition in F14:

1. I used gparted to create the ext4 partition in /dev/sda2 (I deleted the fat32 filesystem first)

2. I used lvscan to find the name of the active volume group and logical volume (this may also include a swap partition, which you can ignore, I don't put swap in an lvm group because I dual boot with Ubuntu and want to share the swap partition)

Code:
$ su -
# lvscan
  ACTIVE            '/dev/VolGroup/LogVol00' [17.34 GiB] inherit
Now extend the filesystem into the 10G partition

Code:
# pvcreate /dev/sda2
# vgextend VolGroup /dev/sda2
# lvextend -L +10G /dev/VolGroup/LogVol00
(gives error not enough physical extents)
 
# sudo lvextend -L +9.99G /dev/VolGroup/LogVol00 
# resize2fs /dev/VolGroup/LogVol00 
#  df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol00
                       27G   15G   13G  54% /

# lvscan
  ACTIVE            '/dev/VolGroup/LogVol00' [27.33 GiB] inherit
(Note that the /dev/sda2 partition wasn't quite 10G, so I had to extend by 9.99G)

This took just a few minutes. You don't have to create the ext4 filesystem in step 1, but I prefer to do this as it will report any potential problems.
Reply With Quote
  #8  
Old 9th March 2012, 04:52 PM
vonmax42 Offline
Registered User
 
Join Date: Mar 2012
Location: Austin, TX
Posts: 1
linuxfirefox
Re: How To extend root / partition 'on-the-fly', ext3/LVM only

An easy way to utilize the entire space instead of guessing is to look at output from the vgdisplay command.

Here is an example. Look at the 1st column from Free PE / Size. Use that in your lvextend.
Code:
lvm> vgdisplay VolGroup01
  --- Volume group ---
  VG Name               VolGroup01
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               3.82 TB
  PE Size               32.00 MB
  Total PE              125042
  Alloc PE / Size       85201 / 2.60 TB
  Free  PE / Size       39841 / 1.22 TB
  VG UUID               WEdh4a-kUiH-8Xzx-gMfd-1J88-RxVI-hf85uZ
   
lvm> 

lvm> lvextend -l+39841 /dev/VolGroup01/lvol0
  Extending logical volume lvol0 to 3.82 TB
  Logical volume lvol0 successfully resized
lvm>


Quote:
Originally Posted by Gödel View Post
(Note that the /dev/sda2 partition wasn't quite 10G, so I had to extend by 9.99G)

This took just a few minutes. You don't have to create the ext4 filesystem in step 1, but I prefer to do this as it will report any potential problems.
Reply With Quote
Reply

Tags
ext3 or lvm, extend, onthefly, partition, root

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I need to extend my partition... I think. quantumburnz Using Fedora 4 21st September 2008 05:55 PM
How To extend an ext3 fs located in an LVM. highc Guides & Solutions (No Questions) 0 23rd October 2005 02:11 PM
Mounting ext3 partition with rw permissions for non-root user ilyushin Using Fedora 6 27th June 2005 02:15 PM
Resizing EXT3 root partition safe? alphonsebrown Using Fedora 7 4th April 2005 03:58 PM


Current GMT-time: 23:37 (Tuesday, 22-07-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat