Extending and Shrinking Logical Partitions

(Difference between revisions)
Jump to: navigation, search
Line 10: Line 10:
  
 
== Process ==
 
== Process ==
 +
=== Shrink the filesystem and volume ===
 
#Cut a hole in the box.
 
#Cut a hole in the box.
 
#Unmount the partition you're about to shrink.  If you're trying to do this to something like /, then you're going to need to do it from a live-cd or different installation.
 
#Unmount the partition you're about to shrink.  If you're trying to do this to something like /, then you're going to need to do it from a live-cd or different installation.
Line 20: Line 21:
 
#Run the command.  If something goes wrong during this step, STOP.  That could be an indicator of greater disk issues.
 
#Run the command.  If something goes wrong during this step, STOP.  That could be an indicator of greater disk issues.
 
#Run the <tt>resize2fs</tt> command again.
 
#Run the <tt>resize2fs</tt> command again.
#
+
#Remount the drive and check to ensure that it completed successfully.
 +
#Run the command <syntaxhighlight lang="bash">
 +
lvreduce -L 200G /dev/vg_ticc1/lv_home
 +
</syntaxhighlight>
 +
#This WILL produce a warning telling you that you may destroy your data.  This should have been mitigated by the backup procedure <i>that you definitely followed, right?</i>  Additionally, if you try to reduce the volume to a size smaller than what you just set for the filesystem, you may encounter bugs.  Like your data missing.
 +
#Check that this freed up space by running <tt>vgdisplay</tt>.  It should show some under "Free PE / Size."
 +
 
 +
=== Extend the other volume and filesystem ===
 +
#Start by ensuring that you have the space available to extend the volume by running <tt>vgdisplay</tt>.
 +
#You can use the <tt>lvdisplay</tt> command to check the proper names of your volumes as well as their sizes.
 +
#Run the command <syntaxhighlight lang="bash">
 +
lvextend -l +100%FREE /dev/vg_ticc1/lv_root
 +
</syntaxhighlight> This extends the logical volume to use up all of the free space within the group.
 +
#Extend the filesystem by running <syntaxhighlight lang="bash">
 +
resize2fs -p /dev/vg_ticc1/lv_root
 +
</syntaxhighlight>
 +
#Check that everything worked as expected by running <tt>df -h</tt>.
 +
#This should be everything.
  
 
== References and External Links ==
 
== References and External Links ==
 
*[http://www.computers-it.com/linux/linux_lvm_resize_filesystem.php Computers-IT]
 
*[http://www.computers-it.com/linux/linux_lvm_resize_filesystem.php Computers-IT]

Revision as of 20:31, 24 April 2013

We found out that the way our parititions were originally was that we did not have enough space for the root partition and more than enough on our home. Since we're using LVMs, we needed to resize those, preferably with everything running and without losing data.

Contents

Important Notes

  • This messes with your logical volumes. This can damage your data if you do it incorrectly or if you do not take proper precautions. BACK UP YOUR DATA!
  • This method is intended for logical volumes. We take no responsibility for anything you do with this otherwise.
  • We used resize2fs for this process, but

Overview

What this method does is shrink one partition (say, /home), and expand another (/, for instance). With LVMs, this becomes a matter of shrinking the filesystem on the volume and then the volume itself. Afterwards, when you want to expand the other partition, you do the same process in reverse, you increase the volume size and then increase the filesystem to fill the new volume.

Process

Shrink the filesystem and volume

  1. Cut a hole in the box.
  2. Unmount the partition you're about to shrink. If you're trying to do this to something like /, then you're going to need to do it from a live-cd or different installation.
  3. Run the following command
    resize2fs -p /dev/vg_ticc1/lv_home 200G
  4. You should get a note that you need to run
    e2fsck -f /dev/vg_ticc1/lv_home
  5. Run the command. If something goes wrong during this step, STOP. That could be an indicator of greater disk issues.
  6. Run the resize2fs command again.
  7. Remount the drive and check to ensure that it completed successfully.
  8. Run the command
    lvreduce -L 200G /dev/vg_ticc1/lv_home
  9. This WILL produce a warning telling you that you may destroy your data. This should have been mitigated by the backup procedure that you definitely followed, right? Additionally, if you try to reduce the volume to a size smaller than what you just set for the filesystem, you may encounter bugs. Like your data missing.
  10. Check that this freed up space by running vgdisplay. It should show some under "Free PE / Size."

Extend the other volume and filesystem

  1. Start by ensuring that you have the space available to extend the volume by running vgdisplay.
  2. You can use the lvdisplay command to check the proper names of your volumes as well as their sizes.
  3. Run the command
    lvextend -l +100%FREE /dev/vg_ticc1/lv_root
    This extends the logical volume to use up all of the free space within the group.
  4. Extend the filesystem by running
    resize2fs -p /dev/vg_ticc1/lv_root
  5. Check that everything worked as expected by running df -h.
  6. This should be everything.

References and External Links

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox