Tuesday, April 8, 2014

Quick how to: extend a linux encrypted partition



You have a linux virtual machine with an encrypted hard drive. How to quickly extend it ?


Environment (this method may apply to other environments):
  • Virtualization type: 
    • VMWare ESX
  • Linux:
    • RHEL 5.7
    • using main root partition as an LVM encrypted with LUKS
      / in /dev/sda2
    • using a boot partition /boot in /dev/sda1

Quick method:
  • give more space from VMWare
    •  edit settings / Hardware / Hard Disk / change the value in "provisioned size"
      (it is usually grayed out when you already have a snapshot)
    • create a snapshot (to roll back in case of problem)
  • boot a live CD
    • from VMWare, Edit Settings / CD DVD adapter / load ISO (I used a debian7 cd image) + connected at poweron
    • edit bios setting to boot on cd
    • Boot on virtual CD: for my Debian 7, I booted in ExpertMode / Rescue Disk 
  • From the live cd console
    • extend physical parition
      fdisk /dev/sda
      sequence is: d 2 n p 2 t 2 8e w

      (sequence meaning: delete partition2, new partiiton primary, number2, change type of parititon2 to LVM (8e) )
    • Open CRYPT
      cryptsetup luksOpen /dev/sda2 crypt1
    • extend  CRYPT:
      cryptsetup resize crypt1
    • entend PV:
      pvdisplay /dev/mapper/crypt1
      pvresize /dev/mapper/crypt1
      pvdisplay /dev/mapper/crypt1
    • entend LV:
      lvdisplpay
      lvresize -L +30G /dev/VolGroup00/LogVol00
      lvdisplay
  • reboot your server as usual
    • extend filesystem:
      resize2fs  -p /dev/mapper/VolGroup00-LogVol00
    • check new available size:
      df -h
That's it

Notes:
this is a quick (and dirty) how to.
It does not cover good practice like writing random data in the disk space we merge with our LUKS partition. It uses a live cd to avoid lock and root unmount problems.
I hope it will be useful for some readers ! Comments welcome





No comments:

Post a Comment