mercredi 11 septembre 2013

[draft][being rectified] My (quite) Perfect Server (NAS, HTPC) - Partitioning


In this article by mediacenter I mean the computer I use as server/NAS/HTPC.
I'm french and, as you probably know, we are bad english speaker, do with it :-p.

Hardware & Software

The mediacenter is base on an Asus P5N7A-VM (with an IGP GeForce 9300) and a Core 2 Duo E8400.
Data is stored on a 1TB HDD (sata II).
I'm using Arch linux and I will made a clean reinstall of it with RAID mirror and striping and LVM.

Current state and upgrade

The past installation was based on LVM2 with only 2 partitions rootfs and /home. There was an old (and unused) partition outside of LVM, used as BOOT partition before upgrade to Grub2.
I added a second 1TB HDD, made RAID 0 for rootfs and swap partitions and RAID 1 for /home.
The problem I had, was to create the RAID arrays, moving data without lost. By the way I will explain which software I installed for a fully fonctionnal medaicenter.
The mediacenter is connected by HDMI cable to a TV, so on the top of the system there is XBMC running, with few other services.
Installation is mostly taken from Arch wiki (really thank to them), but modified to my convenience.

Before Starting

Maybe you can do it without any live support to boot up. But when I started the installation, I wasn't sure that an incomplete RAID array could be usable. The simplest way is to download any Arch linux ISO and type a simple :
# dd if=XXXXXX.iso of=/dev/sdX bs=8M
where sdX is your USB device. Now restart and boot on the USB key.


Now I have 2 disks, sda and sdb. sda is the previous installed disk, so it is this one which contains data, sdb is newly installed drive.
It is recommended to make a full erase of the HDD before including it on a RAID array. I used shred to do it, be patient it takes about 20 hours for 1TB.
# shred --verbose --random-source=/dev/urandom -n 1 /dev/sdb

According to Arch GPT is recommended over MBR, so I partitioned the disdk with gdisk available in the package gptfdisk. But with Grub + GPT, you need an extra partition of type BIOS boot partition to store grub data, and I need another extra partition for boot because grub don't like RAID 0 (it could be done on the RAID 1, but I didn't try yet).
I planned to have 20GB for rootfs and 3GB for swap, the remaining space will be used for data.
# gdisk /dev/sdb
: o // create a new empty GUID partition table (GPT)

: n // add a new partition
: [ENTER] // partition number
: [ENTER] // first sector
: +11776M // last sector => 11.5GB -> (20 + 3) / 2
: fd00 // partition type 'Linux RAID'

: n
: +900G // data will be mirrored
: fd00

: n // /boot partition
: +200M
: 8300

Now we can start creating RAID arrays. The trick is to force the creation of arrays containing only 1 disk, copying data, and finish assembling arrays.
I don't know why, but it was impossible for me to create the RAID 0 with 1 disk and then append another disk to it. So the RAID 0 will be created with the 2 disks at once.
# mdadm --create --verbose --level=1 --metadata=1.2 --raid-devices=1 --force /dev/md1 /dev/sdb2
Don't forget the --force option, because mdadm doesn't like RAID with just 1 device (--raid-devices=1).
Now we have the /dev/md0 device which is a RAID 1 array with just 1 disk.
It's time to deal with LVM:
# pvcreate /dev/md1
# vgcreate vg /dev/md1
# lvcreate -L 800G vg -n home /dev/md1
# mkfs.ext4 -L HOME /dev/vg/home
# mkdir /media/{old,new}
# mount /dev/vg/home /media/new
# mount /dev/xxx/home /media/old // I don't remember the old VG name
# cp -r /media/old/* /media/new // or select what you want

Appening /dev/md0 force this logical volume to be located on this particular physical volume. The goal is to have 1 volume group over the 2 physicals volumes (2 RAID arrays), containing every partition. But /home has to be located on the RAID 1, like rootfs and swap on the RAID 0.

It's time to complete partitioning and then the installation.
# umount /media/{old,new}
# shred --verbose --random-source=/dev/urandom -n 1 /dev/sda
// remember it takes ~20 hours
# gdisk /dev/sda
: o // create a new empty GUID partition table (GPT)

: n // add a new partition
: [ENTER] // partition number
: [ENTER] // first sector
: +11776M // last sector => 11.5GB -> (20 + 3) / 2
: fd00 // partition type 'Linux RAID'

: n
: +900G // data will be mirrored
: fd00

: n // grub needed partition, 2M is enough
: 24
: ef02
Extend the RAID 1 array.
# mdadm --add /dev/md1 /dev/sda2 // add sda2 as spare disk on RAID 1
# mdadm --misc --detail /dev/md1 // to see detailed information
# mdadm --grow -n 2 /dev/md1
The last operation takes time (few hours) you can see the status by looking into /proc/mdstat file. To avoid unecessary errors (I tried myself, it's not a good idea) wait for the end of the synchronisation.
# mdadm --create --verbose --level=0 --metadata=1.2 --raid-devices=2 /dev/md0 /dev/sda1 /dev/sdb1
# pvcreate /dev/md0
# vgextend vg /dev/md0
# lvcreate -L 20G vg -n rootfs /dev/md0
# mkfs.ext4 -L ROOT /dev/vg/rootfs
# lvcreate -L 3G vg -n swap /dev/md0
# mkswap -L SWAP /dev/vg/swap


Aucun commentaire:

Enregistrer un commentaire