From Mageia wiki
Jump to: navigation, search
This page has become outdated and can no longer be trusted.

It requires improvements.
If you want to improve it, simply click on the edit tab.
Please remove this {{Outdated}} template when you're sure this page is completely up-to-date and trustworthy again

View the other outdated pages.

View all other pages to improve and maintain.

Pre-built AMIs for Mageia 4

A Mageia 4 AMI has been built on Amazon's cloud service, EC2. It is public and anyone with an Amazon account can launch instances of these.

The prebuilt AMIs details are:

Name Description Builder AMI (us-east-1) USA AMI (ap-southeast-2) Sydney
mageia-4-64-go Mageia 4, 64 bit nelg@mageia.org

ami-996ff7a3


Pre-built AMIs for Mageia 3

A Mageia 3 beta AMI has been built on Amazon's cloud service, EC2. It is public and anyone with an Amazon account can launch instances of these.

WARNING: The Mageia 3 AMI is beta, because it currently has a cauldron kernel. This causes trouble when installing some packages. It consists of a minimal Mageia 3 installation.

The prebuilt AMIs details are:

Name Description Builder AMI (us-east-1) USA AMI (ap-southeast-2) Sydney
mageia-3-64-go-beta Mageia 3, 64 bit nelg@mageia.org ami-f359c4c9

Pre-built AMIs for Mageia 2

Mageia 2 AMI's have been built on Amazon's cloud service, EC2. These are public and anyone with an Amazon account can launch instances of these. They consist of a minimal Mageia 2 installation.

The prebuilt AMIs details are:

Name Description Builder AMI (us-east-1) USA AMI (ap-southeast-2) Sydney
mageia-2-64-go Mageia 2, 64 bit nelg@mageia.org ami-4e65f827 ami-2486171e
mageia-2-32-go Mageia 2, 32 bit nelg@mageia.org ami-72b4241b ami-fefe6fc4

How to start a pre-build instance

  1. Login to https://console.aws.amazon.com/ec2
  2. Select region: Choose either "US East (N. Virginia)" or "Asia Pacific (Sydney)"
  3. Launch instance
    1. Choose classic wizard
    2. Open the community AMIs tab
    3. Search for mageia, or for the AMI from the above tabel
    4. Click select
    5. Select the Instance Type you would like
    6. Pick availbility zone (or leave default)
    7. Leave all "Advanced Instance Options" default
    8. In the Storage Device Configuration, click edit
    9. Set the root volume size to something bigger than 1GB
    10. You may also attach additional disks
    11. Set the name you would like
    12. Create a keypair, or select an existing one
    13. Configure a security group, you will at least need ssh access to allowed
    14. Connect to your instance with SSH.
    15. Set the locale / lanauage as you need. Default is set to New Zealand.

After starting your instance, right click on it from within the EC2 control panel and choose connect. This will give you the connection ssh command. You can then SSH to your instance.

Building your own Mageia AMIs

Please note: This task is not to be undertaken if you are a beginner. It is complex and has room for lots of mistakes. This page may also possibly be missing a few things. If so, please feel free to email me. Nelg (Glen Ogilvie)

Base install

Using a KVM based VM, provision a VM on your desktop with 1GB of HDD, using a raw disk partition or file. Boot the Mageia installer DVD and perform a minimal installation, or installation to your requirements. I recommend you create just 1 ext4 partition on the disk, using the entire disk and do not set a swap partition. In this example, I have used a 1GB partition created using LVM on the host, which is presented as my disk for the VM. In package selection on the guest, untick all package groups, and choose an install with basic documentation, but without X, and without "install suggested packages". Add only a temp user and root password, as these will be reset. Set the firewall to allow ssh and ping only. Turn off the interactive firewall.

After installation, you can make further modifications to it, or just shut it down and transfer it for completion on Amazon.

Get your base onto an EBS backed volume

Next, boot up an Amazon instance, ideally an existing Mageia instance, but any Linux will do. It must however be the same architecture, and ideally with a kernel not too far off the Mageia version.

Provision a small (1 GB) EBS backed disk and attach it to your booted instance as /dev/xvdf. Then ssh to it, creating an SSH tunnel on port 5555, using:

