{"id":99,"date":"2012-02-29T10:56:41","date_gmt":"2012-02-28T21:56:41","guid":{"rendered":"http:\/\/www.templesoft.co.nz\/blog\/?p=99"},"modified":"2026-04-08T08:19:30","modified_gmt":"2026-04-07T20:19:30","slug":"online-resizing-of-an-lvm-partition","status":"publish","type":"post","link":"https:\/\/templesoft.co.nz\/journal\/?p=99","title":{"rendered":"Online resizing of an LVM partition."},"content":{"rendered":"<h2 style=\"text-align: left;\">The concept and objective<\/h2>\n<p style=\"text-align: justify;\">I built a Bacula server a while back with a 500GB HDD, which I use to backup a number of servers including a mail server. I had it setup so it would recycle the volumes every 180 days (roughly six months), thinking that each volume would well and truly be ready for recycle by that time.<\/p>\n<p style=\"text-align: justify;\">The trouble was, the mail server&#8217;s popularity, not to mention the users desire to keep every Powerpoint presentation touting the latest emotional platitudes (you know the ones) meant that recycle time came around much faster than I thought.<\/p>\n<p style=\"text-align: justify;\">I didn&#8217;t want to rebuild the server, so the plan was to clone the 500GB drive onto a 1TB drive, and resize the partitions accordingly.<\/p>\n<p style=\"text-align: justify;\">The plan was to follow these general steps:<\/p>\n<ol>\n<li>Create a new partition on the unallocated free space.<\/li>\n<li>Expand the <strong>physical<\/strong> volume to include the new partition.<\/li>\n<li>Expand the <strong>logical<\/strong> volume into the inflated PV.<\/li>\n<li>Resize the file system into the expanded LV.<\/li>\n<\/ol>\n<p style=\"text-align: justify;\">Simple right? Well, yes&#8230; in a sort of round about way. You have to remember the context I operate in &#8211; I use free stuff as much as possible!! Most free tools out there allow you to do most things, but don&#8217;t make it too easy for you because they want you to buy the posh version (of course!)<\/p>\n<p style=\"text-align: justify;\">So, that said there are probably paid applications which will do it all for you &#8211; this HOWTO is based on some of the FREE tools I had at hand.<\/p>\n<h2 style=\"text-align: left;\">The ultimate power in the universe&#8230; well, in a boot CD maybe<\/h2>\n<p style=\"text-align: justify;\">If you don&#8217;t have it already, grab a copy of the &#8220;<a href=\"http:\/\/www.ultimatebootcd.com\/\">Ultimate Boot CD<\/a>&#8221; or UBCD as it&#8217;s often referred to. It&#8217;s a great ISO packed with tons of tools that can either be burnt onto CD or imaged to USB.<\/p>\n<p style=\"text-align: justify;\">I had mixed results with some of the tools so I&#8217;ll give you a rundown own what worked\/didn&#8217;t work for me:<\/p>\n<ul>\n<li><strong>Parted Magic<\/strong> has some great utilities. However, I don&#8217;t know if it was me but <a href=\"http:\/\/clonezilla.org\/\"><strong>Clonezilla<\/strong> <\/a>(which can resize partitions automatically and proportionally) took the better part of three days and was still going when I decided to kill it.<\/li>\n<li><strong>Parted magic<\/strong> also has <a href=\"http:\/\/gparted.sourceforge.net\/\"><strong>GParted<\/strong> <\/a>, a GUI of parted for resizing the partitions &#8211; but this didn&#8217;t support LVM volume resizing.<\/li>\n<li>One of the &#8220;Hard Disk Cloning&#8221; tools under the UBCD menu is <a href=\"http:\/\/www.miray.de\/download\/sat.hdclone.html\"><strong>HDClone<\/strong><\/a>. A great cloning tool, but it doesn&#8217;t have the ability to resize the partitions proportionally, and is transfer speed limited (<em>because it&#8217;s the free edition<\/em>).<\/li>\n<li>I ended up using <a href=\"http:\/\/www.easeus.com\/disk-copy\/index.htm\"><strong>EaseUs Disk Copy<\/strong><\/a> (v2.3.1) &#8211; it cloned the disks with a fantastic 3.08GB\/s and only took around an hour and a half (1.5 hours).<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">Once the disks had been cloned, I removed the original drive and booted off the clone drive as normal.<\/p>\n<h2 style=\"text-align: left;\">Come out, come out free space wherever you are?<\/h2>\n<p style=\"text-align: justify;\">I&#8217;ll add &#8220;<strong>the<\/strong>&#8221; disclaimer at this point: This was the way I resized my volume &#8211; there may be other ways, better ways. Most importantly, make sure you have a backup of your data as working with the partitions and volumes can result in loss of data!!<\/p>\n<p style=\"text-align: justify;\">OK, are we good to go on?<\/p>\n<p style=\"text-align: justify;\">I used &#8216;<strong>parted<\/strong>&#8216; to create a new partition because fdisk didn&#8217;t give me any options to display or use the unallocated free space.<\/p>\n<pre>sudo parted\r\n\r\n<span style=\"color: #0000ff;\">(parted) <strong>print free<\/strong>\r\nModel: ATA ST31000524AS (scsi)\r\nDisk <span style=\"color: #00ccff;\"><strong>\/dev\/sda<\/strong><\/span>: 1000GB     <strong><span style=\"color: #c0c0c0;\">&lt;-- !!Take note of this disk id, we'll need it later !!<\/span><\/strong>\r\nSector size (logical\/physical): 512B\/512B\r\nPartition Table: msdos\r\n\r\nNumber  Start   End     Size    Type      File system  Flags\r\n        32.3kB  1049kB  1016kB            Free Space\r\n 1      1049kB  256MB   255MB   primary   ext2         boot\r\n        256MB   257MB   1048kB            Free Space\r\n 2      257MB   500GB   500GB   extended\r\n 5      257MB   500GB   500GB   logical                lvm\r\n        500GB   500GB   1049kB            Free Space\r\n        500GB   1000GB  500GB             Free Space   <strong><span style=\"color: #c0c0c0;\">&lt;-- Note the 'Start' and 'End' value.<\/span><\/strong>\r\n        1000GB  1000GB  745kB             Free Space<\/span><\/pre>\n<p style=\"text-align: justify;\">(parted) print free<\/p>\n<p style=\"text-align: justify;\">Model: ATA ST31000524AS (scsi)<\/p>\n<p style=\"text-align: justify;\">Disk \/dev\/sda: 1000GB &lt;&#8211; !!Take note of this disk id, we&#8217;ll need it later !!<\/p>\n<p style=\"text-align: justify;\">Sector size (logical\/physical): 512B\/512B<\/p>\n<p style=\"text-align: justify;\">Partition Table: msdos<\/p>\n<p style=\"text-align: justify;\">Number Start End Size Type File system Flags<\/p>\n<p style=\"text-align: justify;\">32.3kB 1049kB 1016kB Free Space<\/p>\n<p style=\"text-align: justify;\">1 1049kB 256MB 255MB primary ext2 boot<\/p>\n<p style=\"text-align: justify;\">256MB 257MB 1048kB Free Space<\/p>\n<p style=\"text-align: justify;\">2 257MB 500GB 500GB extended<\/p>\n<p style=\"text-align: justify;\">5 257MB 500GB 500GB logical lvm<\/p>\n<p style=\"text-align: justify;\">500GB 500GB 1049kB Free Space<\/p>\n<p style=\"text-align: justify;\">500GB 1000GB 500GB Free Space &lt;&#8211; Note the &#8216;Start&#8217; and &#8216;End&#8217; value.<\/p>\n<p style=\"text-align: justify;\">1000GB 1000GB 745kB Free Space<\/p>\n<p style=\"text-align: justify;\">Look at the entries listing the free space and note down the &#8216;Start&#8217; and &#8216;End&#8217; value for the corresponding block of free space you want to use. In this case it&#8217;s &#8216;500GB&#8217; and &#8216;1000GB&#8217; respectively. It&#8217;s also worth noting down the disk id as we&#8217;ll need this in a later step &#8211; in this case it&#8217;s \/dev\/sda.<\/p>\n<p style=\"text-align: justify;\">Time to create our new partition&#8230;<\/p>\n<p style=\"text-align: justify;\">(parted) mkpart<\/p>\n<p style=\"text-align: justify;\">Partition type? primary\/logical? p<\/p>\n<p style=\"text-align: justify;\">File system type? [ext2]? ext3<\/p>\n<p style=\"text-align: justify;\">Start? 500GB<\/p>\n<p style=\"text-align: justify;\">End? 1000GB<\/p>\n<p style=\"text-align: justify;\">&#8230;and check to confirm it&#8217;s been created, then quit parted<\/p>\n<p style=\"text-align: justify;\">(parted) print<\/p>\n<p style=\"text-align: justify;\">Model: ATA ST31000524AS (scsi)<\/p>\n<p style=\"text-align: justify;\">Disk \/dev\/sda: 1000GB<\/p>\n<p style=\"text-align: justify;\">Sector size (logical\/physical): 512B\/512B<\/p>\n<p style=\"text-align: justify;\">Partition Table: msdos<\/p>\n<p style=\"text-align: justify;\">Number Start End Size Type File system Flags<\/p>\n<p style=\"text-align: justify;\">1 1049kB 256MB 255MB primary ext2 boot<\/p>\n<p style=\"text-align: justify;\">2 257MB 500GB 500GB extended<\/p>\n<p style=\"text-align: justify;\">5 257MB 500GB 500GB logical lvm<\/p>\n<p style=\"text-align: justify;\">3 500GB 1000GB 500GB primary &lt;&#8211; Your new partiton! Note the number &#8216;3&#8217;<\/p>\n<p style=\"text-align: justify;\">(parted) quit<\/p>\n<p style=\"text-align: justify;\">Information: You may need to update \/etc\/fstab.<\/p>\n<p style=\"text-align: justify;\">Now some wichery as we use fdisk to change the new partition&#8217;s system type.<\/p>\n<p style=\"text-align: justify;\">sudo fdisk \/dev\/sda<\/p>\n<p style=\"text-align: justify;\">Command (m for help): t<\/p>\n<p style=\"text-align: justify;\">Partition number (1-5): 3 &lt;&#8211; Use the number obtained above using parted<\/p>\n<p style=\"text-align: justify;\">Hex code (type L to list codes): 8e<\/p>\n<p style=\"text-align: justify;\">Changed system type of partition 3 to 8e (Linux LVM)<\/p>\n<p style=\"text-align: justify;\">Now check to make sure changes have taken&#8230;<\/p>\n<p style=\"text-align: justify;\">Command (m for help): p<\/p>\n<p style=\"text-align: justify;\">Disk \/dev\/sda: 1000.2 GB, 1000204886016 bytes<\/p>\n<p style=\"text-align: justify;\">255 heads, 63 sectors\/track, 121601 cylinders<\/p>\n<p style=\"text-align: justify;\">Units = cylinders of 16065 * 512 = 8225280 bytes<\/p>\n<p style=\"text-align: justify;\">Sector size (logical\/physical): 512 bytes \/ 512 bytes<\/p>\n<p style=\"text-align: justify;\">I\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<\/p>\n<p style=\"text-align: justify;\">Disk identifier: 0x0002a3e6<\/p>\n<p style=\"text-align: justify;\">Device Boot Start End Blocks Id System<\/p>\n<p style=\"text-align: justify;\">\/dev\/sda1 * 1 32 248832 83 Linux<\/p>\n<p style=\"text-align: justify;\">\/dev\/sda2 32 60802 488136705 5 Extended<\/p>\n<p style=\"text-align: justify;\">\/dev\/sda3 60802 121602 488374272 8e Linux LVM &lt;&#8211; Here is the changed partition!<\/p>\n<p style=\"text-align: justify;\">\/dev\/sda5 32 60802 488135680 8e Linux LVM<\/p>\n<p style=\"text-align: justify;\">&#8230; and write the changes.<\/p>\n<p style=\"text-align: justify;\">Command (m for help): w<\/p>\n<p style=\"text-align: justify;\">The partition table has been altered!<\/p>\n<p style=\"text-align: justify;\">Calling ioctl() to re-read partition table.<\/p>\n<p style=\"text-align: justify;\">WARNING: Re-reading the partition table failed with error 16: Device or resource busy.<\/p>\n<p style=\"text-align: justify;\">The kernel still uses the old table. The new table will be used at<\/p>\n<p style=\"text-align: justify;\">the next reboot or after you run partprobe(8) or kpartx(8)<\/p>\n<p style=\"text-align: justify;\">Syncing disks.<\/p>\n<p style=\"text-align: justify;\">Reboot the system for the changes to take effect.<\/p>\n<p style=\"text-align: justify;\">sudo shutdown -r now<\/p>\n<p style=\"text-align: justify;\">A volume by any other name.<\/p>\n<p style=\"text-align: justify;\">Once the system has restarted, log on and create a new physical volume, on the new partition&#8230;<\/p>\n<p style=\"text-align: justify;\">sudo pvcreate \/dev\/sda3<\/p>\n<p style=\"text-align: justify;\">Physical volume &#8220;\/dev\/sda3&#8221; successfully created<\/p>\n<p style=\"text-align: justify;\">Confirm the new volume has been created&#8230;<\/p>\n<p style=\"text-align: justify;\">sudo pvdisplay<\/p>\n<p style=\"text-align: justify;\">&#8212; Physical volume &#8212;<\/p>\n<p style=\"text-align: justify;\">PV Name \/dev\/sda5<\/p>\n<p style=\"text-align: justify;\">VG Name vgname<\/p>\n<p style=\"text-align: justify;\">PV Size 465.52 GiB \/ not usable 2.81 MiB<\/p>\n<p style=\"text-align: justify;\">Allocatable yes<\/p>\n<p style=\"text-align: justify;\">PE Size 4.00 MiB<\/p>\n<p style=\"text-align: justify;\">Total PE 119173<\/p>\n<p style=\"text-align: justify;\">Free PE 12<\/p>\n<p style=\"text-align: justify;\">Allocated PE 119161<\/p>\n<p style=\"text-align: justify;\">PV UUID vdZpKf-KkHG-mEtw-2vsh-khTT-rRr2-6qhbuL<\/p>\n<p style=\"text-align: justify;\">&#8220;\/dev\/sda3&#8221; is a new physical volume of &#8220;465.75 GiB&#8221;<\/p>\n<p style=\"text-align: justify;\">&#8212; NEW Physical volume &#8212;<\/p>\n<p style=\"text-align: justify;\">PV Name \/dev\/sda3<\/p>\n<p style=\"text-align: justify;\">VG Name<\/p>\n<p style=\"text-align: justify;\">PV Size 465.75 GiB<\/p>\n<p style=\"text-align: justify;\">Allocatable NO<\/p>\n<p style=\"text-align: justify;\">PE Size 0<\/p>\n<p style=\"text-align: justify;\">Total PE 0<\/p>\n<p style=\"text-align: justify;\">Free PE 0<\/p>\n<p style=\"text-align: justify;\">Allocated PE 0<\/p>\n<p style=\"text-align: justify;\">PV UUID UfF1rK-Lx8e-G8Vg-A321-uJQO-5I5O-gqS4XZ<\/p>\n<p style=\"text-align: justify;\">Now we extend the volume group to include the new physical volume.<\/p>\n<p style=\"text-align: justify;\">sudo vgextend vgname \/dev\/sda3<\/p>\n<p style=\"text-align: justify;\">Volume group &#8220;vgname&#8221; successfully extended<\/p>\n<p style=\"text-align: justify;\">We can confirm the logical volume name&#8230;<\/p>\n<p style=\"text-align: justify;\">sudo lvdisplay<\/p>\n<p style=\"text-align: justify;\">&#8212; Logical volume &#8212;<\/p>\n<p style=\"text-align: justify;\">LV Name \/dev\/vgname\/root &lt;&#8211; this is what we&#8217;ll use in the next step<\/p>\n<p style=\"text-align: justify;\">VG Name vgname<\/p>\n<p style=\"text-align: justify;\">LV UUID ebGsgt-CNyw-MsMw-cMM1-ORiD-uZyI-jQqCU4<\/p>\n<p style=\"text-align: justify;\">LV Write Access read\/write<\/p>\n<p style=\"text-align: justify;\">LV Status available<\/p>\n<p style=\"text-align: justify;\"># open 1<\/p>\n<p style=\"text-align: justify;\">LV Size 459.82 GiB &lt;&#8211; this will increase after we extend the LV<\/p>\n<p style=\"text-align: justify;\">Current LE 117715<\/p>\n<p style=\"text-align: justify;\">Segments 1<\/p>\n<p style=\"text-align: justify;\">Allocation inherit<\/p>\n<p style=\"text-align: justify;\">Read ahead sectors auto<\/p>\n<p style=\"text-align: justify;\">&#8211; currently set to 256<\/p>\n<p style=\"text-align: justify;\">Block device 251:0<\/p>\n<p style=\"text-align: justify;\">&#8230; and extend the logical volume to include the physical volume (which is now in our volume group).<\/p>\n<p style=\"text-align: justify;\">sudo lvextend \/dev\/vgname\/root \/dev\/sda3<\/p>\n<p style=\"text-align: justify;\">Extending logical volume root to 925.57 GiB<\/p>\n<p style=\"text-align: justify;\">Logical volume root successfully resized<\/p>\n<p style=\"text-align: justify;\">A quick check now reveals&#8230;<\/p>\n<p style=\"text-align: justify;\">sudo lvdisplay<\/p>\n<p style=\"text-align: justify;\">&#8212; Logical volume &#8212;<\/p>\n<p style=\"text-align: justify;\">LV Name \/dev\/vgname\/root &lt;&#8211; this is what we&#8217;ll use in the next step<\/p>\n<p style=\"text-align: justify;\">VG Name vgname<\/p>\n<p style=\"text-align: justify;\">LV UUID ebGsgt-CNyw-MsMw-cMM1-ORiD-uZyI-jQqCU4<\/p>\n<p style=\"text-align: justify;\">LV Write Access read\/write<\/p>\n<p style=\"text-align: justify;\">LV Status available<\/p>\n<p style=\"text-align: justify;\"># open 1<\/p>\n<p style=\"text-align: justify;\">LV Size 925.57 GiB &lt;&#8211; HOORAY!!<\/p>\n<p style=\"text-align: justify;\">Current LE 236946<\/p>\n<p style=\"text-align: justify;\">Segments 2<\/p>\n<p style=\"text-align: justify;\">Allocation inherit<\/p>\n<p style=\"text-align: justify;\">Read ahead sectors auto<\/p>\n<p style=\"text-align: justify;\">&#8211; currently set to 256<\/p>\n<p style=\"text-align: justify;\">Block device 251:0<\/p>\n<p style=\"text-align: justify;\">Finally, we use resize2fs to resize the file system to include the new space created in the logical volume.<\/p>\n<p style=\"text-align: justify;\">sudo resize2fs \/dev\/vgname\/root<\/p>\n<p style=\"text-align: justify;\">resize2fs 1.41.11 (14-Mar-2010)<\/p>\n<p style=\"text-align: justify;\">Filesystem at \/dev\/vgname\/root is mounted on \/; on-line resizing required<\/p>\n<p style=\"text-align: justify;\">old desc_blocks = 29, new_desc_blocks = 58<\/p>\n<p style=\"text-align: justify;\">Performing an on-line resize of \/dev\/vgname\/root to 242632704 (4k) blocks.<\/p>\n<p style=\"text-align: justify;\">This last step took almost an hour to complete. The rough maths would be 60 minutes divided by the 29 block increase equals ~2 minutes per block. I&#8217;m guessing that this would change depending on the specifications of your hardware, disks, interfaces etc&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The concept and objective I built a Bacula server a while back with a 500GB HDD, which I use to backup a number of servers including a mail server. I had it setup so it would recycle the volumes every 180 days (roughly six months), thinking that each volume would well and truly be ready&#8230;  <a class=\"excerpt-read-more\" href=\"https:\/\/templesoft.co.nz\/journal\/?p=99\" title=\"Read Online resizing of an LVM partition.\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,2],"tags":[84,80,86,87,83,79,85,88,82,81],"class_list":["post-99","post","type-post","status-publish","format-standard","hentry","category-recovery","category-technical-resource","tag-fdisk","tag-logical-volume","tag-lvdisplay","tag-lvextend","tag-parted","tag-physical-volume","tag-pvdisplay","tag-resize2fs","tag-ubcd","tag-volume"],"_links":{"self":[{"href":"https:\/\/templesoft.co.nz\/journal\/index.php?rest_route=\/wp\/v2\/posts\/99","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/templesoft.co.nz\/journal\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/templesoft.co.nz\/journal\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/templesoft.co.nz\/journal\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/templesoft.co.nz\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=99"}],"version-history":[{"count":4,"href":"https:\/\/templesoft.co.nz\/journal\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":181,"href":"https:\/\/templesoft.co.nz\/journal\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions\/181"}],"wp:attachment":[{"href":"https:\/\/templesoft.co.nz\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/templesoft.co.nz\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/templesoft.co.nz\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}