Moin!
Um das auch mal für mich aufzuschreiben und da es möglicherweise für andere nützlich ist:
HOWTO: Neuinstallation eines minimalen Debian Wheezy mit individueller Partitionierung, Soft-RAID1 und LVM mittels debootstrap und einem Live-System (Gentoo)Stand: 25.05.13
Ohne Gewähr, ich bin nicht schuld.
Gründe:- Die vorgegebene Partitionierung des Wheezy Images ist eher unsinnig (z.B. 2GB swap, / -> Rest)
- Die Partitionen über das Rescue-System nachträglich verkleinern und ein vorhandenes Soft-RAID1 anzupassen geht zwar theoretisch, zerschoss _mir_ aber das RAID1 (mag an mir liegen...)
- Das Rescue-System ist... suboptimal (kein debootstrap, kein funktionierendes emerge usw.)
- Das derzeitige Wheezy Image kam bei mir mit seltsamen Fehlern auf die Kiste (nobody:nogroup permissions bei einigen Dateien, wer weiss was da noch schlummert)
Vorbedingungen:- Root-Server mit zwei (möglichst identischen) Festplatten
- Zugang zum Kundencenter/Serverdaten/Re-Installation
- Das Rescue-System darf nicht aktiv sein, es wird hoffentlich gar nicht benutzt
Vorbereitungen:- Alle Daten sichern (!), insb. /etc bei schon laufenden Systemen
Ablauf- Mit ssh auf den Server
- Im Kundencenter Re-Installation mit folgendem Image starten (nur sichtbar, wenn Sprache: Standard ausgewählt ist): Linux Live System (Gentoo) - 64Bit
- Server rebooten
- Etwas warten und im Kundencenter unter Serverdaten das neue Root-Password nachschlagen
- Mit ssh auf das Live-System
- Noch ein Mal prüfen ob debootstrap, mdadm und die lvm tools installiert sind:
LinuxLiveSystem ~ # uname -a
Linux [IP]_LinuxLiveSystem 3.4.2-alt280-amd64 #2 SMP Sun Jun 10 07:17:50 UTC 2012 x86_64 Intel(R) Xeon(R) CPU X3330 @ 2.66GHz GenuineIntel GNU/Linux
LinuxLiveSystem ~ # debootstrap
I: usage: [OPTION]... <suite> <target> [<mirror> [<script>]]
I: Try `debootstrap --help' for more information.
E: You must specify a suite and a target.
LinuxLiveSystem ~ # mdadm
Usage: mdadm --help
for help
LinuxLiveSystem ~ # lvdisplay
No volume groups found - Das Live-System hat bei der "Installation" die Festplatten gelöscht. Vorsichtshalber noch ein Mal überprüfen ob wirklich keine Reste eines alten RAID1 erkannt wurden:
LinuxLiveSystem ~ # cat /proc/mdstat
Personalities :
unused devices: <none> - Neues Partitionsschema auf /dev/sda mittels fdisk anlegen. Kurz die Kommandos die gebraucht werden:
- d - Partion löschen. Es sollten keine Partitionen gefunden werden
- n - Neue Partition erstellen - p Primäre Partition (max. 4)
- t - Partitionstyp - Wir benötigen nur fd für Linux Raid Autodetect
- w - Änderungen auf die Platte schreiben
- q - fdisk beenden
Ich habe mich für eine 500MB Partition für /boot ausserhalb des LVM entschieden. Der Rest der Platte wird komplett im LVM benutzt (auch /swap und /)
LinuxLiveSystem ~ # fdisk /dev/sda
Command (m for help): d
No partition is defined yet!
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1465149167, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1465149167, default 1465149167): +512MB
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (1002048-1465149167, default 1002048):
Using default value 1002048
Last sector, +sectors or +size{K,M,G} (1002048-1465149167, default 1465149167):
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): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
- Jetzt das neue Partitionsschema 1:1 auf /dev/sdb kopieren:
LinuxLiveSystem ~ # sfdisk -d /dev/sda | sfdisk --force /dev/sdb
Checking that no-one is using this disk right now ...
OK [...]
- Vorsichtshalber:
LinuxLiveSystem ~ # mdadm --zero-superblock /dev/sda1
mdadm: Couldn't open /dev/sda1 for write - not zeroing
LinuxLiveSystem ~ # mdadm --zero-superblock /dev/sda2
LinuxLiveSystem ~ # mdadm --zero-superblock /dev/sda1
mdadm: Couldn't open /dev/sda1 for write - not zeroing
LinuxLiveSystem ~ # mdadm --zero-superblock /dev/sdb1
mdadm: Couldn't open /dev/sdb1 for write - not zeroing
LinuxLiveSystem ~ # mdadm --zero-superblock /dev/sdb2 - An dieser Stelle wurde vom Live-System irgendein Raid entdeckt, mir unklar warum, evtl. Reste eines vorhergegangen Versuchs (mit dem untauglichen Rescue-System). Daher alle erkannten Devices stoppen:
LinuxLiveSystem ~ # cat /proc/mdstat
Personalities : [raid1]
md127 : active (auto-read-only) raid1 sdb1[1] sda1[0]
499904 blocks [2/2] [UU]
unused devices: <none>
LinuxLiveSystem ~ # mdadm --stop /dev/md127
mdadm: stopped /dev/md127
LinuxLiveSystem ~ # cat /proc/mdstat
Personalities : [raid1]
unused devices: <none> - Die Ausgabe von parted -l sollte jetzt so oder so ähnlich aussehen:
LinuxLiveSystem ~ # parted -l
Model: ATA WDC WD7500AACS-0 (scsi)
Disk /dev/sda: 750GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 513MB 512MB primary ext4 raid
2 513MB 750GB 750GB primary raid
Model: ATA WDC WD7500AADS-0 (scsi)
Disk /dev/sdb: 750GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 513MB 512MB primary ext4 raid
2 513MB 750GB 750GB primary raid - Jetzt die zwei neuen RAID1-Arrays anlegen:
LinuxLiveSystem ~ # mdadm --create /dev/md0 --level=1 --metadata=0.90 --raid-disks=2 /dev/sda1 /dev/sdb1
mdadm: array /dev/md0 started.
LinuxLiveSystem ~ # mdadm --create /dev/md1 --level=1 --metadata=0.90 --raid-disks=2 /dev/sda2 /dev/sdb2
mdadm: array /dev/md1 started. - Prüfen, ob alles seine Ordnung hat:
LinuxLiveSystem ~ # mdadm --detail /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Sat May 25 23:16:42 2013
Raid Level : raid1
Array Size : 499904 (488.27 MiB 511.90 MB)
Used Dev Size : 499904 (488.27 MiB 511.90 MB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Sat May 25 23:16:42 2013
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
UUID : ab37849f:81ffab00:918ababa:9200019f (local to host LinuxLiveSystem)
Events : 0.1
Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 8 17 1 active sync /dev/sdb1
LinuxLiveSystem ~ # mdadm --detail /dev/md1
/dev/md1:
Version : 0.90
Creation Time : Sat May 25 23:15:41 2013
Raid Level : raid1
Array Size : 732072960 (698.16 GiB 749.64 GB)
Used Dev Size : 732072960 (698.16 GiB 749.64 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 1
Persistence : Superblock is persistent
Update Time : Sat May 25 23:15:41 2013
State : clean, resyncing
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Rebuild Status : 1% complete
UUID : ab37849f:81ffab01:918ababa:9200019f (local to host LinuxLiveSystem)
Events : 0.1
Number Major Minor RaidDevice State
0 8 2 0 active sync /dev/sda2
1 8 18 1 active sync /dev/sdb2
LinuxLiveSystem ~ # cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[1] sda1[0]
499904 blocks [2/2] [UU]
resync=DELAYED
md1 : active raid1 sdb2[1] sda2[0]
732072960 blocks [2/2] [UU]
[>....................] resync = 2.2% (16488512/732072960) finish=140.1min speed=85081K/sec
unused devices: <none> - Warten bis der (unsinnige) resync fertig ist. Aus esoterischen Gründen.
- Neues Dateisystem auf dem für /boot vorgesehenen RAID-Device anlegen:
LinuxLiveSystem ~ # mkfs.ext4 /dev/md0
mke2fs 1.42.3 (14-May-2012)
[...]
Writing superblocks and filesystem accounting information: done
- LVM auf dem RAID-Device /dev/md1 einrichten und gleich zwei logische Datenträger für swap und / erzeugen (ich brauche nur 100GB, der Rest wird dann für XEN-Images verwendet):
LinuxLiveSystem ~ # pvcreate /dev/md1
Writing physical volume data to disk "/dev/md1"
Physical volume "/dev/md1" successfully created
LinuxLiveSystem ~ # vgcreate vg0 /dev/md1
Volume group "vg0" successfully created
LinuxLiveSystem ~ # lvcreate -n root -L 100G vg0
Logical volume "root" created
LinuxLiveSystem ~ # lvcreate -n swap -L 8G vg0
Logical volume "swap" created
LinuxLiveSystem ~ # lvscan
ACTIVE '/dev/vg0/root' [100.00 GiB] inherit
ACTIVE '/dev/vg0/swap' [8.00 GiB] inherit - Neues Dateisystem auf dem für / vorgesehenen logischen Datenträger anlegen und swap vorbereiten:
LinuxLiveSystem ~ # mkfs.ext4 /dev/vg0/root
mke2fs 1.42.3 (14-May-2012)
[...]
Writing superblocks and filesystem accounting information: done
LinuxLiveSystem ~ # mkswap /dev/vg0/swap
[...] - Mit fdisk -l und/oder parted -l noch ein Mal alles überprüfen.
- chroot-Umgebung vorbereiten:
LinuxLiveSystem ~ # mkdir /debroot
LinuxLiveSystem ~ # mount /dev/vg0/root /debroot
LinuxLiveSystem ~ # cd /debroot
LinuxLiveSystem ~ # mkdir boot proc dev sys home etc
LinuxLiveSystem ~ # mount /dev/md0 boot/
LinuxLiveSystem ~ # cd etc
Hier (genauer: /debroot/etc/ die Datei fstab anlegen (mit vi o.Ä.) mit folgendem Inhalt:
proc /proc proc defaults 0 0
/dev/md0 /boot ext4 defaults 0 2
/dev/vg0/root / ext4 defaults 0 1
/dev/vg0/swap none swap defaults,pri=1 0 0
- Das Debian-Basissystem in die neue Umgebung laden:
LinuxLiveSystem etc # debootstrap --arch amd64 stable /debroot ftp://ftp.de.debian.org/debian/
I: Retrieving Release
[...]
I: Base system installed successfully. - Weitere Vorbereitungen für die chroot-Umgebung:
LinuxLiveSystem mount # mount -t proc none /debroot/proc/
LinuxLiveSystem mount # mount -o bind /dev/ /debroot/dev/
LinuxLiveSystem mount # mount -o bind /sys /debroot/sys/ - Jetzt in die chroot-Umgebung wechseln und direkt das neue root-Password anlegen (für den dann hoffentlich frisch laufenden Server):
LinuxLiveSystem mount # chroot /debroot/ /bin/bash
root@LinuxLiveSystem:/# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully - Innerhalb der chroot-Umgebung die wichtigsten Konfigurationsdateien anpassen. Sinnvollerweise mit den Werten aus dem gesicherten /etc. Ganz wichtig ist /etc/network/interfaces. Werte erneut überprüfen!:
root@LinuxLiveSystem:/# vi /etc/network/interfaces
root@LinuxLiveSystem:/# vi /etc/hostname
root@LinuxLiveSystem:/# vi /etc/hosts
root@LinuxLiveSystem:/# vi /etc/resolv.conf - Unbedingt benötigte Pakete installieren. Ohne diese wird das neue System nicht starten/erreichbar sein:
root@LinuxLiveSystem:/# apt-get update
Get:1 http://ftp.us.debian.org stable Release.gpg [1672 B]
Get:2 http://ftp.us.debian.org stable Release [159 kB]
Get:3 http://ftp.us.debian.org stable/main amd64 Packages [5846 kB]
Get:4 http://ftp.us.debian.org stable/main Translation-en [3851 kB]
Fetched 9859 kB in 7s (1382 kB/s)
Reading package lists... Done
root@LinuxLiveSystem:/# apt-get upgrade
Reading package lists... Done
Building dependency tree... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@LinuxLiveSystem:/# apt-get install mdadm lvm2 openssh-server ntp locales
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
[...]
[ ok ] Setting up LVM Volume Groups...done. - Weiterhin sinnvoll:
root@LinuxLiveSystem:/# dpkg-reconfigure locales tzdata
[...]
Generation complete.
Current default time zone: 'Europe/Berlin'
Local time is now: Sun May 26 09:48:24 CEST 2013.
Universal Time is now: Sun May 26 07:48:24 UTC 2013. - Linux-Kernel im neuen System installieren:
root@LinuxLiveSystem:/# apt-get install linux-image-amd64
Reading package lists... Done
Building dependency tree
[...]
update-initramfs: Generating /boot/initrd.img-3.2.0-4-amd64
df: Warning: cannot read table of mounted file systems: No such file or directory - grub im neuen System installieren, auf dem boot-Laufwerk(en) (RAID1) initialisieren und Konfiguration neu erstellen:
root@LinuxLiveSystem:/# apt-get install grub2
Reading package lists... Done
Building dependency tree
[...]
Setting up grub2 (1.99-27+deb7u1) ...
Setting up os-prober (1.58) ...
root@LinuxLiveSystem:/# grub-install --no-floppy /dev/sda
Installation finished. No error reported.
root@LinuxLiveSystem:/# grub-install --no-floppy /dev/sdb
Installation finished. No error reported.
root@LinuxLiveSystem:/# update-grub /dev/md0
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.2.0-4-amd64
Found initrd image: /boot/initrd.img-3.2.0-4-amd64
done
root@LinuxLiveSystem:/# update-initramfs -u
update-initramfs: Generating /boot/initrd.img-3.2.0-4-amd64
df: Warning: cannot read table of mounted file systems - Fertig. Jetzt chroot-Umgebung verlassen und das Live-System neu booten. Der Server bootet anschliessend von den neu eingerichteten Festplatten:
root@LinuxLiveSystem:/# exit
LinuxLiveSystem:/# reboot
Jetzt steht hoffentlich ein frisches Debian mit RAID1 und LVM mit viel freiem Platz zur Verfügung.