Die Standard-Installationsroutinen vieler Hoster bieten auch bei zwei vorhandenen Festplatten nur eine Installation ohne Raid an. Um seine Daten gegen einen Ausfall einer Festplatte zu sichern, ist ein Software-Mirroring der Festplatte zu empfehlen.
In diesem Fall geht es um einen Quad-Core Root-Server mit 2×1 TB Festplattenplatz. Nach einer Standard-Installation mit debian lenny, 64 Bit wurde das System im Rescue-System neu gestartet.
Der Zustand sah nach der Standard-Installation welche die Volumes auf LVM-Basis erstellt folgendermaßen aus:
root@sysresccd /root % lvdisplay
--- Logical volume ---
LV Name /dev/n112h151/root
VG Name n112h151
LV UUID ZPJGaq-t7nv-mwRk-C7ob-H4pi-FMAM-cVzKXE
LV Write Access read/write
LV Status available
# open 0
LV Size 908.66 GB
Current LE 232618
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Name /dev/n112h151/swap_1
VG Name n112h151
LV UUID wr6OXU-wzTp-7BNg-LBhv-oEP4-XVQ6-nxgjI4
LV Write Access read/write
LV Status available
# open 0
LV Size 22.61 GB
Current LE 5787
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
Neben der Umstellung auf Raid wollen wir auch gleich noch die Filesystem-Einteilung verändern, da nur ein großes Root-Filesystem nicht wirklich meinen Anforderungen genügt. Auch ist mir ein Swap-Device mit 24GB einfach viel zu groß, wenn ein Rechner das brauchen täte wäre er vor Langsamkeit kaum noch zu benutzen.
Als erstes legen wir uns mal auf der zweiten Festplatte eine entsprechende Partition an, wo das Software-Raid und dann das LVM-Physical-Volume reinkommt. Dieser spezielle Root-Server hat noch dazu eine WD10EARS und folglich ein Performance-Problem durch die 4k Sektoren, das wir gleich mit lösen (Mittlerweile kommen diese Festplatten nicht mehr zum Einsatz).
fdisk -u /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (63-1953525167, default 63): 64
Last sector, +sectors or +size{K,M,G} (64-1953525167, default 1953525167): +200M
Das war unser zukünftiges /Boot-Filesystem. Nun folgt der Software-Mirror.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First sector (63-1953525167, default 63): 409672
Last sector, +sectors or +size{K,M,G} (409672-1953525167, default 1953525167):
Using default value 1953525167
Command (m for help): p
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x738333c0
Device Boot Start End Blocks Id System
/dev/sdb1 64 409664 204800+ 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2 409672 1953525167 976557748 83 Linux
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)
Command (m for help): p
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x738333c0
Device Boot Start End Blocks Id System
/dev/sdb1 64 409664 204800+ 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2 409672 1953525167 976557748 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Debian mag derzeit ein geraidetes Boot-Filesystem nicht, insofern kopieren wir uns das zwar für den Notfall aber nutzen es nicht im Raid. Nicht vergessen, die Partition zu aktivieren wenn man mal davon booten wollen würde!
Nun legen wir unser Raid-Volume für den lvm Bereich an.
root@sysresccd /root % mdadm --create md0 --chunk=32 --level=1 --force --raid-devices=2 /dev/sdb2 missing
mdadm: array md0 started.
Die Rescue-Installation verhält sich hier ein wenig merkwürdig, gibt sie dem Raid doch einen andere Namen (md127). Schauen wir also nach vorher:
root@sysresccd /root % more /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md127 : active raid1 sdb2[0]
976557632 blocks [2/1] [U_]
unused devices:
Nun legen wir das Filesystem auf der zukünftigen /boot – Kopie an an.
root@sysresccd /root % mkfs.ext2 /dev/sdb1
mke2fs 1.41.9 (22-Aug-2009)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
51200 inodes, 204736 blocks
10236 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
Das Ganze wird nun gemounted und wir kopieren was wir bereits darauf haben. Das aktuelle /boot liegt in unserem Fall auf /dev/sda1, was man mit einem Blick auf die Partitions-Tabelle einfach kontrollieren kann (fdisk /dev/sda).
root@sysresccd /root % mkdir /mnt/newfs
root@sysresccd /root % mount /dev/sdb1 /mnt/newfs
root@sysresccd /root % mkdir /mnt/oldfs
root@sysresccd /root % mount /dev/sda1 /mnt/oldfs
root@sysresccd /root % cd /mnt/oldfs
root@sysresccd /mnt/oldfs % find . -print | cpio -o | (cd /mnt/newfs; cpio -idm)
21045 blocks
21045 blocks
root@sysresccd /mnt/oldfs % cd ..
root@sysresccd /mnt % umount /mnt/oldfs
root@sysresccd /mnt % umount /mnt/newfs
Nun legen wir das neue Physical Volume an, welches die FIlesystem später halten soll. Danach legen wir auch gleich eine neue Volume group (newVG) drauf.
root@sysresccd /mnt % pvcreate /dev/md127
Physical volume "/dev/md127" successfully created
root@sysresccd /mnt % vgcreate newVG /dev/md127
Volume group "newVG" successfully created
Das alte Swap-Volume ist zu groß und auf der alten Volume group, das kommt jetzt weg und wir legen eines mit 4 GB Größe an.
root@sysresccd /mnt % lvremove /dev/n112h151/swap_1
Do you really want to remove active logical volume swap_1? [y/n]: y
Logical volume "swap_1" successfully removed
root@sysresccd /mnt % lvcreate -n swap_1 /dev/newVG -L 4G
Logical volume "swap_1" created
Wir legen unser neues Root-Filesystem an (20GB groß), mounten das alte und das neue und kopieren um.
root@sysresccd /mnt % lvcreate -n root /dev/newVG -L 20G
Logical volume "root" created
root@sysresccd /mnt % mkfs.ext3 /dev/newVG/root
mke2fs 1.41.9 (22-Aug-2009)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
root@sysresccd /mnt % mount /dev/newVG/root /mnt/newfs
root@sysresccd /mnt % mount /dev/n112h151/root /mnt/oldfs
root@sysresccd /mnt % cd oldfs
root@sysresccd /mnt/oldfs % find . -print | cpio -o | (cd /mnt/newfs; cpio -idm)
1025695 blocks
1025695 blocks
root@sysresccd /mnt/oldfs % cd ..
root@sysresccd /mnt % umount /mnt/oldfs
root@sysresccd /mnt % umount /mnt/newfs
Nun löschen wir unser altes Root-Filesystem logisches Volume, die alte Volume-Group und das alte physical Volume.
root@sysresccd /mnt % lvchange -a n /dev/n112h151/root
root@sysresccd /mnt % lvremove /dev/n112h151/root
Logical volume "root" successfully removed
root@sysresccd /mnt % vgremove n112h151
Volume group "n112h151" successfully removed
root@sysresccd /mnt % pvremove /dev/sda2
Labels on physical volume "/dev/sda2" successfully wiped
Wir bennenen unsere Volume-Group um auf den alten Namen, dann brauchen wir später die fstab nicht zu editieren (außer für das /boot-Filesystem).
root@sysresccd /mnt % lvchange newVG/swap_1 -a n
root@sysresccd /mnt % lvchange newVG/root -a n
root@sysresccd /mnt % vgrename newVG n112h151
Volume group "newVG" successfully renamed to "n112h151"
root@sysresccd /mnt % lvchange n112h151/swap_1 -a y
root@sysresccd /mnt % lvchange n112h151/root -a y
Nun passen wir die Partitionstabelle der ersten Festplatte der der zweiten an. Gleiche Partitionsgrößen machen definitiv Sinn.
fdisk -u /dev/sda
The number of cylinders for this disk is set to 121601.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x00044960
Device Boot Start End Blocks Id System
/dev/sda1 * 63 498014 248976 83 Linux
/dev/sda2 498015 1953520064 976511025 8e Linux LVM
Command (m for help): d
Partition number (1-4): 2
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 sector (63-1953525167, default 63): 64
Last sector, +sectors or +size{K,M,G} (64-1953525167, default 1953525167): +200M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First sector (63-1953525167, default 63): 409672
Last sector, +sectors or +size{K,M,G} (409672-1953525167, default 1953525167):
Using default value 1953525167
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)
Command (m for help): a
Partition number (1-4): 1
Command (m for help): p
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x00044960
Device Boot Start End Blocks Id System
/dev/sda1 * 64 409664 204800+ 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 409672 1953525167 976557748 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Nunmehr fügen wir unsere neuen Mirror-Subvolumes hinzu und lassen das ganze seinen Sync Lauf machen.
root@sysresccd /mnt % mdadm /dev/md127 -a /dev/sda2
mdadm: added /dev/sda2
root@sysresccd /mnt % more /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md127 : active raid1 sda2[2] sdb2[0]
976557632 blocks [2/1] [U_]
[>....................] recovery = 0.1% (1321600/976557632) finish=172.1
min speed=94400K/sec
unused devices:
Wir bauen erstmal ein neues /boot und kopieren das vorhin weggespeicherte da wieder drauf.
root@sysresccd /mnt % mkfs.ext2 /dev/sda1
mke2fs 1.41.9 (22-Aug-2009)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
root@sysresccd /mnt % mount /dev/sda1 /mnt/newfs
root@sysresccd /mnt % mount /dev/sdb1 /mnt/oldfs
root@sysresccd /mnt % cd !$
cd /mnt/oldfs
root@sysresccd /mnt/oldfs % !fi
find . -print | cpio -o | (cd /mnt/newfs; cpio -idm)
21045 blocks
21045 blocks
root@sysresccd /mnt/oldfs % cd ..
root@sysresccd /mnt % umount /mnt/newfs
root@sysresccd /mnt % umount /mnt/oldfs
Nun wird es Zeit, das ganze fertig zu stellen. Wir mounten unseren neuen Filesystem Baum und begeben uns per chroot in diesen.
root@sysresccd /mnt % mount /dev/n112h151/root /mnt/newfs
root@sysresccd /mnt % mount /dev/sda1 /mnt/newfs/boot
root@sysresccd /mnt % mount -t proc none /mnt/newfs/proc
root@sysresccd /mnt % mount -o bind /dev /mnt/newfs/dev
root@sysresccd /mnt % mount -o bind /sys /mnt/newfs/sys
root@sysresccd /mnt % chroot /mnt/newfs /bin/bash
root@sysresccd:/#
Doof ist es, wenn wie in unserem Fall das Raid-Verwaltungs-Utility nicht auf der Maschine drauf war. Das kann man aber jetzt sogar noch installiert.
root@sysresccd:/# apt-get install mdadm
Nun konfigurieren wir noch den Boot-Loader (grub) neu. Wichtig ist es, ihn auf beide Platten zu installieren falls eine davon kaputt geht.
root@sysresccd:/# dpkg-reconfigure grub
sysresccd:/# grub-install /dev/sda
sysresccd:/boot# exit
root@sysresccd /root % reboot
Nun nun können wir das System von der Festplatte neu starten und wenn alles gut gelaufen ist läuft es danach mit raid1. Ansonsten rescue-system erneut starten und gucken was falsch ist.
Zu beachten ist noch, das man ab und zu die /boot-Partition auf der zweiten Platte aktualisieren sollte und bei Gelegenheit auch den boot-loader drauf zu spielen. Selbst wenn der Rechner nach dem Austausch einer Festplatte dann nicht mehr booten sollte (wenn es die erste war und die Root-Server nur von der ersten booten sollten) kann man sich damit sein System mit geringem Aufwand wieder herstellen und hat nix verloren.