Linux/Xen/DomU/CentOS/CentOS 7

From Guungle
Jump to navigation Jump to search

CentOS 7

The CentOS 7 installer won't install to a disk smaller then 10-20GB but its still possible to copy the finished install into a smaller image for easier distribution and cloning.

Create a empty image file and format it with xfs. We are making the file 20GB so CentOS will install.

dd if=/dev/zero of=centos_ks.img bs=1M count=1 seek=20000
mkfs.xfs centos_ks.img

The easiest way to install CentOS is using the kickstart system. You will need a webserver to host the kickstart config file. You will also need a kernel and ramdisk image from a CentOS mirror.

Download the vmlinuz and initrd.img files from your favorite CentOS mirror.

http://mirror.centos.org/centos/7/os/x86_64/images/pxeboot/

You will be booting the CentOS kickstart image with these files.

Here is the kickstart config that will need to be put on a webserver.

#version=1.0.0

install

# System authorization information
auth --enableshadow --passalgo=sha512
# Use network installation
url --url="http://mirror.centos.org/centos/7/os/x86_64/"
# Use text mode install
text
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=xvda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts=''
# System language
lang en_US.UTF-8

# Network information
network --hostname=centos7 --bootproto=dhcp --device=eth0 --onboot=on

# Root password
rootpw --iscrypted $6$QgAmrd86o3M8qQIa$0LMJo9zwIe3j1e.hnc5G.6bXyhduRF03McofIDGSb7lrso6mbl9kt.WzxYOCXysC4Fb6Rdlu8OkXNAL22BLUW0
# System services
services --enabled="network"
# Do not configure the X Window System
skipx
# System timezone
timezone Etc/UTC --isUtc
# System bootloader configuration
bootloader --timeout=5 --driveorder=xvda --append="console=hvc0"
# Partition clearing information
zerombr
clearpart --all --initlabel --drives=xvda
part / --fstype=xfs --grow --size=1 --asprimary --ondisk=xvda

# Shutdown when the kickstart is done
halt

%packages
@core --nodefaults
-grub2
-chrony
-NetworkManager
-NetworkManager-team
-NetworkManager-tui
-NetworkManager-libnm
-wireless-tools
-plymouth
-fprintd-pam
-*-firmware


%end

%addon com_redhat_kdump --disable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

Kickstart Xen Config

Once you have the kickstart config file on a webserver you need to create a new Xen config file that will be used to install the base image.

The Xen config will look something like this. You will need to edit the "disk", "kernel" and "ramdisk" paths to match where you are storing the files. Also in the "extra" section, "inst.ks" will be the URL to the kickstart config file.

name="centos7ks"
vcpus=2
memory=2048
disk=['file:/mnt/xen_images/centos/centos_ks.img,xvda,w' ]
vif=['bridge=xenbr0']
on_reboot="restart"
on_crash="restart"
kernel="/mnt/xen_images/centos/x86_64/vmlinuz"
ramdisk="/mnt/xen_images/centos/x86_64/initrd.img"
extra="inst.repo=http://mirror.centos.org/centos/7/os/x86_64/ ip=eth0:dhcp inst.ks=http://192.168.1.80/kickstart/centos_domu.cfg"

If you are not using DHCP you can set a static IP in the "extra" section like this,

extra="inst.repo=http://mirror.centos.org/centos/7/os/x86_64/ ip=192.168.1.20::192.168.1.1:255.255.255.0:centos7ks:eth0:none nameserver=192.168.1.1 inst.ks=http://192.168.1.80/kickstart/centos_domu.cfg"