Setting up an encrypted RAID 5 on Ubuntu 10.10

Post migrated from my old site:

Recently I started on configuring an encrypted RAID 5 on Ubuntu 10.10 Server. These were the steps I took:

First, install the required packages:

sudo apt-get install mdadm gddrescue cryptsetup lvm2

I used fdisk to partition each disk as a “Linux raid autodetect” partition.

sudo fdisk /dev/sdb

for each device (in my case /dev/sdb /dev/sdc /dev/sdd and /dev/sde). First use option “n” to add a partition, option “t”to change it to type “fd” and “w” to write the changes to disk.

Next step is to create the RAID5 device:

sudo mdadm /dev/md0 --create -n 4 -l 5 -z 244198584 -c 256 /dev/sd{b..e}1

244198584 is the number of kilobyte of a single disk obtained with:

sudo hdparm -I /dev/sdb

Once it has been created, check its status by

sudo cat /proc/mdstat

and

sudo mdadm --detail /dev/md0

Wait until the status reports that the RAID has been fully build.

Next step is to create a physical volume by:

sudo pvcreate /dev/md0

To create a volume group, use:

sudo vgcreate rawlargevg /dev/md0

To create a logical volume, use:

sudo lvcreate -n rawsharelv -L 732585984k rawlargevg

Obtain the size by using:

sudo vgs --units k

To randomize the disk content use:

sudo ddrescue /dev/urandom /dev/rawlargevg/rawsharelv urandomminglog

This might take a long time, after it is done, start setting up the encrypted volume:

sudo cryptsetup -c aes-cbc-essiv:sha256 -y -s 256 luksFormat /dev/rawlargevg/rawsharelv

Next step is to open it:

sudo cryptsetup luksOpen /dev/rawlargevg/rawsharelv encsharedev

And format it:

sudo mkfs.ext4 -m 0 /dev/mapper/encsharedev

After it is done formatting, create a mounting directory:

sudo mkdir /srv/raid

Now edit the /etc/crypttab file to include:

encsharedev /dev/rawlargevg/rawsharelv none luks

And edit /etc/fstab to include:

/dev/mapper/encsharedev /srv/raid ext4 rw 0 0

Reboot and done you are with setting up your encrypted RAID.

References to pages I used:

Advertisements

Posted on July 12, 2013, in Linux, Technology, Tips and tricks, Tooling, Ubuntu. Bookmark the permalink. Leave a comment.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: