Extend a LUKS encrypted partition to fill disk











up vote
12
down vote

favorite
11












I recently upgraded my disk from a 128GB SSD to 512GB SSD. The / partition is encrypted with LUKS. I'm looking for help extending the partition to use all the free space on the new disk. I've already dd'd the old drive onto the new one:



[root@localhost ~]# fdisk -l /dev/sda
Disk /dev/sda: 477 GiB, 512110190592 bytes, 1000215216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x00009f33

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 1026047 1024000 500M 83 Linux
/dev/sda2 1026048 250064895 249038848 118.8G 83 Linux


There's about 380GB of unused space after sda2.



More relevant info:



[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
fedora_chocbar 1 3 0 wz--n- 118.75g 4.00m

[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home fedora_chocbar -wi-a----- 85.55g
root fedora_chocbar -wi-a----- 29.30g
swap fedora_chocbar -wi-a----- 3.89g

[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/mapper/encrypted fedora_chocbar lvm2 a-- 118.75g 4.00m


There seems to be a lot of info regarding how to do this, but very little explanation. I appreciate any help on this.










share|improve this question


























    up vote
    12
    down vote

    favorite
    11












    I recently upgraded my disk from a 128GB SSD to 512GB SSD. The / partition is encrypted with LUKS. I'm looking for help extending the partition to use all the free space on the new disk. I've already dd'd the old drive onto the new one:



    [root@localhost ~]# fdisk -l /dev/sda
    Disk /dev/sda: 477 GiB, 512110190592 bytes, 1000215216 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disklabel type: dos
    Disk identifier: 0x00009f33

    Device Boot Start End Sectors Size Id Type
    /dev/sda1 * 2048 1026047 1024000 500M 83 Linux
    /dev/sda2 1026048 250064895 249038848 118.8G 83 Linux


    There's about 380GB of unused space after sda2.



    More relevant info:



    [root@localhost ~]# vgs
    VG #PV #LV #SN Attr VSize VFree
    fedora_chocbar 1 3 0 wz--n- 118.75g 4.00m

    [root@localhost ~]# lvs
    LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
    home fedora_chocbar -wi-a----- 85.55g
    root fedora_chocbar -wi-a----- 29.30g
    swap fedora_chocbar -wi-a----- 3.89g

    [root@localhost ~]# pvs
    PV VG Fmt Attr PSize PFree
    /dev/mapper/encrypted fedora_chocbar lvm2 a-- 118.75g 4.00m


    There seems to be a lot of info regarding how to do this, but very little explanation. I appreciate any help on this.










    share|improve this question
























      up vote
      12
      down vote

      favorite
      11









      up vote
      12
      down vote

      favorite
      11






      11





      I recently upgraded my disk from a 128GB SSD to 512GB SSD. The / partition is encrypted with LUKS. I'm looking for help extending the partition to use all the free space on the new disk. I've already dd'd the old drive onto the new one:



      [root@localhost ~]# fdisk -l /dev/sda
      Disk /dev/sda: 477 GiB, 512110190592 bytes, 1000215216 sectors
      Units: sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 4096 bytes
      I/O size (minimum/optimal): 4096 bytes / 4096 bytes
      Disklabel type: dos
      Disk identifier: 0x00009f33

      Device Boot Start End Sectors Size Id Type
      /dev/sda1 * 2048 1026047 1024000 500M 83 Linux
      /dev/sda2 1026048 250064895 249038848 118.8G 83 Linux


      There's about 380GB of unused space after sda2.



      More relevant info:



      [root@localhost ~]# vgs
      VG #PV #LV #SN Attr VSize VFree
      fedora_chocbar 1 3 0 wz--n- 118.75g 4.00m

      [root@localhost ~]# lvs
      LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
      home fedora_chocbar -wi-a----- 85.55g
      root fedora_chocbar -wi-a----- 29.30g
      swap fedora_chocbar -wi-a----- 3.89g

      [root@localhost ~]# pvs
      PV VG Fmt Attr PSize PFree
      /dev/mapper/encrypted fedora_chocbar lvm2 a-- 118.75g 4.00m


      There seems to be a lot of info regarding how to do this, but very little explanation. I appreciate any help on this.










      share|improve this question













      I recently upgraded my disk from a 128GB SSD to 512GB SSD. The / partition is encrypted with LUKS. I'm looking for help extending the partition to use all the free space on the new disk. I've already dd'd the old drive onto the new one:



      [root@localhost ~]# fdisk -l /dev/sda
      Disk /dev/sda: 477 GiB, 512110190592 bytes, 1000215216 sectors
      Units: sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 4096 bytes
      I/O size (minimum/optimal): 4096 bytes / 4096 bytes
      Disklabel type: dos
      Disk identifier: 0x00009f33

      Device Boot Start End Sectors Size Id Type
      /dev/sda1 * 2048 1026047 1024000 500M 83 Linux
      /dev/sda2 1026048 250064895 249038848 118.8G 83 Linux


      There's about 380GB of unused space after sda2.



      More relevant info:



      [root@localhost ~]# vgs
      VG #PV #LV #SN Attr VSize VFree
      fedora_chocbar 1 3 0 wz--n- 118.75g 4.00m

      [root@localhost ~]# lvs
      LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
      home fedora_chocbar -wi-a----- 85.55g
      root fedora_chocbar -wi-a----- 29.30g
      swap fedora_chocbar -wi-a----- 3.89g

      [root@localhost ~]# pvs
      PV VG Fmt Attr PSize PFree
      /dev/mapper/encrypted fedora_chocbar lvm2 a-- 118.75g 4.00m


      There seems to be a lot of info regarding how to do this, but very little explanation. I appreciate any help on this.







      filesystems luks






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 4 '16 at 4:08









      NisplayDame

      351127




      351127






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          19
          down vote













          OK! The definitive answer finally. My steps to expand a LUKS encrypted volume...





          1. cryptsetup luksOpen /dev/sda2 crypt-volume to open the encrypted volume.


          2. parted /dev/sda to extend the partition. resizepart NUMBER END.


          3. vgchange -a n fedora_chocbar. Stop using the VG so you can do the next step.


          4. cryptsetup luksClose crypt-volume. Close the encrypted volume for the next steps.


          5. cryptsetup luksOpen /dev/sda2 crypt-volume. Open it again.


          6. cryptsetup resize crypt-volume. Will automatically resize the LUKS volume to the available space.


          7. vgchange -a y fedora_chocbar. Activate the VG.


          8. pvresize /dev/mapper/crypt-volume. Resize the PV.


          9. lvresize -l+100%FREE /dev/fedora_chocbar/home. Resize the LV for /home to 100% of the free space.


          10. e2fsck -f /dev/mapper/fedora_chocbar-home. Throw some fsck magic at the resized fs.


          11. resize2fs /dev/mapper/fedora_chocbar-home. Resize the filesystem in /home (automatically uses 100% free space)


          I hope someone else finds this useful. I now have 300+GB for my test VMs on my laptop!






          share|improve this answer























          • Thanks, this was very helpful, it should be the accepted answer!
            – springloaded
            Aug 10 '17 at 15:48






          • 1




            The above also worked great for me. I had one step in there, let's call it step 7.5 where I had to unlock my physical volume: sudo pvchange -x y /dev/mapper/crypt-volume (via ubuntu docs help.ubuntu.com/community/ResizeEncryptedPartitions)
            – four43
            Feb 27 at 5:04


















          up vote
          0
          down vote













          Since this appears not to be a LVM specific question I want to mention that I successfully moved and extended one of my LUKS partitions 100GiB forward(!) with GParted on Fedora 28. It could not be done in Ubuntu 18.04 though and every other solution looked like a hassle of dd'ing around or backup and restore (I made a backup anyway). The LUKS container is automatically extended – IIRC GParted informs you about this – the only thing left is to extend the filesystem, so I had to do fsck.ext4 -f and resize2fs in my case.



          A big thank you to the GParted developers.






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f320957%2fextend-a-luks-encrypted-partition-to-fill-disk%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            19
            down vote













            OK! The definitive answer finally. My steps to expand a LUKS encrypted volume...





            1. cryptsetup luksOpen /dev/sda2 crypt-volume to open the encrypted volume.


            2. parted /dev/sda to extend the partition. resizepart NUMBER END.


            3. vgchange -a n fedora_chocbar. Stop using the VG so you can do the next step.


            4. cryptsetup luksClose crypt-volume. Close the encrypted volume for the next steps.


            5. cryptsetup luksOpen /dev/sda2 crypt-volume. Open it again.


            6. cryptsetup resize crypt-volume. Will automatically resize the LUKS volume to the available space.


            7. vgchange -a y fedora_chocbar. Activate the VG.


            8. pvresize /dev/mapper/crypt-volume. Resize the PV.


            9. lvresize -l+100%FREE /dev/fedora_chocbar/home. Resize the LV for /home to 100% of the free space.


            10. e2fsck -f /dev/mapper/fedora_chocbar-home. Throw some fsck magic at the resized fs.


            11. resize2fs /dev/mapper/fedora_chocbar-home. Resize the filesystem in /home (automatically uses 100% free space)


            I hope someone else finds this useful. I now have 300+GB for my test VMs on my laptop!






            share|improve this answer























            • Thanks, this was very helpful, it should be the accepted answer!
              – springloaded
              Aug 10 '17 at 15:48






            • 1




              The above also worked great for me. I had one step in there, let's call it step 7.5 where I had to unlock my physical volume: sudo pvchange -x y /dev/mapper/crypt-volume (via ubuntu docs help.ubuntu.com/community/ResizeEncryptedPartitions)
              – four43
              Feb 27 at 5:04















            up vote
            19
            down vote













            OK! The definitive answer finally. My steps to expand a LUKS encrypted volume...





            1. cryptsetup luksOpen /dev/sda2 crypt-volume to open the encrypted volume.


            2. parted /dev/sda to extend the partition. resizepart NUMBER END.


            3. vgchange -a n fedora_chocbar. Stop using the VG so you can do the next step.


            4. cryptsetup luksClose crypt-volume. Close the encrypted volume for the next steps.


            5. cryptsetup luksOpen /dev/sda2 crypt-volume. Open it again.


            6. cryptsetup resize crypt-volume. Will automatically resize the LUKS volume to the available space.


            7. vgchange -a y fedora_chocbar. Activate the VG.


            8. pvresize /dev/mapper/crypt-volume. Resize the PV.


            9. lvresize -l+100%FREE /dev/fedora_chocbar/home. Resize the LV for /home to 100% of the free space.


            10. e2fsck -f /dev/mapper/fedora_chocbar-home. Throw some fsck magic at the resized fs.


            11. resize2fs /dev/mapper/fedora_chocbar-home. Resize the filesystem in /home (automatically uses 100% free space)


            I hope someone else finds this useful. I now have 300+GB for my test VMs on my laptop!






            share|improve this answer























            • Thanks, this was very helpful, it should be the accepted answer!
              – springloaded
              Aug 10 '17 at 15:48






            • 1




              The above also worked great for me. I had one step in there, let's call it step 7.5 where I had to unlock my physical volume: sudo pvchange -x y /dev/mapper/crypt-volume (via ubuntu docs help.ubuntu.com/community/ResizeEncryptedPartitions)
              – four43
              Feb 27 at 5:04













            up vote
            19
            down vote










            up vote
            19
            down vote









            OK! The definitive answer finally. My steps to expand a LUKS encrypted volume...





            1. cryptsetup luksOpen /dev/sda2 crypt-volume to open the encrypted volume.


            2. parted /dev/sda to extend the partition. resizepart NUMBER END.


            3. vgchange -a n fedora_chocbar. Stop using the VG so you can do the next step.


            4. cryptsetup luksClose crypt-volume. Close the encrypted volume for the next steps.


            5. cryptsetup luksOpen /dev/sda2 crypt-volume. Open it again.


            6. cryptsetup resize crypt-volume. Will automatically resize the LUKS volume to the available space.


            7. vgchange -a y fedora_chocbar. Activate the VG.


            8. pvresize /dev/mapper/crypt-volume. Resize the PV.


            9. lvresize -l+100%FREE /dev/fedora_chocbar/home. Resize the LV for /home to 100% of the free space.


            10. e2fsck -f /dev/mapper/fedora_chocbar-home. Throw some fsck magic at the resized fs.


            11. resize2fs /dev/mapper/fedora_chocbar-home. Resize the filesystem in /home (automatically uses 100% free space)


            I hope someone else finds this useful. I now have 300+GB for my test VMs on my laptop!






            share|improve this answer














            OK! The definitive answer finally. My steps to expand a LUKS encrypted volume...





            1. cryptsetup luksOpen /dev/sda2 crypt-volume to open the encrypted volume.


            2. parted /dev/sda to extend the partition. resizepart NUMBER END.


            3. vgchange -a n fedora_chocbar. Stop using the VG so you can do the next step.


            4. cryptsetup luksClose crypt-volume. Close the encrypted volume for the next steps.


            5. cryptsetup luksOpen /dev/sda2 crypt-volume. Open it again.


            6. cryptsetup resize crypt-volume. Will automatically resize the LUKS volume to the available space.


            7. vgchange -a y fedora_chocbar. Activate the VG.


            8. pvresize /dev/mapper/crypt-volume. Resize the PV.


            9. lvresize -l+100%FREE /dev/fedora_chocbar/home. Resize the LV for /home to 100% of the free space.


            10. e2fsck -f /dev/mapper/fedora_chocbar-home. Throw some fsck magic at the resized fs.


            11. resize2fs /dev/mapper/fedora_chocbar-home. Resize the filesystem in /home (automatically uses 100% free space)


            I hope someone else finds this useful. I now have 300+GB for my test VMs on my laptop!







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 11 '16 at 16:31

























            answered Nov 11 '16 at 16:13









            NisplayDame

            351127




            351127












            • Thanks, this was very helpful, it should be the accepted answer!
              – springloaded
              Aug 10 '17 at 15:48






            • 1




              The above also worked great for me. I had one step in there, let's call it step 7.5 where I had to unlock my physical volume: sudo pvchange -x y /dev/mapper/crypt-volume (via ubuntu docs help.ubuntu.com/community/ResizeEncryptedPartitions)
              – four43
              Feb 27 at 5:04


















            • Thanks, this was very helpful, it should be the accepted answer!
              – springloaded
              Aug 10 '17 at 15:48






            • 1




              The above also worked great for me. I had one step in there, let's call it step 7.5 where I had to unlock my physical volume: sudo pvchange -x y /dev/mapper/crypt-volume (via ubuntu docs help.ubuntu.com/community/ResizeEncryptedPartitions)
              – four43
              Feb 27 at 5:04
















            Thanks, this was very helpful, it should be the accepted answer!
            – springloaded
            Aug 10 '17 at 15:48




            Thanks, this was very helpful, it should be the accepted answer!
            – springloaded
            Aug 10 '17 at 15:48




            1




            1




            The above also worked great for me. I had one step in there, let's call it step 7.5 where I had to unlock my physical volume: sudo pvchange -x y /dev/mapper/crypt-volume (via ubuntu docs help.ubuntu.com/community/ResizeEncryptedPartitions)
            – four43
            Feb 27 at 5:04




            The above also worked great for me. I had one step in there, let's call it step 7.5 where I had to unlock my physical volume: sudo pvchange -x y /dev/mapper/crypt-volume (via ubuntu docs help.ubuntu.com/community/ResizeEncryptedPartitions)
            – four43
            Feb 27 at 5:04












            up vote
            0
            down vote













            Since this appears not to be a LVM specific question I want to mention that I successfully moved and extended one of my LUKS partitions 100GiB forward(!) with GParted on Fedora 28. It could not be done in Ubuntu 18.04 though and every other solution looked like a hassle of dd'ing around or backup and restore (I made a backup anyway). The LUKS container is automatically extended – IIRC GParted informs you about this – the only thing left is to extend the filesystem, so I had to do fsck.ext4 -f and resize2fs in my case.



            A big thank you to the GParted developers.






            share|improve this answer

























              up vote
              0
              down vote













              Since this appears not to be a LVM specific question I want to mention that I successfully moved and extended one of my LUKS partitions 100GiB forward(!) with GParted on Fedora 28. It could not be done in Ubuntu 18.04 though and every other solution looked like a hassle of dd'ing around or backup and restore (I made a backup anyway). The LUKS container is automatically extended – IIRC GParted informs you about this – the only thing left is to extend the filesystem, so I had to do fsck.ext4 -f and resize2fs in my case.



              A big thank you to the GParted developers.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Since this appears not to be a LVM specific question I want to mention that I successfully moved and extended one of my LUKS partitions 100GiB forward(!) with GParted on Fedora 28. It could not be done in Ubuntu 18.04 though and every other solution looked like a hassle of dd'ing around or backup and restore (I made a backup anyway). The LUKS container is automatically extended – IIRC GParted informs you about this – the only thing left is to extend the filesystem, so I had to do fsck.ext4 -f and resize2fs in my case.



                A big thank you to the GParted developers.






                share|improve this answer












                Since this appears not to be a LVM specific question I want to mention that I successfully moved and extended one of my LUKS partitions 100GiB forward(!) with GParted on Fedora 28. It could not be done in Ubuntu 18.04 though and every other solution looked like a hassle of dd'ing around or backup and restore (I made a backup anyway). The LUKS container is automatically extended – IIRC GParted informs you about this – the only thing left is to extend the filesystem, so I had to do fsck.ext4 -f and resize2fs in my case.



                A big thank you to the GParted developers.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jun 24 at 18:29









                LiveWireBT

                3991217




                3991217






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f320957%2fextend-a-luks-encrypted-partition-to-fill-disk%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    サソリ

                    広島県道265号伴広島線

                    Accessing regular linux commands in Huawei's Dopra Linux