Tuesday, November 25th 2008


How to resize LVM partition on Fedora 9
posted @ 19:40 in [ Timelapse Imaging ]

Just few minutes back I finished resizing an LVM partition. The history if you must read starts like this, I installed Fedora 9 using default settings (i was crazy that day!). Then I liked what I saw as this was my first personal Fedora install. Then fedora said to update, so i did. Then I said, I wanted to install VirtualBox for few other OSs. Getting virtualBox to run is another story. Anyway, after enjoying openSUSE for 2 days, I wanted to install it in real partition. Now was the question, where? I had no space!

Every site around said you can easily resize  and get space. My fedora was taking under 10G on a 100G partition. I installed GParted and tried. It reported /dev/sda3 as a unknown type and so won’t resize it. Damm! Then after digging I realize that Fedora installed LVM2 on my partition. I never know what was that!  Then some other site confidently said, Gparted was very good and even could handle LVM partitions. So I download ISO and burned to a bootable CD. It started and reported the same error. My target partition was still unknown! Now, I had given up of any easy way out.

So I start to learn the LVM funda. Redhat had docs and lots of links about resizing LVMs. Everyone said, LVM was made to be easy. It was made to handle changs without even reboot! Sounded great. Then I came to Mr. resize2fs. This guy said he was expert in rewsizing many partitions including ext3. He also said, he could resize on the fly which is called on-line resize. Any kernel past 2.6 can handle on-line resize. So I tried. And tried. and failed! resize2fs kept reporting that “/dev/sda3″ is in use therefore it should try on-line resize. Then the next line said, on-line resize from NNN to NNN not supported! I went crazy for those 15 mins hunting why did it fail! Anyway, everything love to fail. Finally, I reach a good blog which told the process in slow motion. I understood more about LVM and what do each of the steps to in a LVM resize job.

  1. LVM is simple a seperate partition table system that linux internally supports. That is also why it allows chaning LVM without reboot.
  2. LVM creates a main single partition in the disk with a filesystem flag as lvm or lvm2. These are no filesystems so they are only parsed by LVM itself. We know fat32, ntfs,ext,ext2,ext3 etc are actual filesystems while lvm is a wrapper file system.
  3. LVM resides on a real disk partition and could contain multiple Volume Groups.
  4. Volume Group itself could contain Volumes.
  5. Volumes are the ones which are made up of a readable filesystem such as ext3.
  6. LVM at boot time will scan for lvm partitions on the disk and later parse everything inside to create new devices such as /dev/VolGroup00/LogVol00. These will then be mounted just like any normal partition.
  7. So now we know its not very easy to resize a basic disk parition which itself holds a Volume Group and which then holds multiple Volume which are real filesystems.

Now you know little bit about LVM itself. Everything about LVM is here. My explanation will have minor bugs but the LVM system. As I understood and explained here is more or less correct. How did I resize is now been shown in the following steps.

  1. Boot using the Fedora 9 ISO cd what was used for installing, choose resume mode
  2. Do not mount any filesystems when prompted by setup, and jump directory to the prompt.
  3. start vlm
  4. here, do a vgscan do verify that vlm can read all your volumes.
  5. Now to work on volumes you need to activate that volume. This is NOT the same as mounting. Activation will call LVM core to parse lvm partitions and create a virtual devices. These devices themselves won’t be mounted but made available to any utility who needs them in an exclusive mode. To activate, call
    vgchange -a y my_volume_group

  6. Now the volume device will be ready to resize2fs.
  7. some explaination: resize2fs kept reporting last time when I ran it within the session of my target fedora that the disk was in use therefore it will do a on-line resize. Therefore, I knew I have to give him the disk when nobody will be using it. The hurdle is that the disk itself is a virtual lvm volume. Therefore I had to struggle more on understanding how to activate a volume without mounting any filesystem and that too in a rescue mode.
  8. Now we run resize2fs –physicalvolumesize NNG /dev/VolGroup00/Logvol01
  9. Amazingly it ran without any complain.
  10. explanation: Resize is a two stage process. Its the same even in the LVM context. You can’t just go to and resize the partition. The data units will also have to placed within the new boundries before the resize is done. Otherwise, you will simple have many  bad files reported from your disk check utility. therefore In windows, filesystems are defragmented before being shrunk. Defragmentation moves all the chunks of the file to the start of the disk and the tail of the partition becomes clean. Now after resize, no data is lost. In linux ext2/3 context, as far as I know, linux keeps its file chunks spread all over the available space. This trick saves the requirements of frequent defragmentations requests from the disk. Since all chunks in a file are contigous a file itself gives good read/write performance. But files themselves are never contiguous  and have large chunks of free space when written on disk. This property allows the filesystem space on the tail of every file which may expand. At the last point when no further expansion is possible the chunk is broken and continued some place else. In percentage terms the fragmentation of ext2 file system is under 5% after a very long use compared to ntfs or fat file system.
  11. So resize2fs moves all the chunks within the limits of the suggested boundry but unlike windows, does not defragment everything.
  12. Once, resize2fs is done, call lvresize to change the volume itself. It will report that data might get lost. Since we alreadt called resize2fs, it has already done the shifting job to prevent a data loss.
  13. Then you need to resize the entire volume group using vgresize.
  14. In my case, it failed cause there was already a volume at the end of the group. Since it was swap space, I simply vlremove it and went on.
  15. The next step is to resize the physical volume using pvmove.
  16. Finally, to use fdisk and delete old parition, create a new one with smaller size and save changes. Make sure the system id is 8E for lvm flag.
  17. I did a reboot and saw my freespace.

Phew!


One Response to “How to resize LVM partition on Fedora 9”

  1. How to resize LVM partition on Fedora 9 | Fishing And Hunting Says:

    [...] the original post: How to resize LVM partition on Fedora 9 This entry was posted on Tuesday, November 25th, 2008 at 6:10 am and is filed under hunting. You [...]

Leave a Reply