{"id":34,"date":"2021-01-28T12:38:00","date_gmt":"2021-01-28T12:38:00","guid":{"rendered":"https:\/\/robertrath.com\/gadgetzone\/archives\/34-how-to-resize-an-encrypted-drive.html"},"modified":"2021-01-30T03:36:20","modified_gmt":"2021-01-30T03:36:20","slug":"how-to-resize-an-encrypted-drive","status":"publish","type":"post","link":"https:\/\/robertrath.com\/gadgetzone\/archives\/34-how-to-resize-an-encrypted-drive.html","title":{"rendered":"How To Resize An Encrypted Drive"},"content":{"rendered":"In these examples we will expand the entire disk from 32GB to 64GB.<br \/>\n<br \/>\nThe examples given are with and without an existing swap volume and will use an Ubuntu Live CD ISO as the surrogate.<br \/>\n<br \/>\n<li>Shutdown the target machine.<\/li><br \/>\n<li>In VMware Player, select the target and go to &#8216;Edit virtual machine settings&#8217;.<\/li><br \/>\n<li>Select the &#8216;Hard Disk&#8217; and then go to &#8216;Utilities -&gt; Expand&#8230;&#8217;.<\/li><br \/>\n<li>Enter the new size, ie 32GB and click on &#8216;Expand&#8217;.<\/li><br \/>\n<li>Select the &#8216;CD\/DVD&#8217;, ensure &#8216;Connect at power on&#8217; is checked, select &#8216;Use ISO image file:&#8217; and browse for an approriate Live CD ISO file to boot from. Click OK.<\/li><br \/>\n<li>In VMware Player, select the target and start it. Ensure you are booting into the Live CD.<\/li><br \/>\n<li>If the boot is incorrect, append the line &#8216;bios.forceSetupOnce = &#8220;TRUE&#8221;&#8216; to your target &#8216;vmx&#8217; file, make the necessary bios changes and then boot into the Live CD.<\/li><br \/>\n<li>Make sure you select &#8216;Try Ubuntu&#8217; and NOT install.<\/li><br \/>\n<br \/>\n<pre>root@ubuntu:~# lsblk<\/pre><br \/>\n<br \/>\n<li>Now that we have identified sda as our target we can go to work on it. Proceed with caution as you can easily destroy all your data!<\/li><br \/>\n<br \/>\n<pre>fdisk \/dev\/sda # open sda in 'fdisk'<\/pre><br \/>\n<br \/>\n<li>Use the &#8216;p&#8217; command to print the current partition table, note the start sector addresses of both sda2 and sda5.<\/li><br \/>\n<li>Use the &#8216;d&#8217; command to delete partitions 5 and then 2.<\/li><br \/>\n<li>Use the &#8216;n&#8217; command to create a new extended partition 2.&nbsp;Use the default sector start address which may be less than the original sda2.<\/li><br \/>\n<li>Use the &#8216;n&#8217; command to create a new logical partition 5. Make sure the sector start address is exactly the same as the original sda5. Do not remove the LUKS signature if asked.<\/li><br \/>\n<li>Use the &#8216;w&#8217; command to write the changes and exit from &#8216;fdisk&#8217;.<\/li><br \/>\n<li>The system may automatically mount sda1\/sda5 during operations. If so unmount them.<\/li><br \/>\n<br \/>\n<strong>Simple Single Volume<\/strong><br \/>\n<br \/>\nIn this example we will expand the entire disk from 32GB to 64GB.<br \/>\n<br \/>\n<pre>cryptsetup luksOpen \/dev\/sda5 target    # use the LUKS password to decrypt sda5\nvgscan --mknodes &amp;&amp; vgchange -ay        # Identify and activate the LVM.\ncryptsetup resize target                # Resize the crypt\npvresize \/dev\/mapper\/target             # Resize the volume group\npvchange -x y \/dev\/mapper\/target        # unlock the (LVM) physical volume.\nlvresize -r -L+32G \/dev\/xubuntu-vg\/root # increase our root volume by in this case 32GB, resizing (-r) the underlying filesystem \nvgdisplay                               # find out how much space is now available in our volume group\npvchange -x n \/dev\/mapper\/target        # re-lock the physical volume\nshutdown -h now                         # we are done with the Live CD so.<\/pre><br \/>\n<br \/>\n<strong>Include A Swap File<\/strong><br \/>\n<br \/>\nIn this example we will expand the entire disk from 32GB to 64GB moving an existing swap file of 4GB to the end of the drive. <br \/>\n<br \/>\n<pre>cryptsetup luksOpen \/dev\/sda5 target                         # use the LUKS password to decrypt sda5\n                                                             # the system may automatically mount sda and the logical volumes\n                                                             # inside target_encrypted_volume. If so unmount them.\nvgscan --mknodes &amp;&amp; vgchange -ay                             # Identify and activate the LVM.\ncryptsetup resize target                                     # Resize the crypt\npvresize \/dev\/mapper\/target                                  # Resize the volume group\nlvdisplay                                                    # Use 'lvdisplay' to identify the target volumes for managing\nlvremove \/dev\/xubuntu-vg\/swap                                # remove our swap volume, it is in the way.\npvchange -x y \/dev\/mapper\/target                             # unlock the (LVM) physical volume.\nlvresize -r -L+32G \/dev\/xubuntu-vg\/root                      # increase our root volume by in this case 32GB, resizing (-r) the underlying filesystem \nvgdisplay                                                    # find out how much space is now available in our volume group\nlvcreate --extents 1024 -n \/dev\/xubuntu-vg\/swap   xubuntu-vg # Create a new volume (516 comes from finding the available 'logical extents' in the group using 'vgdisplay'). Remove Swap signature\npvchange -x n \/dev\/mapper\/target                             # re-lock the physical volume (may be redundant) \nmkswap \/dev\/xubuntu-vg\/swap                                  # make the new 4GB volume a swap volume. Copy the UUID to the clipboard. \nlvdisplay                                                    # Use 'lvdisplay' to check our new volumes look good. \nlsblk                                                        # final sanity check \nshutdown -h now                                              # we are done with the Live CD<\/pre><br \/>\n<br \/>\n<li>Edit the target machine to disconnect the CDROM at startup.<\/li><br \/>\n<li>Start the target machine and check all changes work as intended.<\/li><br \/>\n<br \/>\n<strong>References Used<\/strong><br \/>\n<br \/>\n<a href=\"https:\/\/linux.die.net\/man\/8\/lvcreate\">https:\/\/linux.die.net\/man\/8\/lvcreate <\/a><br \/>\n<a href=\"http:\/\/www.systemadminihater.com\/linux\/split-a-lvm2-volume-group-into-two-or-more\/\">http:\/\/www.systemadminihater.com\/linux\/split-a-lvm2-volume-group-into-two-or-more\/ <\/a><br \/>\n<a href=\"http:\/\/www.thegeekstuff.com\/2010\/08\/how-to-create-lvm\">http:\/\/www.thegeekstuff.com\/2010\/08\/how-to-create-lvm<\/a><br \/>\n<a href=\"https:\/\/linux.die.net\/man\/8\/lvresize\">https:\/\/linux.die.net\/man\/8\/lvresize<\/a><br \/>\n<a href=\"http:\/\/tldp.org\/HOWTO\/LVM-HOWTO\/removelv.html\">http:\/\/tldp.org\/HOWTO\/LVM-HOWTO\/removelv.html<\/a><br \/>\n<a href=\"https:\/\/help.ubuntu.com\/community\/ResizeEncryptedPartitions\">https:\/\/help.ubuntu.com\/community\/ResizeEncryptedPartitions<\/a><br \/>\n<a href=\"http:\/\/askubuntu.com\/questions\/63594\/mount-encrypted-volumes-from-command-line\"> http:\/\/askubuntu.com\/questions\/63594\/mount-encrypted-volumes-from-command-line<\/a>","protected":false},"excerpt":{"rendered":"<p>In these examples we will expand the entire disk from 32GB to 64GB. The examples given are with and without an existing swap volume and will use an Ubuntu Live CD ISO as the surrogate. Shutdown the target machine. In VMware Player, select the target and go to &#8216;Edit virtual machine settings&#8217;. Select the &#8216;Hard &#8230; <a title=\"How To Resize An Encrypted Drive\" class=\"read-more\" href=\"https:\/\/robertrath.com\/gadgetzone\/archives\/34-how-to-resize-an-encrypted-drive.html\" aria-label=\"Read more about How To Resize An Encrypted Drive\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/robertrath.com\/gadgetzone\/wp-json\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/robertrath.com\/gadgetzone\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robertrath.com\/gadgetzone\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robertrath.com\/gadgetzone\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/robertrath.com\/gadgetzone\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":0,"href":"https:\/\/robertrath.com\/gadgetzone\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"wp:attachment":[{"href":"https:\/\/robertrath.com\/gadgetzone\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robertrath.com\/gadgetzone\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robertrath.com\/gadgetzone\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}