Extending and Shrinking Logical Partitions
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.
- 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 there are other tools (ex: ext2online or resize_reiserfs).
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.
Shrink the filesystem and volume
- 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.
- Run the following command
resize2fs -p /dev/vg_ticc1/lv_home 200G
- You should get a note that you need to run
e2fsck -f /dev/vg_ticc1/lv_home
- Run the command. If something goes wrong during this step, STOP. That could be an indicator of greater disk issues.
- Run the resize2fs command again.
- Remount the drive and check to ensure that it completed successfully.
- Run the command
lvreduce -L 200G /dev/vg_ticc1/lv_home
- 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.
- Check that this freed up space by running vgdisplay. 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 vgdisplay.
- You can use the lvdisplay command to check the proper names of your volumes as well as their sizes.
- Run the command This extends the logical volume to use up all of the free space within the group.
lvextend -l +100%FREE /dev/vg_ticc1/lv_root
- Extend the filesystem by running
resize2fs -p /dev/vg_ticc1/lv_root
- Check that everything worked as expected by running df -h.
- This should be everything.