23 mai 2008

Changement de disque LVM2 + Crypto et migration des données

Tags : , ,

posté dans Configuration |

Oh ! Le beau titre. Le disque dur de mon beau x31 montrait des faibles depuis quelques temps déjà. Le démon smartd m'informait régulièrement qu'un secteur défectueux avait été trouvé. On le sait tous, ça commence par un secteur et un beau jour on fini par perdre tout le disque. Il fallait réagir. Mais le disque est chiffré avec LUKS et LVM2. Comment migrer tout cela ? Procédure pas-à-pas...Comme détaillé dans un précédent billet, le démontage du disque et sa lecture une fois connecté sur une autre machine via USB n'est pas un problème.

Ouverture du disque chiffré

% cryptsetup luksOpen /dev/sde5 plop
Enter LUKS passphrase:
key slot 0 unlocked.
Command successful.

Recherche des informations LVM2

% pvscan
PV /dev/dm-1   VG x31   lvm2 [37.02 GB / 0    free]
Total: 1 [37.02 GB] / in use: 1 [37.02 GB] / in no VG: 0 [0   ]

% vgscan
Reading all physical volumes.  This may take a while...
Found volume group "x31" using metadata type lvm2

% lvscan
inactive          '/dev/x31/root' [35.46 GB] inherit
inactive          '/dev/x31/swap_1' [1.56 GB] inherit

% lvs
LV     VG   Attr   LSize  Origin Snap%  Move Log Copy%  Convert
root   x31  -wi--- 35.46G
swap_1 x31  -wi---  1.56G

Activation des volumes logiques pour accès depuis /dev/x31/*

% vgchange -a y x31
2 logical volume(s) in volume group "x31" now active
% ls /dev/x31/
root  swap_1

Montage des FS (/ chiffré et /boot classique)

% mount -oro /dev/x31/root /mnt/X/root
% mount -oro /dev/sde1 /mnt/X/boot

Copie des données

% mkdir /mnt/mega20/x31/root
% mkdir /mnt/mega20/x31/boot

% cd /mnt/X/boot
% find . -xdev | cpio -pm /mnt/mega20/x31/boot

% cd /mnt/X/root
% find . -xdev | cpio -pm /mnt/mega20/x31/root

Démontage, désactivation LVM et fermeture LUKS

% umount /mnt/X/root
% umount /mnt/X/boot

% vgchange -a n x31
  0 logical volume(s) in volume group "x31" now active

% cryptsetup luksClose plop

 

 

Nouveau disque

Partitionnement

% fdisk /dev/sde
Command (m for help): p

Disk /dev/sde: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1        9729    78148161    b  W95 FAT32

Command (m for help): d
Selected partition 1

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-9729, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-9729, default 9729): 31

Command (m for help): p

Disk /dev/sde: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1          31      248976   83  Linux

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (32-9729, default 32):
Using default value 32
Last cylinder or +size or +sizeM or +sizeK (32-9729, default 9729):
Using default value 9729

Command (m for help): p

Disk /dev/sde: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1          31      248976   83  Linux
/dev/sde2              32        9729    77899185    5  Extended

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (32-9729, default 32):
Using default value 32
Last cylinder or +size or +sizeM or +sizeK (32-9729, default 9729):
Using default value 9729

Command (m for help): p

Disk /dev/sde: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1          31      248976   83  Linux
/dev/sde2              32        9729    77899185    5  Extended
/dev/sde5              32        9729    77899153+  83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Création FS pour /boot, montage et copie

% mke2fs /dev/sde1
% mount /dev/sde1 /mnt/X/boot/
% cd /mnt/mega20/x31/boot
% find . -xdev | cpio -pm /mnt/X/boot

Création LUKS

% cryptsetup --verbose --verify-passphrase luksFormat /dev/sde5
WARNING!
========
This will overwrite data on /dev/sde5 irrevocably.
Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase:
Verify passphrase:
Command successful.

Ouverture LUKS

% cryptsetup luksOpen /dev/sde5 plop
Enter LUKS passphrase:
key slot 0 unlocked.
Command successful.

Création du volume physique

% pvcreate /dev/mapper/plop
  Physical volume "/dev/mapper/plop" successfully created

Création du groupe x31

% vgcreate x31 /dev/mapper/plop
  Volume group "x31" successfully created

% pvscan
  PV /dev/mapper/plop   VG x31   lvm2 [74,29 GB / 74,29 GB free]
  Total: 1 [74,29 GB] / in use: 1 [74,29 GB] / in no VG: 0 [0   ]

Création des volumes logiques

% lvcreate -L 1560M -n swap_1 x31
  Logical volume "swap_1" created
% lvcreate -l 100%FREE -n root x31
  Logical volume "root" created

% lvscan
  ACTIVE            '/dev/x31/swap_1' [1,52 GB] inherit
  ACTIVE            '/dev/x31/root' [72,77 GB] inherit

Les volumes sont automatiquement actifs. Création du SWAP

% mkswap /dev/x31/swap_1
Setting up swapspace version 1, size = 1635774 kB
no label, UUID=989ba8ea-aab4-4b81-af31-06112abc66e1

Création FS racine et copie

% mke2fs -j /dev/x31/root
% mount /dev/mapper/x31-root /mnt/X/root/

% cd /mnt/mega20/x31/root
% find . -xdev | cpio -pm /mnt/X/root

Démontage, désactivation et fermeture LUKS

% umount /mnt/X/root
% umount /mnt/X/boot

% vgchange -a n x31
  0 logical volume(s) in volume group "x31" now active

% cryptsetup luksClose plop

 

Bootloader Grub

On install GRUB sur le disque USB hd2. stage2 est pointé sur hd2 mais par défaut il est cherché sur le même disque que stage1 (secteur de boot). menu.lst est bien pointé sur le futur hd0 seul disque du lappy

% grub
grub> install (hd2,0)/grub/stage1 (hd2) (hd2,0)/grub/stage2 (hd0,0)/grub/menu/lst
^D
Article posté on Vendredi, 23 mai 2008 à 20:29 dans Configuration. Vous pouvez suivre les commentaires sur cet article via un feed RSS 2.0. Vous pouvez laisser un commentaire. Le Ping n'est actuellement pas autorisé.

Il y a actuellement 2 réponses pour “Changement de disque LVM2 + Crypto et migration des données”

  1. 1 Le 24 mai 2008, FRLinux à écrit :

    Salut, etant utilisateur convaincu de rsync et dump/restore plus anciennement. Je me demandais l’avantage de cpio ?

    Merci :)
    Steph

  2. 2 Le 26 mai 2008, Lefinnois à écrit :

    L’avantage ? Heuuu… réflexe de vieil utilisateur Unix :)

Laisser un commentaire

*
Pour prouver que vous n'êtes pas un bot, recopiez le code ci-dessous
Anti-Spam Image