Skip navigation.
Reports from the fronline in IT

Fast image of a CentOS server

I've got a linux server to build and want to use an image from a server that I've already built. The setup is fairy standard ( well for the servers that I'm using now ).

LVM on software raid 1 across two hard disks.

Items that were used:
2 Gbyte USB key
CentOS 5 recovery CD

Attach the USB key and boot the server from the CentOS 5 installation CD 1. When the boot prompt is displayed select to boot the recovery image

linux rescue

Skip loading the network drivers and also skip examining the hard drives for a install to mount as there is nothing there.

Partition the hard drives

We will create the same partition tables across both of the disks.

partiton 1 50 Mbytes
partiton 2 160 Mbytes

fdisk /dev/sda
n
p
1
50M
n
p
1
160M
p
t
1
fd
t
2
fd
w

fdisk /dev/sdb
n
p
1
50M
n
p
1
160M
p
t
1
fd
t
2
fd
w

Configure the raid 1 MD devices

mdadm --create md0 --level 1 --raid-devices 2 /dev/sda1 /dev/sdb1
mdadm --create md1 --level 1 --raid-devices 2 /dev/sda2 /dev/sdb2

Make the boot file system

mkfs.ext3 /dev/md0

Configure LVM

lvm pvcreate /dev/md1
lvm vgcreate vg00 /dev/md1
lvm lvcreate --name lv_root --size 5G vg00
lvm lvcreate --name lv_swap --size 1.5G vg00
lvm lvcreate --name lv_data --size 35G vg00

Restore from tar image

Restore the image of the server that I'd made previously, this was taken with star and included the switches for selinux as per the Red Hat guide.

star -xattr -H=exustar -czf /tmp/server.tgz .

I'm not sure if we need to use the flags on the restore ( the tar version knows about them on CentOS 5 ) but I've included them anyway.

tar -xz --selinux --xattr -f /mnt/image/server.tgz

To check that the selinux use the -Z switch to ls to display the security context

ls -Z

You should see the security contexts displayed on the restored files

drwxr-xr-x root root system_u:object_r:bin_t:s0 bin
drwxr-xr-x root root system_u:object_r:boot_t:s0 boot
drwxr-xr-x root root system_u:object_r:device_t:s0 dev
drwxr-xr-x root root system_u:object_r:etc_t:s0 etc
drwxr-xr-x root root system_u:object_r:home_root_t:s0 home
drwxr-xr-x root root system_u:object_r:lib_t:s0 lib
drwx------ root root system_u:object_r:lost_found_t:s0 lost+found
...

Installation of the GRUB boot loader

We will need a working /dev file system so we'll do some setup before we get started. If we put a tmpfs filesystem onto the local restore/dev directory we can then chroot and everything will be correct locally.

mount -t tmpfs /mnt/restore/dev
cd /dev
tar cf- . | ( cd /mnt/restore/dev; tar xf - )

cd /mnt/restore
chroot .

Now we can do the grub install and we're ready to go.

grub
device (hd0) /dev/sda
root (hd0,0)
setup (hd0)

device (hd0) /dev/sdb
root (hd0,0)
setup (hd0)

exit