This guy couldn't find any instructions on how to create a CentOS 6 AMI but then fails to provide necessary details in his howto.
""I used PV-Grub, which boots into a mini Xen OS first, using one of the Amazon supplied kernels. It then boots the kernel inside the AMI, which happens to be the native kernel supplied with CentOS 6.""
So here are my steps - in as much detail as I recorded - maybe I need to add a bit more explanation to some of the steps so one does not follow them blindly:
- Start an EC2 instance, preferably a Redhat/CentOS 6, as it already has the tools needed.
- used CentOS ami-697bae00
- used defaults for kernel (aki-8e5ea7e7), ram disk etc
- Create a 5GB EBS and attach it to the running instance
- vol-xxxxxxx (note volume id)
- /dev/sdf
- Format (labeling it) and mount the partition, creating a few skeleton directories
- cat /proc/partitions (to verify what dev our volume was attached to .. newer/XEN kernels rename them)
- parted /dev/xvdj
- mklabel msdos
- mkpart primary ext4 1 -1
- set 1 boot on
- quit
- mkfs.ext4 /dev/xvdj1
- mkdir /mnt/ami
- mount /dev/xvdj1 /mnt/ami
- mkdir -p /mnt/ami/{dev,etc,proc,sys}
- Create base devices for the new install
- /sbin/MAKEDEV -v -d /mnt/ami/dev -x console
- /sbin/MAKEDEV -v -d /mnt/ami/dev -x null
- /sbin/MAKEDEV -v -d /mnt/ami/dev -x zero
- Create fstab for the new install
- cp /etc/fstab /mnt/ami/etc/fstab
- mount -t proc proc /mnt/ami/proc
- mount -t sysfs sysfs /mnt/ami/sys
- Install YUM
- mkdir -p /mnt/ami/var/lib/rpm
- rpm --rebuilddb --root=/mnt/ami
- rpm --import --root=/mnt/ami http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
- wget http://mirror.centos.org/centos/6.2/os/x86_64/Packages/centos-release-6-2.el6.centos.7.x86_64.rpm
- rpm -i --root=/mnt/ami --nodeps centos-release-6-2.el6.centos.7.x86_64.rpm
- yum --installroot=/mnt/ami install -y rpm-build yum
- mkdir /mnt/ami/root
- cp -v /mnt/ami/etc/skel/.??* /mnt/ami/root
- mount --bind /proc /mnt/ami/proc
- mount --bind /dev /mnt/ami/dev
- cp /etc/sysconfig/network /mnt/ami/etc/sysconfig/network
- cp -v /etc/resolv.conf /mnt/ami/etc/resolv.conf
- chroot /mnt/ami/ su -
- cp /etc/fstab /etc/mtab
- yum clean all
- yum groupinstall base
- yum groupinstall core
- exit
- cp -v /etc/sysconfig/network-scripts/ifcfg-eth0 /mnt/ami/etc/sysconfig/network-scripts/ifcfg-eth0
- Enable fetching of assigned ssh keypair from instance user data at boot time
- cp /etc/rc.local /mnt/ami/etc/rc.local
- Disable DNS checks and allow root to log into SSH (as in original AMI we started from)
- cp /etc/ssh/sshd_config /mnt/ami/etc/ssh/sshd_config
- [?? STILL TRUE ??] Disable (as it screws up with Xen) selinux in /mnt/ami/etc/selinux/config
- cp /etc/selinux/config /mnt/ami/etc/selinux/config
- Configure GRUB "ghost" to satisfy PV-GRUB (menu.lst link to grub.conf pointing to kernel & initramfs)
- \rm -r /mnt/ami/boot/grub
- cp -r /boot/grub /mnt/ami/boot/grub/
- Update initramfs
- chroot /mnt/ami/ su -
- cd /boot
- mv initramfs-2.6.32-220.2.1.el6.x86_64.img orig_initramfs-2.6.32-220.2.1.el6.x86_64.img
- mkinitrd --force initramfs-2.6.32-220.2.1.el6.x86_64.img 2.6.32-220.2.1.el6.x86_64
- With the AMI completed, time to sync and unmount the drive (verify unmounts via "cat /etc/mtab")
- sync
- umount /mnt/ami/dev
- umount /mnt/ami/proc
- umount /mnt/ami/sys
- umount /mnt/ami
- Create a snapshot of the EBS volume
- Create an AMI from snapshot (root/block device MUST be /dev/sda NOT default of /dev/sda1)
- kernel: aki-8e5ea7e7
- arch: x86_64
- root: /dev/sda
Great. Thanks for this info. Just one mistake in the the Step 6, on the 5, it should be centos-release-6-2.el6.centos.7.x86_64.rpm instead of centos-release-6-2.el6.centos.7.i686.rpm.
ReplyDeleteStep 24 you need to exit out at the end.
ReplyDelete