How to create a Fedora 7 Instance for EC2

Now that Fedora 7 is out I figured it was time to update the EC2 instance howto. It is almost exactly the same as creating a FC6 instance so if you want to know the details you can reference that article.

Here is an updated script for creating the AMI the only change between this and the one for FC6 is the yum repo and the image name:

[code lang=”bash”]
#!/bin/sh

dd if=/dev/zero of=fedora7-i386.img bs=1M count=1 seek=1024
/sbin/mke2fs -F -j fedora7-i386.img

mount -o loop fedora7-i386.img /mnt

mkdir /mnt/dev
mkdir /mnt/proc
mkdir /mnt/etc
for i in console null zero ; do /sbin/MAKEDEV -d /mnt/dev -x $i ; done

cat < /mnt/etc/fstab
/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 1 2
/dev/sda3 swap swap defaults 0 0
EOL

mount -t proc none /mnt/proc

cat < /tmp/yumec2.conf
[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
exclude=*-debuginfo
gpgcheck=0
obsoletes=1
reposdir=/dev/null

[base]
name=Fedora Core 6 – i386 – Base
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-7&arch=i386
enabled=1

[updates-released]
name=Fedora Core 6 – i386 – Released Updates
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f7&arch=i386
enabled=1
EOL

yum -c /tmp/yumec2.conf –installroot=/mnt -y groupinstall Base

yum -c /tmp/yumec2.conf –installroot=/mnt -y clean packages

mv /mnt/lib/tls /mnt/lib/tls-disabled

cat <> /mnt/etc/rc.local
if [ ! -d /root/.ssh ] ; then
mkdir -p /root/.ssh
chmod 700 /root/.ssh
fi
# Fetch public key using HTTP
curl http://169.254.169.254/1.0/meta-data/public-keys/0/openssl > /tmp/my-key
if [ $? -eq 0 ] ; then
cat /tmp/my-key >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
rm /tmp/my-key
fi
# or fetch public key using the file in the ephemeral store:
if [ -e /mnt/openssh_id.pub ] ; then
cat /mnt/openssh_id.pub >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
fi
EOL

cat <> /mnt/etc/ssh/sshd_config
UseDNS no
PermitRootLogin without-password
EOL

cat < /mnt/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
EOL

cat < /mnt/etc/sysconfig/network-scripts/ifcfg-eth0
ONBOOT=yes
DEVICE=eth0
BOOTPROTO=dhcp
EOL

sync
umount /mnt/proc
umount /mnt
[/code]

[tags]ec2, fedora 7[/tags]

3 thoughts on “How to create a Fedora 7 Instance for EC2

  1. JetztGradNet

    Hi!

    Thanks for this handy script, I will try it!

    One small thing: the names of the yum repositories still contain “FC 6” (but the urls seem to be ok)…

    Regards,

    JetztGradNet

  2. Bryan Field-Elliot

    I noticed this error while it was installing the kernel:

    Installing: kernel ##################### [223/324]
    error opening /sys/block: No such file or directory
    error opening /sys/block: No such file or directory

    Should we be creating the /sys/block directory before installing?

  3. Blake

    curl http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key > /tmp/my-key

    will work better than:

    curl http://169.254.169.254/1.0/meta-data/public-keys/0/openssl > /tmp/my-key

    If you look at your authorized_keys file, you’ll see a bunch of dorked HTML in there. It happens to work because you grab /mnt/openssh_id.pub and smack it in there. This happens on your Fedora 7 public image that you’ve provided also.

    Other than that, this seemed to work OK. I haven’t done the EC2 image part of this yet, so we’ll see how that goes.

    Thanks for the work.

Comments are closed.