8

I have encrypted my SSD with dm-crypt/LUKS to install an Archlinux in an LVM container. Here's a graph of the structure (it's in French but should be understandable):

1

Now I realised I should have aligned my partitions for better SSD performances (like explained here).

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63      481949      240943+  83  Linux
/dev/sda2          481950   250069679   124793865   83  Linux

My question is: can I (and how) correct the misalignment of my partitions or should I reinstall everything? Knowing that the second partition is encrypted and contains an LVM container.

Karan
  • 57,289

1 Answers1

3

The problem is, that you have to shrink the cryptsetup luks container which is currently not possible (growing is possible, but not shrinking).

So you have to reinstall everything or use a rescue linux from a usb stick and do the following:

  1. backup the content of all your LVs
  2. delete the volumegroup and the logical volumes
  3. delete the cryptsetup container
  4. align the partitions (which means delete the old and create new aligned partitions)
  5. create the cryptsetup container (see the note 1 below)
  6. Create a aligned PV (see note 2 below)
  7. Create the VG
  8. Create all needed LVs
  9. Create your filesystems
  10. Restore your data/system

Note 1: Please remind that you should not at least align your partitions, you should align every container/block device on your ssd or a 4KB Sector hdd.

To correctly align your cryptsetup container for a 4KB sector drive use the following formula:

alignment (512Byte sectors) = (sector size (Byte)) / 512

alignment (512Byte sectors) = (4KB * 1024) / 512 = 8

So you should add the following to your cryptsetup command: --align-payload=8

Note 2: To create a aligned PV you should go sure that the start of the PV's data (pe_start) is aligned on a full 4KB sector width boundary.

Please keep in mind that your physicalextentsize (which you can specify while creating a VG) should be a multiple of your alignment.

So you should add the following to your pvcreate command: --dataalignment 8s

teissler
  • 326