I recently accquired a root server hosted by Manitu. It was planned to run Centos 6 on that server, but unfortunately that is not in the list of operating systems that can be preinstalled (or reinstalled) via the management web page.
There is, however, a rescue system, an option to remotely boot the server into a bare bones Linux system via the network. Since an OS is basically a bunch of bits on a hard disk it should be possible to get said bits onto the hard disk from the rescue system.
How hard can it be?
Now, there are some things to consider. First of all, this is not for someone new to Linux or CentOS. There are lots of ways for things to go wrong or not end up as expected. The usual failure mode for this is the remote system not booting, which is kind of hard to debug without any further information. Also, this will erase all data on the hard disks in the system.
The partitioning scheme is what I needed for my system. Adjust as needed. If you don't know how that's the first clue that you should not be doing this in the first place.
Preconditions
Some of the things needed for this to work:
- The rescue system has to support the hardware you want to install on (mainly network and hard disk controllers). Since the rescue system is provided by the hoster this is usually the case, but it does not hurt to check.
- The rescue system has to support software RAID (if you want it), LVM (if you want it) and all file systems you want to use (or at least the ones needed to boot the system)
- The rescue system kernel has to be reasonably similar to the CentOS installer kernel. Being newer is usually not a problem, being much older can be.
- wget (or some other way to download files via HTTP)
- File system support in the kernel for ISO9660, squashfs and ext3
- At least 2GB of RAM
- Hardware supported by CentOS 6. If CentOS 6 would not install or boot on the system when doing a normal (CD/DVD based or network) install then chances are that installing it this way will not work either.
It is further assumed that a tmpfs file system is mounted at /dev/shm
.
Install plan
The hardware in question here has two SATA HDDs on AHCI compatible controllers without any hardware RAID. The final hard disk layout will be as follows:
/dev/md0
, 1GB, consisting of /dev/sda1
and /dev/sdb1
, ext3, mounted at /boot
/dev/md1
, 64GB, consisting of /dev/sda2
and /dev/sdb2
, LVM PV
The PV is part of a volume group which contains an LV holding the root file system.
Prepare the Live CD
The rescue system usually has no CentOS specific tools (like RPM) which are needed to install the OS packages. In order to get a usable install environment we'll commandeer the CentOS 6 live CD. It contains a complete root file system image.
- Download the current live CD ISO image from "http://mirror.centos.org":http://mirror.centos.org, putting the file into
/dev/shm
. Be sure to grab the CD for the right architecture (the right architecture is x86_64, by the way).
- Create a bunch of directories
mkdir /loop1 /loop2 /sysroot
- Mount the root image (this is a bit recursive)
mount -o ro /dev/shm/CentOS-6.2-x86_64-LiveCD.iso /loop1
mount -o ro /loop1/LiveOS/squashfs.img /loop2
mount -o ro /loop2/LiveOS/ext3fs.img /sysroot
- Bind mount needed virtual file systems
mount -o bind /dev /sysroot/dev
mount -o bind /proc /sysroot/proc
mount -o bind /sys /sysroot/sys
Now chroot into /sysroot
and try running some commands (RPM, yum). If this does not work then the rescue system kernel is probably too far from the live CD kernel, and this adventure ends here.
The image mounted at /sysroot
is read only. This will not do, since we need to change DNS entries, so create a writable /etc
:
mount -t tmpfs tmpfs /tmp
rsync -a /etc /tmp
mount -o bind /tmp/etc /etc
Ignore the mtab
warning the first command produces. After this, fill in /etc/resolv.conf
with some name servers and try to pinging something by name.
Prepare for installation
Leave the chroot again (working with LVM does not work within it).
Remove and stop any existing volume groups and software raids. Then partition the hard disks according to the new scheme and create the new software RAIDs and LVMs.
fdisk -u -c /dev/sda
sfdisk -d /dev/sda | sfdisk --force /dev/sdb
mdadm --create /dev/md0 -n 2 --level 1 --metadata=0.90 /dev/sda1 /dev/sdb1
mdadm --create /dev/md1 -n 2 --level 1 /dev/sda2 /dev/sdb2
pvcreate /dev/md1
vgcreate -s 64M vg_tara_root /dev/md1
lvcreate -n lv_swap -L 8G vg_tara_root
lvcreate -n lv_c6_root -L 16G vg_tara_root
mkfs.ext3 /dev/md0
mkfs.ext4 /dev/mapper/vg_tara_root-lv_c6_root
tune2fs -c0 -i0 -r32000 -L boot /dev/md0
tune2fs -c0 -i0 -r32000 -L lv_c6_root /dev/mapper/vg_tara_root-lv_c6_root
It's probably a good idea to wait for the RAID resync, that should not take long. The metadata version on /dev/md0
is needed to help the boot loader.
- chroot into
/sysroot
again.
- Prepare a directory tree to hold the system to be installed (it's also called sysroot. Yes, this is intentionally confusing):
mkdir /tmp/sysroot
mount /dev/mapper/vg_tara_root-lv_c6_root /tmp/sysroot
mkdir -p /tmp/sysroot/{boot,dev,proc,sys}
mount /dev/md0 /tmp/sysroot/boot
mount -o bind /dev /tmp/sysroot/dev
mount -o bind /proc /tmp/sysroot/proc
mount -o bind /sys /tmp/sysroot/sys
Installation
- Prepare the RPM database in the new system:
rpm --root /tmp/sysroot --rebuilddb
- Download the centos-release RPM from the current CentOS 6 build (again: architecture) into
/tmp
and install it:
rpm --root /tmp/sysroot -ihv /tmp/centos-release-6-2.el6.centos.7.x86_64.rpm
- Now install the CentOS base system. This ought to install 300 to 350 packages, depending on the release. Confirm the GPG key import question, and ignore the DBUS error at the end. Depending on network connection and hard disk speed this may take a while.
yum --installroot=/tmp/sysroot groupinstall base
- Install the bootloader and SSH server package.
yum --installroot=/tmp/sysroot install grub openssh-server
- Unmount the newly installed system and clean up the chroot
umount /tmp/sysroot/{boot,dev,proc,sys,} /etc /tmp
- Leave the chroot
- Remove the live CD image
umount /sysroot/{dev,proc,sys,}
umount /loop2
umount /loop1
- Mount the new system under
/sysroot
mount /dev/mapper/vg_tara_root-lv_c6_root /sysroot
mount /dev/md0 /sysroot/boot
mount -o bind /dev /sysroot/dev
mount -o bind /proc /sysroot/proc
mount -o bind /sys /sysroot/sys
- chroot into
/sysroot
- Set the password for root
- Create a symlink for
/etc/mtab
ln -s /proc/mounts /etc/mtab
grub-install /dev/md0
- Remove
/etc/mtab
- Populate
/etc/fstab
. Do not use raw device names here, especially not for software RAIDs. Use labels or UUIDs.
LABEL="lv_c6_root" / ext4 defaults 1 1
LABEL="boot" /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
- Populate
/etc/resolv.conf
- Populate
/etc/sysconfig/network
NETWORKING=yes
NOZEROCONF=yes
HOSTNAME=tara.example.org
- Populate
/etc/sysconfig/network-scripts/ifcfg-eth0
(use the correct values for IPs, prefixes and gateways)
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.0.100
GATEWAY=192.168.0.1
PREFIX=24
ONBOOT=yes
- Populate
/boot/grub/grub.conf
(mind the line break)
default=0
timeout=5
title CentOS (2.6.32-220.23.1.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-220.23.1.el6.x86_64 ro root=LABEL=lv_c6_root LANG=en_US.UTF-8 \
SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=de-latin1-nodeadkeys
initrd /initramfs-2.6.32-220.23.1.el6.x86_64.img
cp /etc/skel/.* /root
- Create
grub.conf
symlinks
ln -s grub.conf /boot/grub/menu.lst
ln -s /boot/grub/grub.conf /etc/grub.conf
- Leave the chroot
- Unmount the new system
umount /sysroot/{boot,sys,dev,proc,}
Now, usually this ought to result in a bootable system which can be accessed via SSH. Only one way to find out.