Archive for the ‘Système’ Category

RAID over LVM2

Mardi, juin 30th, 2009

Voici plusieurs semaines que je voulais sécuriser mon serveur eBox. Une des solutions consiste à migrer le seul disque de 80Go sur deux disques de 500Go en RAID1 soft. LVM2 sera utilisé pour gérer au mieux et avec plus de souplesse les différentes partitions.

Voici donc en détail la procédure à suivre avec quelques commandes basiques mais très utiles pour contrôler le système RAID et LVM2 :

Connexion  sur le serveur eBox

ssh utilisateur@ipduserveur
utilisateur@ipduserveur’s password:

Liste des disques et partitions

utilisateur@ebox38-srv:~$sudo -s

root@ebox38-srv:~$ df -h

/dev/sda1              73G   31G   40G  44% /
varrun               1014M  272K 1013M   1% /var/run
varlock              1014M     0 1014M   0% /var/lock
devshm               1014M     0 1014M   0% /dev/shm

root@ebox38-srv:~# fdisk -l /dev/sda

Disk /dev/sda: 82.3 GB, 82348277760 bytes
255 heads, 63 sectors/track, 10011 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xb115d3e5
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        9598    77095903+  83  Linux
/dev/sda2            9599       10011     3317422+   5  Extended
/dev/sda5            9599       10011     3317391   82  Linux swap / Solaris

root@ebox38-srv:~# fdisk -l /dev/sdb

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Disk identifier: 0x0004e881
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          13      104391   fd  Linux raid autodetect
/dev/sdb2              14       60801   488279610   fd  Linux raid autodetect

Installation des outils

root@ebox38-srv:~# apt-get install lvm2 mdadm

Partitionnement du disque cible

root@ebox38-srv:~# fdisk /dev/sdb
suppression des partition 1 et 2 (commande « d »)
creation de la partition 1 (commande « n », Start 1, End 32)
partition en raid linux autodetect (commande « t », fd)

creation de la partition 2 (commande « n », Start 33 End 59584)
partition en raid linux autodetect (commande « t », fd)

écriture de la table de partition (commande « w »)

Création du RAID

root@ebox38-srv:~# mdadm –zero-superblock /dev/sdb1
mdadm: Unrecognised md component device – /dev/sdb1
root@ebox38-srv:~# mdadm –zero-superblock /dev/sdb2
mdadm: Unrecognised md component device – /dev/sdb2

root@ebox38-srv:~# mdadm –create /dev/md0 –level=1 –raid-devices=2 /dev/sdb1 missing

mdadm: /dev/sdb1 appears to contain an ext2fs file system
    size=104320K  mtime=Sat Apr 25 12:44:43 2009
Continue creating array? Y
mdadm: array /dev/md0 started.

root@ebox38-srv:~# mdadm –create /dev/md1 –level=1 –raid-devices=2 /dev/sdb2 missing
mdadm: array /dev/md1 started.

root@ebox38-srv:~# cat /proc/mdstat

Personalities : [raid1]
md1 : active raid1 sdb2[0]
      478351360 blocks [2/1] [U_]
md0 : active raid1 sdb1[0]
      256896 blocks [2/1] [U_]
unused devices: <none>

root@ebox38-srv:~# dpkg-reconfigure mdadm
* Stopping MD monitoring service mdadm –monitor                                                                                                               [ OK ]
Removing any system startup links for /etc/init.d/mdadm-raid …
update-initramfs: Generating /boot/initrd.img-2.6.24-23-server
* Starting MD monitoring service mdadm –monitor                                                                                                               [ OK ]
root@ebox38-srv:~# cp /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf_orig

root@ebox38-srv:~# /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf

Mise en place de LVM

root@ebox38-srv:~# modprobe dm-mod
root@ebox38-srv:~# lvcreate -n root -L 20G vg00

Logical volume « root » created
root@ebox38-srv:~# lvcreate -n swap -L 4G vg00
Logical volume « swap » created
root@ebox38-srv:~# lvcreate -n home -L 200G vg00
Logical volume « home » created

