The Bone Yard

Browse posts by
Search posts by
Tag

My 2 Cent (OS)

My unofficial guide for bootstrapping CentOS

As part of my blog project, I had decided to switch VPS providers from Digital Ocean to Linode. In my experience, Digital Ocean has been a very capable hosting company. Really no appreciable downtime, and they effectively communicate when they plan their downtime for maintenance activity. The cost for the minimal resource instance I run is effectively a wash between the two providers. There are some subtle differences, though, in the area of disk management, particularly around block device wrapper tools (e.g. LVM, LUKS), that differentiated Linode. Additionally, Linode enables users to manually initiate boots from a Linux rescue CD, which turns out to be a very good method of bootstrapping non-standard distributions not offered by a VPS provider. Digital Ocean does allow use of a rescue CD to boot from, but my understanding is that their process involves issuing a ticket request to customer support, while Linode gives users autonomy to do this on their own. I will spend another post on the topic of VPS providers, but for now, I want to write about how I went about setting up my Linode for hosting my site.

My preference for a Linux server distribution is CentOS. For desktop intalls, I have usually opted in the past for more quickly evolving distros that tend to push upstream work down faster to users. Server installs present a different need, where stability will tend to trump quicker feature adoption and release migration. In that regard, CentOS is excellent; it is perhaps one of the most stable distributions out there.

Another appealing aspect of CentOS is the fairly broad degree to which it is documented. There are good manuals available on the CentOS site, and plenty of user written articles on CentOS lie only a Google search away. It's easy enough to find information for whatever task you have in mind for CentOS. Yet, as I find myself setting up more Cent instances, I figured it would be beneficial for me to record my own manual for the series of steps I take to bootstrap a new CentOS instance. These are more or less the actions I took to install the CentOS that hosts this blog. It's possible there are grammatical typos or inaccuracies in the steps I followed. Also, this guide involves LVM; one can modify this configuration (e.g. mix in LUKS or go with a simple, bare partition scheme) to add or remove such things. Eventually this should make its way to my GitHub, too, but for now, I'll post it here. I will refine the guide as I go along, and one day this could form the basis of a scriptable process or deployment tooling via Chef, Vagrant or the like. That, however, is a discussion for another time.

NOTE: THIS IS A DISCLAIMER AGAINST ANY AND ALL ISSUES, SELF-INFLICTED SYSTEM DAMAGE, PLAGUES OF LOCUST, BODILY HARM THAT YOU MAY INCUR BY FOLLOWING THIS GUIDE. IT IS PROVIDED AS IS WITHOUT ANY GUARANTEE OR WARRANTY. USE IT AT YOUR OWN RISK.

Installing CentOS Via VPS Rescue
================================

*** Updated 09/05/2016 ***
 - include step for GPT BIOS partiion
 - update yum in minimal install
 - rsync path spec
 - set locale.conf

 Part I - Partition and Init Block Dev(s)
 ---------------------------------------

1) Initiate rescue system boot using VPS instance management software.

2) Access rescue system console via SSH, VNC terminal or whatever.

3) Using fdisk or similar tool, partition disks to your liking. For 24GB disk, I used:

   ** If using GPT partitions with BIOS ***
   * For GPT based BIOS boot, you need a small 2MB partition before boot
   * /dev/sda1 ==> bios       ==> 2MB     EF02  

   * Device                       Size    Part  FileSystem   
   *
   * /dev/sda1 ==> boot       ==> 200MB   8300  (ext4)
   * /dev/sda2 ==> swap       ==> 2GB     8200
   * /dev/sda3 ==> root (lvm) ==> 21.8GB  8e00
   *   |
   *   |-- /dev/mapper/lvroot ==> 5GB           (ext4)
   *   |-- /dev/mapper/lvvar  ==> 11.8GB        (ext4)
   *   |-- /dev/mapper/lvhome ==> 5GB           (ext4)

4) Use pvcreate to build lvm physical volume on /dev/sda3

5) Use vgcreate to build lvm volume group on pv

6) Use lvcreate to build lvm logical volumes shown above

7) Use mkfs to format file systems as listed above


 Part III - Obtain and Mount CentOS LiveCD for Installing 
 -----------------------------------------------------

1) Locate desired iso from mirror, use wget to pull down into rescue env.