ssh -L 5555:localhost:5555 -i yourkey.pem root@youinstance

The is two possibilities now, one is to copy the partition table to Amazon, and use a pv grub kernel that supports booting from the first partition (hd0,0). The other is to copy the partition and use the whole disk for the partition and use a pv grub kernel that supports booting hd0. This is the perferred option, as it makes resizing simple and works well in Amaozon's setup.

On the Amazon instace, use netcat to listen on port 5555 and write the contents to the block device:

nc -l 5555 |unxz| pv -pr -s 1G | dd of=/dev/xvdb bs=1M

(urpmi netcat-openbsd pv) might be needed.

On your desktop, in another terminal, read your new VM's first partition and send it to Amazon. IE:

kpartx -a /dev/ssd/mageia2aws
dd if=/dev/mapper/ssd-mageia2aws64p1 bs=1M | xz | nc localhost 5555
# rescan to find new /dev/xvdb1
kpartx -d /dev/ssd/mageia2aws

If you copied the whole partition table, on the amazon machine, you will need to run:

 partprobe /dev/xvdf

Or: create FS on the Amazon EBS backend and rsync. The MBR is not important for Amazon, as it uses a pv-grub kernel to read your /boot/grub/menu.1st file, rather than the MBR.


Amazon AMI kernel, that boots hd0
32 bit Kernel ID (us-east-1): aki-407d9529
64 bit Kernel ID (us-east-1): aki-427d952b

A complete list of kernels can be obtained using ec2-describe-images, as per below.

EC2 command:

# Sydney
# export EC2_REGION=ap-southeast-2
export EC2_URL=https://${EC2_REGION:-us-east-1}.ec2.amazonaws.com
# List kernels
ec2-describe-images \
 --owner amazon \
 --filter image-type=kernel \
 --filter manifest-location=*pv-grub* 
# List details about a kernel
ec2-describe-image-attribute ami-5a8d7a33

Setting up the VM for Amazon

These steps can be performed either on Amazon after transferring the VM image, or can be done locally.

Chroot into the image

(change mga number as needed)

mkdir /mnt/ec2-image
tune2fs -l /dev/xvdf
tune2fs -L mga2root /dev/xvdf
mount /dev/disk/by-label/mga2root /mnt/ec2-image
mount -o bind /dev /mnt/ec2-image/dev
mount -o bind /dev/pts /mnt/ec2-image/dev/pts
mount -o bind /dev/shm /mnt/ec2-image/dev/shm
mount -o bind /proc /mnt/ec2-image/proc
mount -o bind /sys /mnt/ec2-image/sys
cp /etc/resolv.conf  /mnt/ec2-image/etc
chroot /mnt/ec2-image

Set up

Delete install users
userdel -r nelg
dd if=/dev/urandom count=50|md5sum|passwd --stdin root


Setup urpmi media

(Change mirror location as suitable for your country and version)

urpmi.removemedia -a
urpmi.addmedia --distrib --mirrorlist http://distrib-coffee.ipsl.jussieu.fr/pub/linux/Mageia/distrib/2/x86_64/
urpmi.update --no-ignore "Nonfree Updates"
urpmi.update --no-ignore "Nonfree Release"
urpmi.update -a
Patch
urpmi --update --auto-select
Install required packages - Mageia 2

You will need a kernel-server version of the kernel. I recommend picking a specific version, rather than kernel-server-latest, due to the possible problems with upgrading a kernel in Amazon

urpmi openssh-server mkinitrd
urpmi kernel-server-3.4.34-1.mga2
urpme -a kernel-desktop
Install required packages Mageia 3

Mageia 3 kernel-server package currently has a kernel compresses with xz. This is not compatible with Amazon. Work around is to use the kernel-server package from Cauldron

 urpmi openssh-server dhcp-client rsyslog
 aria2c ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/Mageia/distrib/cauldron/x86_64/media/core/release/kernel-server-3.10.10-3.mga4-1-1.mga4.x86_64.rpm
 aria2c ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/Mageia/distrib/cauldron/x86_64/media/core/release/kernel-firmware-20130624-1.mga4.noarch.rpm
 rpm -Uvh kernel-server-3.10.10-3.mga4-1-1.mga4.x86_64.rpm kernel-firmware-20130624-1.mga4.noarch.rpm
 urpme -a kernel-desktop
