Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My embedded Linux device have 2 partitions:

  • small root partition containing OS
  • big data partition which uses ext3

I want to encrypt the data partition by using an encrypted file system. I don't want to lose any data on the partition. The size of the root partition is too small to hold all data of the data partition. It is not possible to use any external data storage.

Are there any tools that can convert the file system of the data partition from ext3 to an encrypted FS without copying all files to another place?

share|improve this question
up vote 2 down vote accepted

It is possible, but be warned: your data is toast if anything goes wrong. I strongly suggest finding some way to back up first.

Since you can't use external data storage, you have to do it in place.

This assumes the data in your data partition can fit in half the current space.

  1. Resize and move the data partition to half its current size at the end of the disk.
  2. In the newly-created free space, create a new encrypted LUKS volume, and create a new filesystem inside it.
  3. Copy all files from the old partition to the new one, then delete the old partition.
  4. Resize the encrypted volume (based on the instructions here):

    Show the size of your crypt with cryptsetup.

    sudo cryptsetup status crypt1

    This shows the size of your crypt in sectors.

    Make note of the offset

    offset: 2056 sectors

    Resize with cryptsetup.

    sudo cryptsetup -o 2056 -b 11800000 resize crypt1

    -o = offset (get this from the status command) -b = size in sectors.

  5. Finally, resize the filesystem contained in the encrypted volume to the full size. If you used ext3/4, sudo resize2fs /the/partition should suffice.

If your data takes up more than half the space, you can adapt this procedure by starting with a smaller encrypted partition, and resizing and copying some of the files several times. Obviously more laborious.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .