Slackware custom amazon AMI from scratch 16-06-2014

Summary:

Sometimes ago, I tried to find a Slackware AMI. Unfortunately, I couldn't find any images. So I aimed to build up it myself. After searching the internet, I found a couple of resources which explains how to do it for some other distributions but not for Slackware. So I want to share my practice with others. Below you can find step by step process  of building a Slackware amazon ec2 image from scratch.

Prerequisites:

Linux host machine; Slackware 13.1 installation media,  Amazon AWS account, installed Amazon API and AMI tools

Steps:

1. Create a working directory

# mkdir /tmp/amiworks

2.  Prepare installation target

Create an image file (~ 8Gb)

# dd if=/dev/zero of=/tmp/amiworks/img-slackware bs=16M count=$((64*8))

Create a filesystem on the image

# mke2fs -F -j /tmp/amiworks/img-slackware

Create a mount point and mount the image to there

# mkdir /tmp/amiworks/fs-slackware
# mount -o loop /tmp/amiworks/img-slackware /tmp/amiworks/fs-slackware

Partitioning the loop device (here it's our image). And remount the image in order to activate new settings

# fdisk /dev/loop0
    n
    p
    1
    [Enter]
    [Enter]
    w
# mount -o remount /tmp/amiworks/fs-slackware

3. Installing Slackware

Either insert installation media or mount the iso file to fs. (I used first one)

# cd [path to SlackDVD]/slackware

change ROOT path and install packages (this step is really important. If you skip it, then you mess up your host machine.) . Allow full installation under the package groups: a ap d f k l n t tcl and x. I know that some are not needed but I didn't have time to filter out them. (In future I may work on it) The packages under  t, tcl and x are important since they are needed for installing xen kernel.

# export ROOT=/tmp/amiworks/fs-slackware/
# for i in `ls -F1 | grep /`; do cd $i && ./install-packages && cd ..; done
... ... ...

Install grub and finalize preparation

# cd ../extra/grub
# installpkg grub-0.97-i486-9.txz
# cd
# unset ROOT

 

4. Installing xen kernel

Create a working directory

# mkdir /tmp/amiworks/xen-kernel
# cd /tmp/amiworks/xen-kernel

Before install the kernel We need to populate all required files and prepare them for the installation process. These are xen packages for 13.1 from slackbuild.org,
acpica package which is required for xen kernel installation and again can be downloaded from slackbuild.org
and files for dom0 install script.
Please, for the time being, don't execute any installation scripts. We have to do that at a later time on the image file. The host machine and the image may have different operation systems or versions

# wget http://slackbuilds.org/slackbuilds/13.1/development/acpica.tar.gz
# tar zxvf acpica.tar.gz
# cd acpica
# wget http://www.acpica.org/download/acpica-unix-20100915.tar.gz
# cd ../
# wget http://slackbuilds.org/slackbuilds/13.1/system/xen.tar.gz
# tar zxvf xen.tar.gz
# cd xen
# wget http://bits.xensource.com/oss-xen/release/4.0.1/xen-4.0.1.tar.gz

And for dom0's install script, two required files we need so get them by using internet addresses in the readme file.

# cd dom0/
# wget http://gentoo-xen-kernel.googlecode.com/files/xen-patches-2.6.34-6.tar.bz2
# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.34.7.tar.bz2
# cd /tmp

Move all of them to the image filesystem

# mv /tmp/amiworks/xen-kernel/ /tmp/amiworks/fs-slackware/tmp/

Change root directory, and modify the PATH of the environment for image filesystem

# chroot /tmp/amiworks/fs-slackware/ /bin/bash
# PATH=/usr/share/texmf/bin:$PATH

Install xen package

# cd /tmp/xen-kernel/acpica
# ./acpica.SlackBuild
# installpkg /tmp/acpica-20100915-i486-1_SBo.tgz
# cd ../xen
# ./xen.SlackBuild
# installpkg /tmp/xen-4.0.1-i486-1_SBo.tgz

Run the dom0 script.

# cd dom0/
# tar -C /usr/src/ -jxf linux-2.6.34.7.tar.bz2
# BOOTLOADER=grub sh ./kernel-xen.sh

5. After install steps.

set the root password and leave the image root directory of the image

# passwd root
# exit

make sure that DHCP is active (edit /etc/rc.d/rc.inet1 file: USE_DHCP[0]="YES" is sufficient. )

create the fstab file as

/dev/sda1 / ext3 defaults 1 1
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
/dev/sda2 /mnt ext3 defaults 0 0
/dev/sda3 swap swap defaults 0 0 

Clean up all the temp files for the image file

# rm -r /tmp/amiworks/fs-slackware/tmp/xen*
# rm /tmp/amiworks/fs-slackware/tmp/acpica-20100915-i486-1_SBo.tgz 
# rm -r /tmp/amiworks/fs-slackware/tmp/SBo/
# umount -d /tmp/amiworks/fs-slackware/

6. Prepare Amazon Image

In order to create an AMI you need amazon ec2 ami and api tools, an amazon account and the account number(like 111222333444 without hyphen), private key and certificate files.
The x509 certificate files can be created and downloaded easily from AWS management console (under the access credential menu).

# ec2-bundle-image -i /tmp/amiworks/img-slackware -k pk-privatekeyfile.pem -c cert-certificatefile.pem -u 111111111111
      specify a value for arch [unknown]:

type i386 and hit the enter.

Before upload the files to Amazon AWS, you need to create a bucket at S3 service. I created a bucked named Slackware-images. Again access and secret keys can be obtained from access credential menu of AWS management console.

# ec2-upload-bundle -b slackware-images -m /tmp/img-slackware.manifest.xml -a -s
# ec2-api-tools-1.6.6.3/bin/ec2-register slackware-images/img-slackware.manifest.xml -n slackware-13.1-v.1

Clear working directory

# rm -r /tmp/amiworks

With these last steps, we created ami image, uploaded it to Amazon AWS and registered it as an AMI. Now one can use it as an instance

Note: When initiate a new instance at AWS/EC2 from this image choose the kernel named as aki-f5cbe081.

Last words

Hope this explanations will help you. All comments, corrections etc are welcome. My email address is soydaner{at]kahverengi[dot]com.

I will also make this image to public at AWS but please be aware that this image is not suited for production environment but for educational purposes only.

Used Resources

-  Building a root Slackware filesystem from scratch for the User-Mode Linux through loopback devices 

-  Bundling Amazon S3-Backed Linux/UNIX AMIs From a Loopback