Install required packages Mageia 4
 urpmi openssh-server dhcp-client rsyslog kernel-server-latest
 urpme -a kernel-desktop
Install optional packages
urpmi vim-enhanced rsync
Turn off un-needed services
chkconfig partmon off
chkconfig mandi off
systemctl disable microcode_ctl.service
systemctl disable mandi.service
systemctl disable partmon.service
Setup firstrun
touch /root/firstrun

Disable harddrake on boot

echo HARDDRAKE_ONBOOT=no >> /etc/sysconfig/system

Setup sshd

perl -pi -e 's/^PermitRootLogin .*/PermitRootLogin without-password/' /etc/ssh/sshd_config

Grub setup

Rewrite /boot/grub/menu.lst Mageia 2

Edit /boot/grub/menu.lst to contain the following:

timeout 0
color black/cyan yellow/cyan
default 0
title linux
root (hd0)
kernel /boot/vmlinuz BOOT_IMAGE=linux root=LABEL=mga2root nokmsboot
initrd /boot/initrd.img
Rewrite /boot/grub/menu.lst Mageia 3 / 4

(change LABEL as reqired) Edit /boot/grub/menu.lst to contain the following:

timeout 0
color black/cyan yellow/cyan
default 0
title linux
root (hd0)
kernel /boot/vmlinuz BOOT_IMAGE=linux root=LABEL=mga3root nokmsboot console=hvc0 clearcpuid=156
initrd /boot/initrd.img

Note: clearcpuid=156 is required, and console=hvc0 is needed for console output.

Edit grub/device.map

set to /dev/xvda

Rebuild initrd Mageia 2

rm /boot/initrd-3.4.24-server-2.mga2.img
cd /boot
mkinitrd-mkinitrd --with=xen-blkfront --with=xennet --with=xen-netfront initrd-3.4.24-server-2.mga2.img 3.4.24-server-2.mga2
ln -fs vmlinuz vmlinuz-server
ln -fs initrd-3.4.24-server-2.mga2.img initrd-server.img 
ln -fs initrd-3.4.24-server-2.mga2.img initrd.img

Rebuild initrd Mageia 3

rm /boot/initrd-3.10.10-server-3.mga4.img
cd /boot
mkinitrd --with=xen-blkfront --with=xennet --with=xen-netfront initrd-3.10.10-server-3.mga4.img 3.10.10-server-3.mga
ln -fs vmlinuz-server vmlinuz
ln -fs initrd-3.8.13.4-server-1.mga3 initrd-server.img
ln -fs initrd-server.img initrd.img
ln -fs vmlinuz-3.10.10-server-3.mga4 vmlinuz-server

If you are doing this from within an existing amazon guest, I've also found that the below works.

mkinitrd initrd-3.10.10-server-3.mga4.img 3.10.10-server-3.mga 

in place of the mkinitrd above.

Rebuild initrd Mageia 4

rm /boot/initrd-3.10.10-server-3.mga4.img
cd /boot
mkinitrd --with=xen-blkfront --with=xennet --with=xen-netfront initrd-3.10.10-server-3.mga4.img 3.12.13-server-2.mga4
ln -fs vmlinuz-server vmlinuz
ln -fs initrd-3.10.10-server-3.mga4.img initrd-server.img
ln -fs initrd-server.img initrd.img
ln -fs vmlinuz-3.12.13-server-2.mga4 vmlinuz-server

If you are doing this from within an existing amazon guest, I've also found that the below works.

mkinitrd initrd-3.10.10-server-3.mga4.img 3.12.13-server-2.mga4

in place of the mkinitrd above.

Check shorewall Mageia 2

Confirm that /etc/shorewall/rules.drakx contains:

ACCEPT  net     fw      icmp    8       -
ACCEPT  net     fw      tcp     22      -

Check shorewall Mageia 3

Confirm that /etc/shorewall/rules contains:

SSH/ACCEPT      net     fw
Ping/ACCEPT     net     fw

/etc/shorewall6/interfaces

net     ipv6
fw      firewall

/etc/shorewall6/policy

fw      net     ACCEPT
net     all     DROP    info
all     all     REJECT  info

