MRW
http://piratenpartei.ch

Piratenpartei Zürich
PC 85-112704-0

Der Politnetz Auftritt von Marc Wäckerlin Im Politnetz unterstützen

Add New Harddisk To Encrypted Logical Volume

I have a HP ProLiant N36L, which offers 4 slots for harddisk. I bought it with the built in 250G Harddisk and an additional 2TB drive (I strongly recommend special 7dx24h server harddisk for servers that are alwys up; cheaper harddisks crash after a year).

I set it up with a 500MB /boot partition (formatted with ext2, then I merged the remaining space /dev/sda2 of the 250GB harddisk with the full second 2TB harddisk /dev/sdb1 using the logical volume manager LVM2. The I encrypted thus huge logical volume with dmcrypt and formatted with xfs. I configured this in the installer of the Ubuntu alternate-, respectively server installer.

Then I had to add a next 2TB disk. Of course, I want to do this without destroying the data; not because I have no backup, but because restoring 2TB of lasts days. My shock was, other than during installation, there's no LVM2-GUI that prevents me from hacking into the command line. So I had to find out the commands to manually add the space of the new disk. It was quite simple.

  1. Add new Harddisk: First, shut down the system (if it does not support hotplugging), turn out the computer and add the new disk, then restart.
    Here it is the third disk, so it's /dev/sdc. After boot, login as root and start …
  2. Use fdisk to init partition table and setup a primary partition /dev/sdc1 with id 8e
  3. Create physical volume: pvcreate /dev/sdc1
  4. Look for the name of the volume group with vgdisplay; in my case, it's named big
  5. Extend the volume group by the new harddisk: vgextend big /dev/sdc1
  6. Look for the name of the logical volume within the volume group with lvdisplay; in my case, it's also named big
  7. Extend the logical volume by the new harddisk: lvextend /dev/big/big /dev/sdc1
  8. Get the name of the mounted encrypted filesystem in /dev/mapper by calling mount; in my case, it's /dev/mapper/big-big_crypt
  9. Resize the encrypted filesystem to the new dimension: cryptsetup resize big-big_crypt
  10. Expand the filesystem, here it's xfs, so I use xfs_growfs, otherwise use resize2fs for ext2, ext3, ext4 or resize_reiserfs for reiserfs.
  11. That's it. resized a running system, no reboot necessary. df -h / now shows that my filesystem now has a bit less than 4TB. Before, it was a bit less than 2TB (yes, a «2TB» harddisk is much smaller than 2TB, that's part of the day-to-day ceating).