Install Alpine on Amazon EC2: Difference between revisions

From Alpine Linux
No edit summary
No edit summary
Line 3: Line 3:
The goal here is to have a "1GB" (the smallest possible) EBS 'virtual usb stick' that can boot and run Alpine Linux.   
The goal here is to have a "1GB" (the smallest possible) EBS 'virtual usb stick' that can boot and run Alpine Linux.   


= Create a Virtual USB in EBS =
= Create an EBS backed Alpine Linux AMI =


{{Note|You need to do this process at least once in each availability region.  EBS can't be shared between Ireland and California, for instance.}}
{{Note|You need to do this process at least once in each availability region.  EBS can't be shared between Ireland and California, for instance.}}


# Create an Amazon instance in the desired availabity region.  A micro instance is fine - we will need it only long enough to create our EBS usb stick.
* Create an Amazon instance in the desired availabity region.  A micro instance is fine - we will need it only long enough to create our EBS usb stick.
# Create a new EBS volume
* Create a new 1GB EBS volume  
 
* Attach the new volume to the running instance
 
* The new volume will have a name like /dev/xvdf or such
 
* Format the volume as ext4 {{Cmd|mke2fs -t ext4 /dev/xvdf}}  ''Do not partition it - just format the whole volume''
Just transcribing notes from the mailing list.
* wget a '''x86_64''' iso and extract it to the new volume.   32bit will not work.
 
<pre>
wget http://dl-4.alpinelinux.org/alpine/v2.4/releases/x86_64/alpine-2.4.5-x86_64.iso
mkdir target
mkdir source
mount /dev/xvdf target
mount -o loop alpine-2.4.5-x86_64.iso source
cp -av source/boot target
cp -av source/apks target
umount source
</pre>
* Create a grub.conf on the new partition. 
<pre>
<pre>
Date: Sun, 27 May 2012 09:00:47 -0700
mkdir -p target/boot/grub
From: Nathan Angelacos <nangel@alpinelinux.org>
cat - >target/boot/grub/grub.conf <<EOF
Subject: [alpine-devel] Notes on Alpine 2.4.2 in Amazon EC2
 
Just some notes on trying to get Alpine Linux running on an EC2 instance.
 
As of 27 May 2012, The Amazon Linux AMI includes pv-grub, so trying an
alternate kernel is fairly simple:
 
* Start the instance (its some variant of redhat)
* wget the alpine iso and copy the /boot and /apk directories to the
EC2  instance /
* create a apkovl.tar.gz that includes the ssh public keys, starts
openssh, etc.; place the apkovl in /
 
 
The /boot/grub/grub.conf looks like this:
 
default=0
default=0
fallback=1
timeout=3
timeout=3
hiddenmenu
hiddenmenu
Line 40: Line 33:
title Alpine Linux
title Alpine Linux
root (hd0)
root (hd0)
kernel /boot/grsec alpine_dev=xvda1:ext4
kernel /boot/grsec alpine_dev=xvda1:ext4 modules=loop,squashfs,sd-mod,ext4 console=hvc0 pax_nouderef BOOT_IMAGE=/boot/grsec
modules=loop,squashfs,sd-mod,ext4 console=hvc0
initrd /boot/grsec.gz
initrd /boot/grsec.gz
EOF
</pre>
:* Syslinux automatically adds BOOT_IMAGE to the kernel command line; grub does not, so make sure you specify it in the grub.conf
:* You do not need any other grub files - just boot.conf
* symlink the grub.conf to menu.lst
<pre>
ln -sf ./grub.conf target/boot/grub/menu.lst
</pre>
* Create an amazon.apkovl.tar.gz file to put on the target
** This is probably easiest on a local alpine linux instance.  Make sure the following are configured:
*** eth0 uses dhcp
*** networking is set to autostart
*** sshd is installed and set to autostart
*** your ssh public key is in /root/.ssh/authorized_keys
*** the root password is set to something
*** lbu include root/.ssh
*** (optional) - eldete the /etc/ssh/*key* files, so they are created on the new box
** {{Cmd|lbu package amazon.apkovl.tar.gz}} {{Warning|If you are packaging on a 32bit box, manually delete etc/apk/arch from the apkovl.tar.gz file}}
** copy amazon.apkovl.tar.gz to target/
* Unmount target
* '''Do the following from the Amazon web interface'''
** Detach the new volume
** Make note of the volume ID
** Launch NEW instance.  Use defaults, amazon linux, micro; we are going to canibalize it in a bit, so defaults are fine here.
** Once the instance starts, ''stop'' but ''do not terminate'' the instance.
** Under EBS, detach the existing volume, and attach the alpine linux volume as /dev/sda1 (note the 1 at the end)
** Restart the instance
* Log in and make sure it works
* Do any final cleanups necessary, and if necessary lbu ci
** Only make configs that are appropriate for an AMI, we are going to snapshot this instance and create an AMI out of it
* Again from the Amazon web interface
** Delete the 8GB volume that is no longer needed
** ''Stop'' but do not terminate the instance
** right click the stopped instance and choose 'Create Image (EBS AMI)'
*** Image name should be unique for the image - example AlpineLinux-2.4.5
*** Description can be anything - example 'Base AlpineLinux Installation - no services'
* Done.




title Amazon Linux AMI (PV)
root (hd0)
kernel /boot/vmlinuz-3.2.12-3.2.4.amzn1.i686 root=LABEL=/ console=hvc0
initrd /boot/initramfs-3.2.12-3.2.4.amzn1.i686.img
----
What doesn't work:
* Booting the 32bit kernel reports:
  ERROR: Invalid kernel: 'elf_xen_note_check: ERROR: Will only load
images built for the generic loader or Linux images
  xc_dom_oparse_image returned -I
http://wiki.alpinelinux.org/wiki/Talk:Create_Alpine_Linux_PV_DomU says
that's because the kernel uses PVOps and its running on 64 bit
hardware.


* Booting the 64bit kernel reports:
  can only boot x86 32 PAE kernels, not xen-3.0-x86_64
  Error 13: Invalid or unsupported executable format
Date: Tue, 29 May 2012 17:09:56 +0200
From: Natanael Copa <ncopa@alpinelinux.org>
Subject: {SPAM 01.5} Re: [alpine-devel] Notes on Alpine 2.4.2 in Amazon EC2
On Sun, 27 May 2012 09:00:47 -0700
Nathan Angelacos <nangel@alpinelinux.org> wrote:
> * Booting the 64bit kernel reports:
>    can only boot x86 32 PAE kernels, not xen-3.0-x86_64
>    Error 13: Invalid or unsupported executable format
>
I built a kernel dedicated for virtual guests. One of the goals is to
make it as small as possible. I have no idea if it even boots at this
point but feedback is welcome.
I'd like it to include drivers for qemu/kvm, xen, vmware, virtualbox
and hyper-v guests.
It is in edge/testing and is named linux-virt-grsec.
Thanks!
-nc
> Can we see a bootable iso in edge/releases or a wiki help page on how
> to create one. It would be great to have a lighter iso suited for
> virtual guests. I could test using kvm and install/test pmreader on
> it. (http://insteps.net/pr/a/pmwiki/Apps/PmReader-help-v1-1)
I built one for testing
http://dev.alpinelinux.org/~ncopa/alpine/alpine-virt/
>
> Thanks.
I think kernel config might needs some tweaking still.
-nc
Date: Thu, 31 May 2012 18:56:29 -0700
From: Nathan Angelacos <nangel@alpinelinux.org>
Subject: Re: [alpine-devel] Notes on Alpine 2.4.2 in Amazon EC2
Thanks to all for the help - Alpine Linux is now live in the  Amazon
EC2 cloud.  The following isn't pretty (no prepackaged AMI or
anything) - more like duct-tape and fishing line - but its a start.
Pre setup:
  * Set up a local box so that it does
    * dhcp on eth0
    * starts sshd
    * put your public key in /root/.ssh/authorized_keys
    * set the root password
    * lbu include root/.ssh
    * You may wish to delete the /etc/ssh/*key* files, so that they
are created  on the new box
  * lbu package amazon.apkovl.tar.gz
    * IMPORTANT:  If you are building this on a 32bit box, delete
etc/apk/arch from the apkovl.tar.gz file
* Create an instance, use Amazon Linux, *64bit* version
* Copy the amazon.apkovl.tar.gz to the instance
* Log in, sudo
* Move the apkovl.tar.gz to /
* wget the latest alpinelinux *x86_64* iso. 32bit won't work
* Copy alpinelinux to the EBS harddrive
  * mkdir x;
  * mount alpine*.iso x -o loop
  * cd x
  * cp -av apks /
  * cp boot/* /boot
  * cd
* Edit the /boot/grub/grub.conf so that it looks something like this:
> default=0
> fallback=1
> timeout=3
> hiddenmenu
>
> title Alpine Linux
> root (hd0)
> kernel /boot/grsec alpine_dev=xvda1:ext4 modules=loop,squashfs,sd-mod,ext4 console=hvc0 pax_nouderef BOOT_IMAGE=/boot/grsec
> initrd /boot/grsec.gz
>
>
> title Amazon Linux AMI (PV)
> root (hd0)
> kernel /boot/vmlinuz-3.2.12-3.2.4.amzn1.i686 root=LABEL=/ console=hvc0
> initrd /boot/initramfs-3.2.12-3.2.4.amzn1.i686.img
  * syslinux automatically adds the BOOT_IMAGE to the kernel command
line; grub does not.
* Reboot
</pre>


[[Category:Virtualization]]
[[Category:Virtualization]]

Revision as of 22:29, 21 July 2012

This material is work-in-progress ...

Do not follow instructions here until this notice is removed.
(Last edited by Nangel on 21 Jul 2012.)

The goal here is to have a "1GB" (the smallest possible) EBS 'virtual usb stick' that can boot and run Alpine Linux.

Create an EBS backed Alpine Linux AMI

Note: You need to do this process at least once in each availability region. EBS can't be shared between Ireland and California, for instance.
  • Create an Amazon instance in the desired availabity region. A micro instance is fine - we will need it only long enough to create our EBS usb stick.
  • Create a new 1GB EBS volume
  • Attach the new volume to the running instance
  • The new volume will have a name like /dev/xvdf or such
  • Format the volume as ext4

    mke2fs -t ext4 /dev/xvdf

    Do not partition it - just format the whole volume
  • wget a x86_64 iso and extract it to the new volume. 32bit will not work.
wget http://dl-4.alpinelinux.org/alpine/v2.4/releases/x86_64/alpine-2.4.5-x86_64.iso
mkdir target
mkdir source
mount /dev/xvdf target
mount -o loop alpine-2.4.5-x86_64.iso source
cp -av source/boot target
cp -av source/apks target
umount source
  • Create a grub.conf on the new partition.
mkdir -p target/boot/grub
cat - >target/boot/grub/grub.conf <<EOF 
default=0
timeout=3
hiddenmenu

title Alpine Linux
root (hd0)
kernel /boot/grsec alpine_dev=xvda1:ext4 modules=loop,squashfs,sd-mod,ext4 console=hvc0 pax_nouderef BOOT_IMAGE=/boot/grsec
initrd /boot/grsec.gz
EOF
  • Syslinux automatically adds BOOT_IMAGE to the kernel command line; grub does not, so make sure you specify it in the grub.conf
  • You do not need any other grub files - just boot.conf
  • symlink the grub.conf to menu.lst
ln -sf ./grub.conf target/boot/grub/menu.lst
  • Create an amazon.apkovl.tar.gz file to put on the target
    • This is probably easiest on a local alpine linux instance. Make sure the following are configured:
      • eth0 uses dhcp
      • networking is set to autostart
      • sshd is installed and set to autostart
      • your ssh public key is in /root/.ssh/authorized_keys
      • the root password is set to something
      • lbu include root/.ssh
      • (optional) - eldete the /etc/ssh/*key* files, so they are created on the new box
    • lbu package amazon.apkovl.tar.gz

      Warning: If you are packaging on a 32bit box, manually delete etc/apk/arch from the apkovl.tar.gz file

    • copy amazon.apkovl.tar.gz to target/
  • Unmount target
  • Do the following from the Amazon web interface
    • Detach the new volume
    • Make note of the volume ID
    • Launch NEW instance. Use defaults, amazon linux, micro; we are going to canibalize it in a bit, so defaults are fine here.
    • Once the instance starts, stop but do not terminate the instance.
    • Under EBS, detach the existing volume, and attach the alpine linux volume as /dev/sda1 (note the 1 at the end)
    • Restart the instance
  • Log in and make sure it works
  • Do any final cleanups necessary, and if necessary lbu ci
    • Only make configs that are appropriate for an AMI, we are going to snapshot this instance and create an AMI out of it
  • Again from the Amazon web interface
    • Delete the 8GB volume that is no longer needed
    • Stop but do not terminate the instance
    • right click the stopped instance and choose 'Create Image (EBS AMI)'
      • Image name should be unique for the image - example AlpineLinux-2.4.5
      • Description can be anything - example 'Base AlpineLinux Installation - no services'
  • Done.