Installing any Red Hat Enterprise Linux clone without using a standard installer

You need to install a modern Linux system only once, both for a single physical server and for the deployment of an entire virtual farm. Why not spend a little more time on it and immediately do everything exactly as it should, and not finish what came from the installer along its rails. In addition, the amount of software that is installed in the "minimum" mode of the standard installer does not correspond to the really minimum.
To some, manual installation may seem like a waste of time, but every Linuxoid must do it at least once in order to better understand how it works. If you are not afraid of the words fdisk, grub and chroot, read on.

The installation of the operating system can be divided into 4 separate stages.
  1. Preparing system storage
  2. Install and configure system components
  3. Preparing the system for self-boot
  4. System setup for work tasks

In most modern systems, tasks 1-3 are performed by installers. In semi-automated installers, items 1-3 are conducted in a question-and-answer mode. In most automated ones - similarly, it is just possible to specify a pre-prepared answer file.

Writing an installer is not a trivial task. This was always known to the guys from the Gentoo project , in which it had never happened before, and in the Arch Linux community, recently decided to abandon the installer support in favor of more urgent tasks. Even Microsoft understood this - the second step in the Windows installer starting with Vista comes down to rolling an already-assembled image. In other matters, we are not talking about windows; this is the topic of another article.

By installing the OS manually, we have complete freedom of action at all stages. This article is naturally not the only correct instruction, it is a scenario for installing a "spherical server in a vacuum." Specific tasks and conditions can significantly affect any of the steps. As an example, we will install Oracle Enterprise Linux 6 on a virtual machine running Microsoft Hyper-V . Not the loosest combination of course, but that's not the point. By the way, this installation method does not require registration with Oracle. And to the purists and adherents of Comrade Stallman I suggest using KVM and installing CentOS or Scientificwhich are almost 1: 1 RHEL clones so there is practically no difference in installation for them. OEL does not have many unique nuances. In addition to its kernel-uek, Oracle Linux also offers the core of its Django Fett , in which there is paravirtual firewood for Hyper-V devices and PnP probros drives.

For installation, in principle, any Linux or LiveCD is suitable, rpm and yum are available for many platforms. But since we will have RHEL, it is most convenient to use a fresh LiveCD of an RHEL-like distr of the same major version. It will definitely have rpm and yum compatible versions, which greatly simplifies the task. I chose CentOS LiveCD , which can be downloaded from the nearest mirror .

1. Preparing system storage


In this example, the system storage will be a virtual disk of 10 Gb connected to the VMke. We will give all the space except a small section for the bootloader to LVM , which I consider the most stable volume management system on the Linux platform. We boot

from our LiveCD and climb into the terminal. If you plan to work with the virtual machine itself, it is convenient to use the LiveCD graphical download mode. There is even Firefox, of course, not the latest.
But if we are already tuned to minimalism, well, or the machine does not have much RAM, we are loaded into text mode, which can be selected in the bootloader. Raise the ssh server to be able to work in the terminal from your machine. For access, you will need to change the root password and disable or configure the firewall.
$ sudo su
# service sshd start
# passwd root
# service iptables stop

We split our disk using fdisk , (parted, Red Hat Disk utility, hex editor, as you like :) into the necessary sections. Personally, I like the time-tested fdisk. RHEL is a conservative system, fdisk, by default, works in compatibility mode with the Historical heritage, so start it with special flags.

# fdisk -cu / dev / sda

Create a 500M partition for the bootloader. This is a huge size for the boot partition, but we do not mind.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, + sectors or + size {K, M, G} (2048-20971519, default 20971519): + 500M

We set a “bootable” flag for it, so that the first stage of the bootloader knows exactly where to load it.
Command (m for help): a
Partition number (1-4): 1

The rest of the space is given to the second partition,
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First sector (1026048-20971519, default 1026048):
Using default value 1026048
Last sector, + sectors or + size {K, M, G} (1026048-20971519, default 20971519):
Using default value 20971519

