Recently I got an idea to reuse my old PC as a Linux server box. The main problem was that I had only PC box left – no mouse, keyboard and monitor (I dumped all this when I was moving to my new flat).
I decided to install CentOS on USB stick, boot it on my old PC, create software raid on it and move everything from USB to permanent storage on old PC. At the end everything ended quite successful – this blog is already running on that old box 🙂
So I am going to describe each step I have done and all the caveats I have encountered.
Step 1: USB stick preparation
Normally at work I use Windows 7 laptop because I haven’t got any other usable PC at the moment (actually, there is no need to have it anyway).
I didn’t want to burn or prepare any media at all. Just to download install image and install OS to USB stick, so for this I used Oracle VirtualBox. I mounted CentOS install DVD as CD-ROM drive and passed through USB flash to the virtualized system. CentOS installer booted and I did Base installation to USB stick.
I am not going to describe all the installation procedure, but there is some installation decisions to highlight:
- Use VirtualBox with USB 2.0 support or it will be very slow.
- You’ll need at least 4GB (possibly 2GB is enough too if you are not going to create swap partition) USB stick.
- When doing partitioning rename standard VolGroup and LogVol to something that makes sense (for example vg_server, lv_root, lv_swap). Do not use whole space. Create 1-2GB swap volume and leave at lease 1.5GB for root). You can leave 500MB for /boot as it is by default. If you are using 2GB flash – you can make it smaller – 200MB is enough.
Step 2: booting from USB first time on my laptop and initial CentOS configuration
Next I booted my Linux from USB stick. Please make sure that you have got USB boot enabled. Next steps:
- yum update (to update whole system)
- chkconfig iptables off (disabling firewall is easiest way to deal with it – we will need ssh port open)
- make sure sshd is enabled and it is allowing root login or you have got user which can do su to root
- make sure mdadm, mkinitrd, rsync commands exists (I don’t remember if all of them come in CentOS base installation)
- prepare /etc/sysconfig/network-scripts/ifcfg-eth2 with ONBOOT=”yes” and your IP parameters (static or dhcp). You should notice that for every new ethernet interface CentOS discovers the udev renames it to be unique. I use eth2 because eth0 was my VirtulBox and eth1 is my current interface used with laptop. You can change this mappings in /etc/udev/rules.d/70-persistent-net.rules
- Reboot to check if everything comes up (try ssh)
Step 3: booting USB stick on my old PC
I knew that USB boot (thankfully) was enabled on my old PC box. That’s why I started all this difficult Linux installation.
I inserted USB flash into USB port, connected network cable and powered on the system.
After a few minutes I checked my Mikrotik router’s DHCP logs to get the IP address of Linux instance.
ssh was a success!
Now I needed to move the system to local physical storage.
The system has 2 same size HDDs, so I decided to go with software RAID1.
Step 4: preparing physical storage devices (software RAID)
- Partitioning physical drives. I decided to use 2 partitions on each drive: one for md0 (/boot) and second one for md1 (LVM’s physical storage). Other layouts may include additional raid partition for swap, but I use swap as logical volume. So for md0 – 500M, for md1 – all the rest. Please do not forget change partition type to fd and set bootable flag for first partition.
- mdadm –create /dev/md0 –level=mirror –raid-devices=2 –metadata=0.90 /dev/sda1 /dev/sdb1 (you must force older metadata or GRUB will fail to install, GRUB2 doesn’t have this problem but it doesn’t come with CentOS 6)
- mdadm –create /dev/md1 –level=mirror –raid-devices=2 /dev/sda2 /dev/sdb2
- please wait till md arrays are building. Check status by running cat /proc/mdstat
- mdadm –detail –scan > /etc/mdadm.conf
- remove rd_NO_MD from /boot/grub/menu.lst (this option disables MD raid detection on boot)
- mkinitrd /boot/initramfs-2.6.32-279.22.1.el6.x86_64.img 2.6.32-279.22.1.el6.x86_64 (to have md kernel modules included)
- GRUB installation (do not use grub-install, it may be false possitive):
- root (hd0, 0)
- setup (hd0)
- root (hd1, 0)
- setup (hd1)
- quit (it shouldn’t report any errors)
- mount /dev/md0 /mnt
- rsync -avz /boot /mnt
- umount /mnt
- pvcreate /dev/md1
- vgextend vg_server /dev/md1
- pvmove /dev/sdc2 (USB stick partition)
- vgreduce vg_server /dev/sdc2
- pvremove /dev/sdc2
- edit /etc/fstab: change /boot UUID to md0’s UUID (use blkid to get UUID)
- remove USB stick
- power on the system
And hope you are up and running! I was lucky one 🙂