Pages

15 March 2013

359. Installing Scientific Linux (CentOS, RHEL) via a chroot in a running debian installation

This is a fun post. I've got a small server and I'd like to put Scientific Linux on it. I figure that between using Arch on my laptop, and Debian on my beowulf cluster, my work desktop, my home desktop and on another two laptops what I really need is to become a bit more proficient in the use of RHEL clones.

I've settled on Scientific Linux since I encounter that more often than CentOS.

My mini server lacks any form of video interface though, so the easiest solution is to take out the harddrive and install Scientific Linux via a USB tether and a chroot, similar to how things are done when making standard installs of Arch or Gentoo (it's all coming together...)

In a future post I'll write up how to install debian via a running debian system and a chroot (hint: debootstrap).

Anyway.

1. Install yum on your debian system
sudo apt-get install yum

2. Set up the Scientific Linux repos for yum on your debian system
Because it's easier, we'll disable gpg check.

If you're target is a 32 bit box, change x86_64 to i386 (my little server runs a 32 bit atom cpu and I screwed this up once)

Create /etc/yum/repo.d/sl.repo
[sl] name=Scientific Linux 6.3 - x86_64 baseurl=http://ftp.scientificlinux.org/linux/scientific/6.3/x86_64/os/ http://ftp1.scientificlinux.org/linux/scientific/6.3/x86_64/os/ http://ftp2.scientificlinux.org/linux/scientific/6.3/x86_64/os/ ftp://ftp.scientificlinux.org/linux/scientific/6.3/x86_64/os/ enabled=1 gpgcheck=0 [sl-security] name=Scientific Linux 6.3 - x86_64 - security updates baseurl=http://ftp.scientificlinux.org/linux/scientific/6.3/x86_64/updates/security/ http://ftp1.scientificlinux.org/linux/scientific/6.3/x86_64/updates/security/ http://ftp2.scientificlinux.org/linux/scientific/6.3/x86_64/updates/security/ ftp://ftp.scientificlinux.org/linux/scientific/6.3/x86_64/updates/security/ enabled=1 gpgcheck=0
Test that everything is working by running

yum repolist
sl | 3.2 kB 00:00 sl-security | 1.9 kB 00:00 repo id repo name status sl Scientific Linux 6.3 - x86_64 enabled: 6,399 sl-security Scientific Linux 6.3 - x86_64 - security updates enabled: 1,584 repolist: 7,983
It might take 60 s before you get any feedback, so don't interrupt the command.

3. Mount your external harddrive
mkdir $HOME/tmp/jail -p
sudo mount /dev/sdb1 $HOME/tmp/jail

assuming of course that /dev/sdb1 is your intended root partition (see the arch and gentoo install guides for examples of how to use fdisk)

4. Install a basic system on your mounted harddrive
sudo yum --installroot=$HOME/tmp/jail install bash sl-release coreutils yum iputils vim

5. Chroot your mounted harddrive
sudo cp /etc/resolv.conf $HOME/tmp/jail/etc/resolv.conf
sudo cp /etc/yum/repos.d/* /$HOME/tmp/jail/etc/yum.repos.d/
sudo mount -t proc none $HOME/jail/proc
sudo mount --bind /sys $HOME/tmp/jail/sys
sudo mount --bind /dev $HOME/tmp/jail/dev
sudo chroot $HOME/tmp/jail
bash-4.1# head -n 1 /etc/issue.net Scientific Linux release 6.3 (Carbon) bash-4.1# ping -c 1 google.com PING google.com (74.125.237.98) 56(84) bytes of data. 64 bytes from syd01s12-in-f2.1e100.net (74.125.237.98): icmp_seq=1 ttl=51 time=16.0 ms
We are now working in Scientific Linux. Sure, we're still using the debian kernel, but everything else is from the SL repos:

First set up /etc/fstab. I normally do
blkid > /etc/fstab

and then edit it. In this case I ended up with:
UUID=45495a62-a141-4033-a739-8063f0e80a56 / ext4 errors=remount-ro,user_xattr 0 1 UUID=6dc86d8d-0ad6-4574-8dea-9d28b0151362 none swap sw 0 0
Install everything we need to boot our new system and make it run:
yum install kernel openssh-clients openssh-server passwd dhclient


Important:
passwd

If you don't set a password you can't log in.


A. Grub legacy -- I couldn't make this work; see B
yum install grub 

Make the system bootable (the first command is so that df works)
grep -v rootfs /proc/mounts > /etc/mtab
grub-install --no-floppy /dev/sdb
grub-install --no-floppy /dev/sdb Installation finished. No error reported. This is the contents of the device map /boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'. (fd0) /dev/fd0 (hd0) /dev/sda (hd1) /dev/sdb
The last command took a LONG time without any visual feedback until the very end.

Create a /boot/grub/grub.conf file:
default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz title Scientific Linux (2.6.32-358.2.1.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-358.2.1.el6.x86_64 ro root=UUID=45495a62-a141-4033-a739-8063f0e80a56 initrd /initramfs-2.6.32-358.2.1.el6.x86_64.img

B. Grub2 -- this worked perfectly for me
Grub and I don't play well together. I'm more at home with grub2 which..well..allows for a bit of stupidity. After spending a fair amount of time trying to figure out grub (legacy) I gave up and did the following:

yum install wget diffutils bison gcc gcc-c++ kernel-devel flex freetype-devel make fuse-libs fuse-devel 
cd /tmp
wget ftp://ftp.gnu.org/gnu/grub/grub-2.00.tar.gz
tar xvf grub-2.00.tar.gz
cd grub-2.00/
./configure
make
make install
grub-mkconfig -o /boot/grub/grub.cfg
yum erase grub
grub-install /dev/sdb


Set up the following files:

/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=science!
/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
If you want static inet instead, do
DEVICE=eth0
HWADDR=D4:AE:52:71:79:14
IPADDR=10.1.1.1
NETMASK=255.255.0.0
BOOTPROTO=none
ONBOOT=yes
MTU=1500
TYPE=Ethernet
You're now ready to exit the chroot, unmount everything and reboot. Things to do after the first reboot include setting up a user (useradd -m verahill) and install sudo.
Anyway, there are plenty of guides online for that...

I tried this on physical hardware, and it works  Since the box is headless I only had ssh access, setting up proper rules in /etc/udev/rules.d/ was important so that I could configure the network via /etc/sysconfig/network-scripts files before putting the drive back in the server.

/etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0e:b6:2a:a9:30", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0e:b6:2a:a9:31", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

This is a headless box (no graphics card, no vga output -- only a serial port), but I wanted to be able to use for a student to use gnuplot etc. in a pinch.

sudo yum install xorg-x11-server-Xvfb xorg-x11-server-Xorg

To set up keyword-less key-based ssh log in, edit /etc/ssh/sshd_config and uncomment
AuthorizedKeysFile .ssh/authorized_keys
mkdir ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 644 ~/.ssh/authorized_keys

Done.

No comments:

Post a Comment