which, to simplify the definition of LVM groups at the boot stage, set type 8e (Linux LVM)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list): 8e


Create a file system for / boot. There are many fs from which the standard for the army of RHEL-clones GRUB can load. Enough even old women ext2 , the log on the boot partition is not really needed - writing to it occurs only when installing new kernels and changing the bootloader configuration. I chose ext4 . Additionally, we specify a label for the new fs, which can then be used in mount and fstab .

# mkfs.ext4 / dev / sda1
# e2label / dev / sda1 boot

We prepare LVM on which our system will live
# pvcreate / dev / sda2
# vgcreate system / dev / sda2


In the created group, select the root partition in 4G. This is more than enough for a minimal system, we will give 1G to swap, which, together with the new sections, we will mount it on the Live system. The rest of the space gives you the freedom to create additional fs for / opt or / var, and you can also leave a margin, which will allow you to use LVM snapshots

# lvcreate -n root -L 4G system
# mkfs.ext4 / dev / system / root
# e2label root! $
# lvcreate -n swap –L 1G system
# mkswap -f / dev / system / swap
# swapon! $
# mkdir - p / mnt / system / boot
# mount LABEL = root / mnt / system
# mount LABEL = boot / mnt / system / boot

2. Installation and configuration of system components


Information about all installed rpm packages is stored in a special database. For both rpm and yum, you can specify an alternative root fs, which allows us to install RHEL in any directory with a minimum number of commands. RPMDB - RHEL spine, create it for the new system.

# rpm --root = / mnt / system –initdb


The sources of installation packages for yum are package repositories, the links to which are in the /etc/yum.repos.d/ configs. Such a connection can be any public repository accessible via the Internet, your own, mounted from a network storage, or, if you have images of installation disks available, you can use them. Like this:

# yum install createrepo
# mkdir -p / mnt / iso / {1,2,3}
# mount -o loop /mnt/nas/install/oel-6.4-cd{1,2,3►.iso / mnt / iso / {1,2,3}
# createrepo / mnt / iso


If we want to install CentOS, it’s enough to explicitly specify $ releasever in existing .repo files. These variables are taken from the distribution package of the distribution, which is not yet in the new system, so you have to sed a little bit

# sed -i.orig 's / $ releasever / 6 / g' /etc/yum.repos.d/*.repo


I need OEL, so yum will be configured on Oracle public repository
# mv /etc/yum.repos.d{,.orig}
# mkdir /etc/yum.repos.d
# cd! $
# wget public-yum.oracle.com/public-yum-ol6.repo


You can begin to install the system. Let's start with a completely "rudimentary" set of packages: the release package, glibc, bash and their dependencies:

# yum --installroot = / mnt / system install oraclelinux-release glibc bash


Such a system is already ready to run as a chroot from any Linux. But we have other plans, so we put rpm and yum there with all the dependencies:

# yum --installroot = / mnt / system install rpm yum


The remaining packages will be installed already in the new system. Copy the settings for dns, yum repositories. Bind the virtual fs of our Live environment to similar system paths and enter it.

# cd / mnt / system
# cp /etc/resolv.conf ./etc/
# cp /etc/yum.repos.d/*.repo ./etc/yum.repos.d/

# mount -o bind / dev. / dev
# mount -o bind / sys ./sys
# mount -o bind / proc ./proc

# chroot ./


The first thing we see is a standard bash invitation. To make RHEL normal, copy the bash settings from / etc / skel.
bash-4.1 # cp /etc/skel/.bash* / root /
bash-4.1 # source /root/.bashrc


Let's put some basic software:
  • dhclient, among the dependencies of which (in addition to the OS logos in OEL :) there is also udev, an initialization system, and even a firewall, which in one fell swoop will bring our system to independence
  • cronie scheduler that pulls postfix with it as an MTA and rsyslog logger
  • less, which, passwd, nc, telnet, which, man
  • favorite shell, editor, other software of your choice

the set of software in the basic RHEL repositories is very limited, but fortunately there is an EPEL that is designed to solve this problem:
rpm -i www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
yum install passwd dhclient openssh cronie vim-minimal netcat telnet less which htop tmux less zsh figlet


Since we use LVM, at any time during the installation (for example, now) we can take a snapshot of our fs - which will be a block cast of the base RHEL, or stage3 in Gentoo terminology. It can be dumped to another repository. Or create a snapshot fs archive by mounting it. Based on such a snapshot with minimal effort, you can create templates for OpenVZ and similar systems. All this is best done outside of chroot:
(livecd) # lvcreate -L1G -s -nstage3 system / root

(livecd) # xz / dev / system / stage3> /mnt/nas/templates/OEL6.4-minimal.bin.xz

(livecd) # mkdir / mnt / stage3
(livecd) # mount / dev / system / stage3! $
(livecd) # cd! $
(livecd) # tar -zvpf /mnt/nas/templates/OEL6.4-minimal.tar.gz ./


Prepare a table of file systems. It is most reliable to specify the root path in the form of a virtual device LVM, since it solves the potential problems with naming when changing the configuration of the machine’s disk system by design.

# vi / etc / fstab
LABEL = boot / boot ext4 noauto 1 1
/ dev / mapper / system-root ext4 defaults 1 2

Set up the network by creating configuration files, as the anaconda installer usually does.
# vi / etc / sysconfig / network
NETWORKING = yes
HOSTNAME = spoon.matrix.local

# vi / etc / sysconfig / network-scripts / ifcfg-eth0
DEVICE = eth0
BOOTPROTO = dhcp
ONBOOT = yes

Create a new user with sudo rights and specify a password for him.
useradd -u1337 -m -s / bin / zsh -G wheel morpheus
# echo "morpheus ALL = (ALL) ALL" >> /etc/sudoers.d/morpheus
# passwd morpheus

Set up a local time zone.
# ln -sf / usr / share / zoneinfo / Europe / Riga / etc / localtime

Put a greeting in motd.
# echo " there is no "> / etc / motd
# figlet -f mini spoon >>! $

Further, in principle, we can already configure the machine for the working task at our discretion, but I prefer to boot from it first:

3. Preparing the system for self-loading


Mount the boot partition and install the bootloader, its configuration manager, LVM management tools and the kernel
# mount / boot
# yum install grub grubby lvm2 kernel

So that grubby can register the kernel itself in the bootloader config, a little work remains to be done. In addition to the symlink to the GRUB config, he needs at least one working record in the config, which is used as a template. In a system installed in the standard way, the initial template is generated by anaconda. We will have to prepare the config manually, specifying the newly installed kernel and the necessary parameters for it. For example, quiet will remove the excessive "verbosity" of the kernel, and rhgb will launch a fake progress bar.
# cd / etc
# ln -sf ../boot/grub/grub.conf
# cd / boot
# ln -sf grub.conf menu.lst
# vi grub.conf
timeout = 5
splashimage = (hd0,0) / grub / splash.xpm.gz
hiddenmenu
title Linux
root (hd0,0)
kernel /vmlinuz-2.6.32-358.6.2.el6.x86_64 ro lvm root = / dev / mapper / system-root LANG = en_US.UTF-8
initrd / initramfs-2.6.32-358.6.2.el6.x86_64.img

Reinstall the kernel to make sure that grubby is working and kernel updates in the future will be correctly added to the config. After that, we can delete the entry with our example from the config:
# yum reinstall kernel
# vi grub.conf

Install the bootloader on our disk
# grub-install / dev / sda --no-floppy

If for some reason the installation script did not work, grub can be manually installed on disk
# grub
grub> root (hd0,0)
grub> setup (hd0)

We reboot into our system and begin 4. Setting up the system for work tasks . Their.

This creates sharpened templates for servers. Both universal, under the tear of automation systems, and target, ready for deployment with a minimum configuration.

Also popular now: