I need to move a LUKS encrypted partition to the end of a harddrive to expand another partition.
Does anyone know how to do this?

Is it possible to do this with other partition editing programs?

Gparted doesnt support LUKS/LVM enter image description here

I wrote up a quick tutorial on how I fixed this: http://matthiaslee.com/moving-a-luks-encrypted-lvm-with-dd-and-sfdisk/

1 Answer 1


The easiest thing would be to create a new partition at the end of the disk and copy the contents of the old partition to the new partition. This is not possible, because your disk is really unfavorably partitioned. A PC partition table can hold only 4 primary partitions. Because of this the fourth primary partition must be at the end of the disk. It was a quite silly idea to put sda4 not at the end of the disk, because it is not possible to add another partition behind sda4.

So the only way is to calculate the beginning and ending of sda4 by hand, delete it, create it new at the end of the disk and move the content into the newly created. But this is a quite risky operation and you should create a full disk image of your hard disk first. In order to create the disk image boot a rescue CD like Knoppix and do something like this

dd if=/dev/sda of=/some/mountpoint/from/sdb bs=512

All other steps should also be done with a rescue CD.

After the backup check the geometry of your hard disk with sfdisk -luS. The output will give you the start and end of each partition. This is an example of my disk:

Disk /dev/sda: 60801 cylinders, 255 heads, 63 sectors/track
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sda1   *        63   1959929    1959867  83  Linux
/dev/sda2       1959930   3919859    1959930  82  Linux swap / Solaris
/dev/sda3       3919860 976768064  972848205   5  Extended
/dev/sda4             0         -          0   0  Empty
/dev/sda5       3919923  19551104   15631182  83  Linux
/dev/sda6      19551168 976768064  957216897  83  Linux

Partition 5 for example starts at sector 3919923 and contains 15631182 sectors. Each sector has 512 bytes. You have to write down the start sector and size of your partition. Be sure to write it down in a way you can read it later. ;-)

After that you can erase sda4 and create a new sda4 at the end of the disk having the same size.

Now you can move the contents of the old sda4 to the new sda4 by the following command:

dd if=/dev/sda of=/dev/sda bs=512 skip=BEGIN_OLD_SDA4 count=SIZE_SDA4 seek=BEGIN_NEW_SDA4

You have to insert the sizes you have written down.

Good luck.

  • I finally got around to doing this. Thanks for the pointers, im writing up a quick tutorial on my website
    – madmaze
    May 31, 2012 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.