root@ebox38-srv:~# vgchange -a y vg00
3 logical volume(s) in volume group « vg00″ now active

Formatage des systèmes de fichiers

root@ebox38-srv:~# mkfs.ext3 -L boot /dev/md0
root@ebox38-srv:~# mkfs.ext3 -L root /dev/vg00/root
root@ebox38-srv:~# mkfs.ext3 -L home /dev/vg00/home
root@ebox38-srv:~# mkfs.ext3 -L home /dev/vg00/home
root@ebox38-srv:~# mkswap -L swap /dev/vg00/swap

Récapitulatif

root@ebox38-srv:~# vgdisplay -v vg00

    Using volume group(s) on command line
    Finding volume group "vg00"
  --- Volume group ---
  VG Name               vg00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               456,19 GB
  PE Size               4,00 MB
  Total PE              116784
  Alloc PE / Size       108544 / 424,00 GB
  Free  PE / Size       8240 / 32,19 GB
  VG UUID               CVAS3j-XtB9-iVr6-jsv9-fCpD-mgNH-W1clin
  --- Logical volume ---
  LV Name                /dev/vg00/root
  VG Name                vg00
  LV UUID                zJiPSq-rbBj-LM0i-mIGx-eLX1-8s1V-eQB6CJ
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                20,00 GB
  Current LE             5120
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           254:0
  --- Logical volume ---
  LV Name                /dev/vg00/swap
  VG Name                vg00
  LV UUID                mMD04d-anWo-c8NJ-XH4B-zrTs-9Xjf-2tuq5j
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                4,00 GB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           254:1
  --- Logical volume ---
  LV Name                /dev/vg00/home
  VG Name                vg00
  LV UUID                mp1Yvo-ioeb-aoVh-0U7u-lohA-VppQ-jlergI
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                200,00 GB
  Current LE             102400
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           254:2
 --- Physical volumes ---
  PV Name               /dev/md1
  PV UUID               Uo3xMT-AbC2-dhjV-m9Aa-JAQv-y6Vp-gz7Yjk
  PV Status             allocatable
  Total PE / Free PE    116784 / 8240

root@ebox38-srv:~# pvs

  PV         VG   Fmt  Attr PSize   PFree
  /dev/md1   vg00 lvm2 a-   456,19G 232,19G

root@ebox38-srv:~# vgs

  VG   #PV #LV #SN Attr   VSize   VFree
  vg00   1   3   0 wz--n- 456,19G 232,19G

root@ebox38-srv:~# lvs

  LV   VG   Attr   LSize   Origin Snap%  Move Log Copy%
  home vg00 -wi-a- 200,00G
  root vg00 -wi-a-  20,00G
  swap vg00 -wi-a-   4,00G

Préparation du futur /etc/fstab

root@ebox38-srv:~# cd /dev/vg00/
root@ebox38-srv:/dev/vg00# ls -l

total 0
lrwxrwxrwx 1 root root 21 2009-06-28 12:15 home -> /dev/mapper/vg00-home
lrwxrwxrwx 1 root root 21 2009-06-28 12:15 root -> /dev/mapper/vg00-root
lrwxrwxrwx 1 root root 21 2009-06-28 12:15 swap -> /dev/mapper/vg00-swap

root@ebox38-srv:/dev/vg00# vi /etc/fstab.new

# /etc/fstab: static file system information.
#
# <file system>       <mount point>   <type>       <options>                  <dump>  <pass>
proc                  /proc           proc         defaults                   0       0
# root
/dev/mapper/vg00-root /               ext3         defaults,errors=remount-ro 0       1
# swap
/dev/mapper/vg00-swap none            swap         sw                         0       0
# boot
/dev/md0              /boot           ext3         defaults                   0       2
# home
/dev/mapper/vg00-home /home           ext3         defaults                   0       2
/dev/scd0             /media/cdrom0   udf,iso9660  user,noauto,exec,utf8      0       0
/dev/fd0              /media/floppy0  auto         rw,user,noauto,exec,utf8   0       0

Copie des fichiers

# A suivre…