From: "Brian C. Lane" bcl@redhat.com
AMI images are un-partitioned filesystem images with a grub.conf that is read by the pv-grub bootloader used by EC2. Most of the actual work making the AMI is done in the kickstart. This just creates the image file. --- src/sbin/livemedia-creator | 41 ++++++++++++++++++++++++++++++----------- 1 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/src/sbin/livemedia-creator b/src/sbin/livemedia-creator index 23c9b3f..e91c050 100755 --- a/src/sbin/livemedia-creator +++ b/src/sbin/livemedia-creator @@ -46,7 +46,7 @@ from pykickstart.version import makeVersion from pylorax.base import DataHolder from pylorax.treebuilder import TreeBuilder, RuntimeBuilder, udev_escape from pylorax.sysutils import joinpaths, remove, linktree -from pylorax.imgutils import PartitionMount, mksparse +from pylorax.imgutils import PartitionMount, mksparse, mkext4img from pylorax.executils import execWithRedirect, execWithCapture
@@ -406,6 +406,23 @@ def get_kernels( boot_dir ): return [f[8:] for f in files if f.startswith("vmlinuz-")]
+def make_ami( disk_img, ami_img="ami-root.img", ami_label="AMI" ): + """ + Copy the / partition to an un-partitioned disk image + + ami_img is the filename to write, defaults to ami-root.img + ami_label is the FS label to apply to the image + + All other AMI setup is handled by the kickstart's %post + """ + with PartitionMount( disk_img ) as img_mount: + work_dir = tempfile.mkdtemp() + log.info("working dir is {0}".format(work_dir)) + log.info("creating {0}".format(ami_img)) + mkext4img(img_mount.mount_dir, joinpaths(work_dir, ami_img), label=ami_label) + return work_dir + + def make_livecd( disk_img, squashfs_args="", templatedir=None, title="Linux", project="Linux", releasever=16 ): """ @@ -423,6 +440,9 @@ def make_livecd( disk_img, squashfs_args="", templatedir=None,
""" with PartitionMount( disk_img ) as img_mount: + if not img_mount or not img_mount.mount_dir: + return None + kernel_list = get_kernels( joinpaths( img_mount.mount_dir, "boot" ) ) log.debug( "kernel_list = {0}".format(kernel_list) ) if kernel_list: @@ -592,7 +612,7 @@ if __name__ == '__main__': log.error("You need to run this as root") sys.exit( 1 )
- if not os.path.exists( opts.lorax_templates ): + if opts.make_iso and not os.path.exists( opts.lorax_templates ): log.error( "The lorax templates directory ({0}) doesn't" " exist.".format( opts.lorax_templates ) ) sys.exit( 1 ) @@ -614,10 +634,6 @@ if __name__ == '__main__': log.error( "--make-appliance is not yet implemented." ) sys.exit( 1 )
- if opts.make_ami: - log.error( "--make-ami is not yet implemented." ) - sys.exit( 1 ) - if not opts.no_virt and not opts.iso and not opts.disk_image: log.error( "virt-install needs an install iso." ) sys.exit( 1 ) @@ -701,13 +717,16 @@ if __name__ == '__main__': result_dir = make_livecd( opts.disk_image or disk_img, opts.squashfs_args, opts.lorax_templates, opts.title, opts.project, opts.releasever ) + elif opts.make_ami and not opts.image_only: + result_dir = make_ami(opts.disk_image or disk_img)
- if not opts.keep_image and not opts.disk_image: - os.unlink( disk_img ) + # cleanup the mess + if disk_img and not opts.keep_image and not opts.disk_image: + os.unlink( disk_img )
- if opts.result_dir: - shutil.copytree( result_dir, opts.result_dir ) - shutil.rmtree( result_dir ) + if opts.result_dir and result_dir: + shutil.copytree( result_dir, opts.result_dir ) + shutil.rmtree( result_dir )
log.info("SUMMARY") log.info("-------")
From: "Brian C. Lane" bcl@redhat.com
--- src/sbin/livemedia-creator | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/sbin/livemedia-creator b/src/sbin/livemedia-creator index e91c050..dc5ff09 100755 --- a/src/sbin/livemedia-creator +++ b/src/sbin/livemedia-creator @@ -332,10 +332,10 @@ class VirtualInstall( object ): extra_args = "ks=file:/{0}".format(os.path.basename(ks_paths[0])) if kernel_args: extra_args += " "+kernel_args - if not vnc: - extra_args += " console=/dev/ttyS0" if iso.liveos: extra_args += " root=live:CDLABEL={0}".format(udev_escape(iso.label)) + if not vnc: + extra_args += " console=ttyS0" cmd.append("--extra-args") cmd.append(extra_args)
From: "Brian C. Lane" bcl@redhat.com
currently untested on EC2, but it builds an image that looks like it should work. --- docs/fedora-livemedia-ec2.ks | 119 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 119 insertions(+), 0 deletions(-) create mode 100644 docs/fedora-livemedia-ec2.ks
diff --git a/docs/fedora-livemedia-ec2.ks b/docs/fedora-livemedia-ec2.ks new file mode 100644 index 0000000..469da7f --- /dev/null +++ b/docs/fedora-livemedia-ec2.ks @@ -0,0 +1,119 @@ +# Build a basic Fedora AMI using livemedia-creator +lang en_US.UTF-8 +keyboard us +timezone --utc America/New_York +auth --useshadow --enablemd5 +selinux --enforcing +firewall --service=ssh +bootloader --location=none +network --bootproto=dhcp --device=eth0 --onboot=on --activate +services --enabled=network,sshd,rsyslog +shutdown + +# By default the root password is emptied +rootpw --plaintext removethispw + +# +# Define how large you want your rootfs to be +# NOTE: S3-backed AMIs have a limit of 10G +# +zerombr +clearpart --all +part / --size 10000 --fstype ext4 --ondisk sda +part biosboot --size=1 +part swap --size=512 + +# +# Repositories +url --url="http://dl.fedoraproject.org/pub/fedora/linux/development/17/x86_64/os/" + +# +# +# Add all the packages after the base packages +# +%packages --nobase +@core +system-config-securitylevel-tui +audit +pciutils +bash +coreutils +kernel + +e2fsprogs +passwd +policycoreutils +chkconfig +rootfiles +yum +vim-minimal +acpid +openssh-clients +openssh-server +curl +sudo + +#Allow for dhcp access +dhclient +iputils + +-firstboot +-biosdevname + +# package to setup cloudy bits for us +cloud-init + +grub +%end + +# more ec2-ify +%post --erroronfail + +# create ec2-user +/usr/sbin/useradd ec2-user +/bin/echo -e 'ec2-user\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers + +# fstab mounting is different for x86_64 and i386 +cat <<EOL > /etc/fstab +/dev/xvda1 / ext4 defaults 1 1 +/dev/xvda2 /mnt ext3 defaults 0 0 +/dev/xvda3 swap swap defaults 0 0 +EOL + +if [ ! -d /lib64 ] ; then +# workaround xen performance issue (bz 651861) +echo "hwcap 1 nosegneg" > /etc/ld.so.conf.d/libc6-xen.conf +fi + +# Install grub.conf +# idle=nomwait is to allow xen images to boot and not try use cpu features that are not supported +INITRD=`ls /boot/initramfs-* | head -n1` +KERNEL=`ls /boot/vmlinuz-* | head -n1` +mkdir /boot/grub +pushd /boot/grub +cat <<EOL > grub.conf +default 0 +timeout 0 + +title Fedora Linux + root (hd0) + kernel $KERNEL root=/dev/xvda1 idle=halt + initrd $INITRD +EOL +# symlink grub.conf to menu.lst for use by EC2 pv-grub +ln -s grub.conf menu.lst +popd + +# the firewall rules get saved as .old without this we end up not being able +# ssh in as iptables blocks access +rename -v .old "" /etc/sysconfig/*old + +# setup systemd to boot to the right runlevel +rm /etc/systemd/system/default.target +ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target + +# remove the root password +passwd -d root > /dev/null + +%end +
From: "Brian C. Lane" bcl@redhat.com
--- README.livemedia-creator | 25 ++++++++++++++++++++----- docs/fedora-livemedia.ks | 3 ++- 2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/README.livemedia-creator b/README.livemedia-creator index efbce9c..630f639 100644 --- a/README.livemedia-creator +++ b/README.livemedia-creator @@ -116,12 +116,12 @@ the repo each time you run it. To speed things up you either need a local mirror of the packages, or you can use a caching proxy. When using a proxy you pass it to livemedia-creator like so:
---kernel-args="proxy=http://proxy.yourdomain.com:3128" +--proxy=http://proxy.yourdomain.com:3128
You also need to use a specific mirror instead of mirrormanager so that the -packages will get cached: +packages will get cached, so your kickstart url would look like:
-url --url="http://download.fedora.redhat.com/pub/fedora/linux/development/16/x86_64/os/" +url --url="http://dl.fedoraproject.org/pub/fedora/linux/development/17/x86_64/os/"
You can also add an update repo, but don't name it updates. Add --proxy to it as well. @@ -154,6 +154,21 @@ Example cmdline: sudo livemedia-creator --make-iso --no-virt --ks=./fedora-livemedia.ks
+AMI IMAGES +---------- +Amazon EC2 images can be created by using the --make-ami switch and an appropriate +kickstart file. All of the work to customize the image is handled by the kickstart. +The example currently included was modified from the cloud-kickstarts version so +that it would work with livemedia-creator. + +Example cmdline: +sudo livemedia-creator --make-ami --iso=/path/to/boot.iso --ks=./docs/fedora-livemedia-ec2.ks + +This will produce an ami-root.img file in the working directory. + +At this time I have not tested the image with EC2. Feedback would we welcome. + + DEBUGGING PROBLEMS ------------------ Cleaning up an aborted (ctrl-c) virt-install run (as root): @@ -177,8 +192,8 @@ the anaconda-cleanup script.
THE FUTURE ---------- -The current release only supports creating live iso's. In the future -I want it to be able to create ami images as well as appliance images. +The current release supports creating live iso's and ami images. In the future +I also want it to be able to create appliance images.
It is also limited to x86 architectures because of it's use of virt-install. I hope to be able to support other arches by using Anaconda's image install diff --git a/docs/fedora-livemedia.ks b/docs/fedora-livemedia.ks index 667b560..752e840 100644 --- a/docs/fedora-livemedia.ks +++ b/docs/fedora-livemedia.ks @@ -3,7 +3,8 @@ sshpw --username=root --plaintext randOmStrinGhERE # Firewall configuration firewall --enabled --service=mdns # Use network installation -url --url="http://download.fedora.redhat.com/pub/fedora/linux/releases/16/Everything/x8..." +url --url="http://dl.fedoraproject.org/pub/fedora/linux/development/17/x86_64/os/" + # X Window System configuration information xconfig --startxonboot # Root password
anaconda-devel@lists.stg.fedoraproject.org