Wednesday, April 4, 2012

Aligning partitions, lvm and encrypted volumes on SSD

The disk: OCZ Vertex3 120GB
The goals:
  • partition disk with GPT
  • prepare disk to host multiple Linux-es (multiboot)
  • setup an LVM
  • make a few encrypted logical volumes
  • make the whole stack work fast, namely align all :)
The tool: sysresccd (on USB stick)

The main idea is to make sure every layer aligns to SSD erase block.
If there is any error on any level the whole work is probably wasted. I'm not an expert, so, I can be wrong :)

Erase block size is probably 2 MiB. The post on forum states 2 MB, but I assume they actually mean 2 MiB. This is very important number. Every step must take it into account. As extra caution measure I would align everything to 4 MiB.

1. Creating GPT partition table
Warning! This destroys all data on the drive!
Boot from our sysresccd, and load gui.
Start GRparted.
Device > Create Partition table... > Advanced > select "gpt" > Apply

2. Creating aligned partitions
We are still using GParted.
2.1. Unallocated space at the beginning of the drive. The purpose of this space is to hold partition table. I'm giving it 8 MiB (dividable by 4 MiB). To create such space you need to create the first partition which starts at 8 MiB. I'm not sure if this step is need, I've read different opinions about this. But I don't worry too much about this, it's just 8 MiB after all :)
2.2. Bios boot partition. 32 MiB (dividable by 4 MiB), fat32, flagged as "bios_grub" (this is important). Wikipedia article states a few MiBs should be fine, but Sabayon howto recommends 32MiB. I'm not greedy, so I choose the latter. Again, it must be flagged as "bios_grub". It might be good idea to add labels to partitions. I named this one "groob_boot".
2.3. Multiple partitions for /boot volumes of multiple Linux-es (each Linux will have its own /boot). 400 MiB (dividable by 4 MiB), ext2 each. This is where grub2 will put its staff. I'm labeling them like "ubuntu_boot", "sabayon_boot", etc. I created 5 such partitions, which is probably a little bit overkill. But who knows :)

3. Creating physical volumes (which will host my logical volume group)
Physical volume contains metadata  area at the beginning of the volume followed by actual data area. Here it's important to start your data area aligned. So, we use --dataalignment option with value 4m (which is 4 MiB):
pvcreate --dataalignment 4m /dev/sda7
--dataalignment option means that data area will start to a multiple of its value. 
Following command will show you where the data area starts.
pvs -o +pe_start

4. Creating logical volume group
Due to physical volumes were created with  --dataalignment option, we need set physical extent size for volume group. To do so we pass -s option to vgcreate. As you can see I'm passing the same 4 MiB:
vgcreate -s 4m vg_main /dev/sda7

5. Creating logical volumes
Nothing special here. E.g.:
lvcreate -L 10G -n lv_ubuntu_root vg_main

6. Creating encrypted containers
Next we setup an encrypted volume above logical volume. According to this mail the encrypted container also should be aligned. To do so we pass --align-payload option which value is in 512 bytes sectors. To align to 4 MiB we do:
cryptsetup luksFormat --align-payload=8192 /dev/vg_main/lv_ubuntu

7. Creating file systems
The post in OCZ  forum states that tuning ext3 and ext4 "probably won't effect performance". One of benchmarks I've found shows questionable effect from such tuning. Arch wiki page omits the tuning also. So, I'm not using it :)

No comments: