{"id":2964,"date":"2014-03-29T09:18:32","date_gmt":"2014-03-29T01:18:32","guid":{"rendered":"http:\/\/rmohan.com\/?p=2964"},"modified":"2014-03-29T09:18:32","modified_gmt":"2014-03-29T01:18:32","slug":"shrink-root-partition-using-lvm","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=2964","title":{"rendered":"Shrink root partition using LVM"},"content":{"rendered":"<div dir=\"ltr\">While I installed my OS long back, I had partitioned more space in the root file system, because of which I was unable to use other file systems due to lack of disk space.<\/div>\n<div dir=\"ltr\"><\/div>\n<div>So, incase if few are facing the same issues, here is the tutorial to decrease your space in root partition.<\/div>\n<div><\/div>\n<div>Once your volume group(VG) gets free space, you can extend any where in your logical volumes(LV) which resides in the same volume group(VG)<\/div>\n<div><\/div>\n<div><b>Change Plan:<\/b><\/div>\n<div>1. find the current disk usage in the file system.<\/div>\n<div>2. Since your root partition(mounted) needs to be\u00a0re-sized,\u00a0\u00a0need access to\u00a0unmounted\u00a0root volume\u00a0get into the rescue environment.<\/div>\n<div>3. Change to logical volume manager in\u00a0rescue environment.<\/div>\n<div>4. Shrink the root file system<\/div>\n<div>5. Reduce root volume.<\/div>\n<div>6. Reboot system and bring it online.<\/div>\n<div>7. Check the root disk after\u00a0re-sizing.<\/div>\n<div><\/div>\n<div><b>Technical Implementation:<\/b><\/div>\n<div><b>\u00a0<\/b><\/div>\n<div>1. Current disk usage:<\/div>\n<div>tux# df -h<\/div>\n<div>Filesystem \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0Size \u00a0Used Avail Use% Mounted on<\/div>\n<div>\/dev\/mapper\/VolGroup00-LogVol00<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<b>\u00a0 \u00a0 6.7G \u00a02.0G \u00a04.5G \u00a031% \/<\/b><\/div>\n<div>\/dev\/sda1 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a099M \u00a0 12M \u00a0 83M \u00a013% \/boot<\/div>\n<div><\/div>\n<div>tmpfs \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 379M \u00a0 \u00a0 0 \u00a0379M \u00a0 0% \/dev\/shm<\/div>\n<div><\/div>\n<div>2. Reboot the system and boot system in rescue environment.<\/div>\n<div><\/div>\n<div>3. In rescue shell, change to LV Manager prompt.<\/div>\n<div>#lvm vgchange -a y<\/div>\n<div><\/div>\n<div>The -a y argument sets the availability to &#8220;y&#8221; or yes. As there are no specified LVM volume groups, this command will make all LVM volumes found available to the rescue kernel.<\/div>\n<div><\/div>\n<div>Once the kernel is aware of all LVM volumes they will be automatically mapped as devices. These are usually located under \/dev\/VolGroup.<\/div>\n<div><\/div>\n<div>#ls \/dev\/VolGroup00\/<\/div>\n<div><\/div>\n<div>LogVol00 \u00a0LogVol01<\/div>\n<div><\/div>\n<div>#e2fsck -f \/dev\/VolGroup00\/LogVol00<\/div>\n<div><\/div>\n<div>4. After the check, resize2fs can be used to shrink the file system on the LVM volume. Here I reduce the root volume to 1GB<\/div>\n<div><\/div>\n<div>#resize2fs -f \/dev\/VolGroup00\/LogVol00 1G<\/div>\n<div><\/div>\n<div><\/div>\n<div>The e2fsck check command could be run again to make sure the, now significantly smaller, root file system is OK.<\/div>\n<div><\/div>\n<div>5. Reduce the root volume.<\/div>\n<div>#lvm lvreduce -L 1G \/dev\/VolGroup00\/LogVol00<\/div>\n<div><\/div>\n<div>The lvreduce command reduces the size of LVM volumes. The -L option allows the new size to be explicitly given. If the option to this argument does not begin with a minus sign, it is taken as the size to reduce the volume.<\/div>\n<div><\/div>\n<div>6. Remove CD\/DVD and reboot the system to bring it online.<\/div>\n<div>#reboot<\/div>\n<div><\/div>\n<div>7. Check root partition after reboot.<\/div>\n<div>tux# df -h<\/div>\n<div>Filesystem \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0Size \u00a0Used Avail Use% Mounted on<\/div>\n<div>\/dev\/mapper\/VolGroup00-LogVol00<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<b>\u00a0 5.9G \u00a02.0G \u00a03.7G \u00a035% \/<\/b><\/div>\n<div>\/dev\/sda1 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a099M \u00a0 12M \u00a0 83M \u00a013% \/boot<\/div>\n<div>tmpfs \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 379M \u00a0 \u00a0 0 \u00a0379M \u00a0 0% \/dev\/shm<\/div>\n<div><\/div>\n<div>Root partition was\u00a0shrinked\u00a0successfully.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>While I installed my OS long back, I had partitioned more space in the root file system, because of which I was unable to use other file systems due to lack of disk space. So, incase if few are facing the same issues, here is the tutorial to decrease your space in root partition. Once [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2964"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2964"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2964\/revisions"}],"predecessor-version":[{"id":2965,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2964\/revisions\/2965"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}