2) Need to mount top level installer (.iso file), e.g. /tmp/cd

3) Need to mount installer nested squashfs img from iso, , e.g. /tmp/sfs

4) Need to mount nested extfs img from squashfs, e.g. /tmp/liveroot

5) LiveCD is packaged as read-only file system. We need to copy this to
   a writable location we can mount.

   mkdir /tmp/rwroot
   rsync -a /tmp/liveroot /tmp/rwroot

   Note that this will create a dir structure /tmp/rwroot/liveroot;
   You can append a / onto the rsync source dir to avoid this.

6) Need to init nameserver so yum can find CentOS install mirrors

   echo 'nameserver 8.8.8.8' > /tmp/rwroot/etc/resolv.conf 

7) Prep for chroot into LiveCD system
   
   mount -o bind /sys /tmp/rwroot/sys
   mount -o bind /proc /tmp/rwroot/proc
   mount -o bind /dev /tmp/rwroot/dev

8) Bring up the install environment 
   
   chroot /tmp/rwroot
 
 Part III - Execute CentOS Install 
 -----------------------------------------------------

1) Mount the target file systems somewhere accessible by install chroot

   mkdir /mnt/root
   mount /dev/mapper/lvroot /mnt/root
   mkdir /mnt/root/{boot,home,var}
   mount /dev/sda1 /mnt/root/boot
   mount /dev/mapper/lvhome /mnt/root/home
   mount /dev/mapper/lvvar /mnt/root/var

2) Need to fetch and install CentOS 'release' rpm into target system

   wget http://mirror.centos.org/centos/7/os/x86_64/Packages/centos-release-xxx.el7.centos.2.10.x86_64.rpm

   rpm --root /mnt/root -ihv centos-release-xxx.el7.centos.2.10.x86_64.rpm

*** Update 9/5/2016 ****
2a) There's one more step here, which is to install a more complete version of yum into our install target.
   If you do not do this, then you'll receive error "ImportError: No module named yummain"
   Note yum version xx.yy.zz; replace with the latest one you find in the mirror folder.

   wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-xx.yy.zz.el7.centos.0.1.noarch.rpm
   rpm -i --nodeps yum-xx.yy.zz.el7.centos.0.1.noarch.rpm


3) Now we can begin installing our CentOS system into the target environment.
   Desired packages to insall will vary. Below is minimal server.

   yum --installroot=/mnt/root groupinstall core
   yum --installroot=/mnt/root install lvm2 kernel grub2
   yum --installroot=/mnt/root install passwd shadow
   etc etc

 Part IV - Config Installed System 
 -----------------------------------------------------

1) Set up fstab

   /dev/sda1            /boot       ext4        rw,relatime 
   /dev/mapper/lvroot   /           ext4        rw,relatime,data=ordered   0 1
   /dev/mapper/lvhome   /home       ext4        rw,relatime,data=ordered   0 2
   /dev/mapper/lvvar    /var        ext4        rw,relatime,data=ordered   0 2

2) Need to init nameserver so yum can find CentOS install mirrors

   echo 'nameserver 8.8.8.8' > /tmp/rwroot/etc/resolv.conf 

3) Prep for chroot into target system
   
   mount -o bind /sys /mnt/root/sys
   mount -o bind /proc /mnt/root/proc
   mount -o bind /dev /mnt/root/dev

4) chroot /mnt/root

5) Set hostname

   echo foo > /etc/hostname

6) Set the time zone

   ln -s /usr/share/zoneinfo/America/New_York /etc/localtime

7) Assign the locale

   localedef -v -c -i en_US -f UTF-8 en_US.UTF-8
   
   echo "LANG=en_US.UTF-8" > /etc/locale.conf
   
8a) Install grub2 MBR

   grub2-install /dev/sda

8) Generate a grub2 configuration file to control boot params

   grub2-mkconfig -o /boot/grub2/grub.cfg

9) Set root password

   passwd

 Part V - Reboot 
 -----------------------------------------------------

1) Power off the VPS image

2) Disable the VPS system rescue env

3) Boot the system

Like what you're reading?
Let me know your thoughts on the content or arrangment of this blog.
How to Connect
Tags for this post
Linux
Skelton
Online
CentOS
VPS