/etc/shorewall6/interfaces

FORMAT 2
net             eth0

Check shorewall Mageia 4

Check that shorewall contains rules allowing SSH and ICMP for IPv4, and don't forget to check the IPv6 firewall as well.


Check /etc/fstab

Check /etc/fstab. Remove any entries for cdrom's, and if you have rebuilt the filesystem, update the uuid.

Clean up

delete any invalid symlinks in /boot

find /boot -type l -xtype l -delete

Clean up misc

rm /etc/udev/rules.d/*persistent*.rules
rm -rf /root/.ssh
rm -rf /home/*
rm -f /etc/ssh/ssh_host_*
for i in messages dmesg security.log user.log maillog secure syslog; do
 echo "Clean Mageia install" > /var/log/$i
done
rm -rf /root/.bash_history /root/.lesshst /root/.xauth /root/.gnupg/

Add required files for Amazon EC2 setup

/etc/rc.d/rc.local

The following is an example rc.local

#!/bin/sh
#
### BEGIN INIT INFO
# Provides: rc.local
# X-Mandriva-Compat-Mode
# Default-Start: 2 3 4 5
# Short-Description: Local initialization script
# Description: This script will be executed at the end of the boot process.
#              You can put your own initialization stuff in here if you don't
#              want to do the full Sys V style init stuff.
### END INIT INFO

# Only do this on first boot up
if [ -f "/root/firstrun" ] ; then
 
  cd /tmp
# Random root password
  dd if=/dev/urandom count=50|md5sum|passwd --stdin root

# Grow the disk.
  resize2fs /dev/xvda1


#Setting up root ssh key
  if [ ! -d /root/.ssh ] ; then
        mkdir -p /root/.ssh
        chmod 700 /root/.ssh
  fi

# Fetch public key using HTTP
  aria2c http://169.254.169.254/2007-01-19/meta-data/public-keys/0/openssh-key -d /tmp -o 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

  # Don't do this next boot
  rm -f /root/firstrun
fi

touch /var/lock/subsys/local

lsmod > /var/log/ami-debug.txt
ifconfig -a >> /var/log/ami-debug.txt
uname -a >> /var/log/ami-debug.txt
ps -ef >> /var/log/ami-debug.txt
df -h >> /var/log/ami-debug.txt
ifconfig eth0 >> /var/log/ami-debug.txt
chmod 755 /etc/rc.d/rc.local
cd /etc
ln -s rc.d/rc.local

Exit the chroot

Ctrl - d

Unmount your EBS volume (/dev/xvdf)

cd /mnt/ec2-image
umount dev/pts dev/shm dev proc sys
cd /mnt
umount ec2-image
sync

Registering your AMI with Amazon

Ensure you have the latest ec2-api-tools available on your desktop. Export the necessary Amazon variables for your enviroment. These should be, PATH, JAVA_HOME, EC2_HOME, EC2_PRIVATE_KEY, EC2_CERT.

Create a snapshot of your EBS volume. Note the snapshot ID for the following commands.

us-east-1

32 bit

ec2-register -n mageia-2-go --kernel aki-407d9529  -b '/dev/sda1=snap-XXXXXXXX:1:false' -d "Linux - Mageia 2, 32 bit, built by YOUR NAME" -a i386

64 bit

ec2-register -n mageia-2-64-go --kernel aki-427d952b -b '/dev/sda1=snap-XXXXXXXX:1:false' -d "Linux - Mageia 2, 64 bit, built by YOUR NAME" -a x86_64

Making your AMI available in different regions

Example: copy to sydney ap-southeast-2:

Find the snapshot ID on existing region. Note region as well. Also, find suitable pvgrub kernel in the destination region, using ec2-describe-images

Creating it

Set your region

export EC2_URL=https://ap-southeast-2.ec2.amazonaws.com
ec2-copy-snapshot -s snap-XXXXXXXX -r us-east-1 -d 'Build by Glen, copied from snap-XXXXXXXX, us-east-1'
ec2-register -n mageia-2-go --kernel aki-33990e09 -b '/dev/sda1=snap-YYYYYYYY:1:false' -d "Linux - Mageia 2, 32 bit, built by Glen Ogilvie" -a i386