CentOS 6, LVM, mdadm, USB stick tricks

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:

  1. yum update (to update whole system)
  2. chkconfig iptables off (disabling firewall is easiest way to deal with it – we will need ssh port open)
  3. make sure sshd is enabled and it is allowing root login or you have got user which can do su to root
  4. make sure mdadm, mkinitrd, rsync commands exists (I don’t remember if all of them come in CentOS base installation)
  5. 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
  6. 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)

  1. 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.
  2. 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)
  3. mdadm –create /dev/md1 –level=mirror –raid-devices=2 /dev/sda2 /dev/sdb2
  4. please wait till md arrays are building. Check status by running cat /proc/mdstat
  5. mdadm –detail –scan > /etc/mdadm.conf
  6. remove rd_NO_MD from /boot/grub/menu.lst (this option disables MD raid detection on boot)
  7. 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)
  8. GRUB installation (do not use grub-install, it may be false possitive):
    1. grub
    2. root (hd0, 0)
    3. setup (hd0)
    4. root (hd1, 0)
    5. setup (hd1)
    6. quit (it shouldn’t report any errors)
  9. mount /dev/md0 /mnt
  10. rsync -avz /boot /mnt
  11. umount /mnt
  12. pvcreate /dev/md1
  13. vgextend vg_server /dev/md1
  14. pvmove /dev/sdc2 (USB stick partition)
  15. vgreduce vg_server /dev/sdc2
  16. pvremove /dev/sdc2
  17. edit /etc/fstab: change /boot UUID to md0’s UUID (use blkid to get UUID)
  18. poweroff
  19. remove USB stick
  20. power on the system

And hope you are up and running! I was lucky one 🙂


This entry was posted in CentOS, Linux and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *