Showing posts with label virtualization. Show all posts
Showing posts with label virtualization. Show all posts

Wednesday, September 21, 2011

From domU read the xenstore (ec2, linode etc)

In case you wonder what is the dom0 running for your instance/vps this will give you information from xenstore. Taken from a FreeBSD receipe and adapted to linux.

Building & installation
-----------------------

Prerequisites: make, XENHVM or XEN kernel (GENERIC will not work) - all this is already there if you run as pv.

1. wget http://bits.xensource.com/oss-xen/release/4.1.1/xen-4.1.1.tar.gz

2. tar xvfz xen-4.1.1.tar.gz

3. cd xen-4.1.1/tools

4. make -C include

5. cd misc

6. make xen-detect

7. install xen-detect /usr/local/bin

8. cd ../xenstore

9. Build client library and programs:
  make clients

10. Install client library and programs:
  install libxenstore.so.3.0 /usr/local/lib
  install xenstore xenstore-control /usr/local/bin
  cd /usr/local/bin
  ln xenstore xenstore-chmod
  ln xenstore xenstore-exists
  ln xenstore xenstore-list
  ln xenstore xenstore-ls
  ln xenstore xenstore-read
  ln xenstore xenstore-rm
  ln xenstore xenstore-write

(in case that your ld loader doesn't look into /usr/local/lib do this
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib)


Usage
-----

1. Set required environment variable:
  export XENSTORED_PATH=/dev/xen/xenstore -- FreeBSD
  export XENSTORED_PATH=/proc/xen/xenbus -- Linux

2. Now you can do things such as:
  xen-detect
  xenstore-ls device
  xenstore-ls -f /local/domain/0/backend/vif/11/0
  xenstore-read name

Tuesday, September 20, 2011

Ec2 metadata

In case that you are looking for more info while you are into a ec2 instance you can call
from within the instance the api metadata server from ec2.

$ curl http://169.254.169.254/latest/meta-data/
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
hostname
instance-action
instance-id
instance-type
kernel-id
local-hostname
local-ipv4
mac
network/
placement/
profile
public-hostname
public-ipv4
public-keys/
ramdisk-id
reservation-id

Thursday, September 17, 2009

Create from scratch a Xen image [Part-1]

This is a mini howto on creating from scratch a xen domU guest system cloning the
hostOS.

What you need:

- have a host os which runs xen in dom0 (you can install a centOS and choose virtualization as profile)
- some disk space (i put 20Gb for the / and 2 for swap)
- run the following two commands to set the volumes

pvcreate /dev/sda7 -- change the /dev/sda7 with whatever you want to
vgcreate VolGroup00 /dev/sda7 -- change the /dev/sda7 with whatever you want to

if unsure what to do look it on on how to create volumes in linux (google it ... )



The following script will create you and image:

#!/bin/sh

##########################################
echo $0 "Starting"                       #
echo "This script will clone the guestOS #
creating a new xen image"                #
#
# echo "Author: dioda11@gmail.com"       #
##########################################

if [ $@ ne 1 ]; then
echo "please give a numeric identifier for the clone
between 10 and 100"
exit 1;
# if ![ $1 lt 100 ]  
fi

IMGID=$1
BASEDIRMOUNT=/mnt

VOLGROUP=VolGroup00

lvcreate  -L 20G -n   LV_VM$IMGID_RH5.3_ROOT   $VOLGROUP
lvcreate  -L 2G -n   LV_VM$IMGID_RH5.3_SWAP  $VOLGROUP

mkfs.ext3  /dev/$VOLGROUP/LV_VM$IMGID_RH5.3_ROOT
mkswap  /dev/$VOLGROUP/LV_VM$IMGID_RH5.3_SWAP


if [ -d $BASEDIRMOUNT/$IMGID ]; then
mount /dev/$VOLGROUP/LV_VM$IMGID_RH5.3_ROOT $BASEDIRMOUNT/$IMGID
echo "Mounting the /dev/$VOLGROUP/LV_VM$IMGID_RH5.3_ROOT was " $? 
else
mkdir -p $BASEDIRMOUNT/$IMGID
echo "Creating $BASEDIRMOUNT/$IMGID was  " $?
mount /dev/$VOLGROUP/LV_VM$IMGID_RH5.3_ROOT $BASEDIRMOUNT/$IMGID
echo "Mounting the /dev/$VOLGROUP/LV_VM$IMGID_RH5.3_ROOT was " $? 
fi


echo "Cloning the host OS === "

ARCH=`uname -m`

if [ $ARCH == "x86_64" ]; then 
cp -ax /{bin,dev,etc,lib,lib64,root,sbin,usr,var} $BASEDIRMOUNT/$IMGID
else 
cp -ax /{bin,dev,etc,lib,root,sbin,usr,var} $BASEDIRMOUNT/$IMGID
fi

mkdir $BASEDIRMOUNT/$IMGID/{home,proc,opt,sys,tmp}
chmod 777 $BASEDIRMOUNT/$IMGID/tmp

echo "Cloning finished === " $?


echo "At this point you need to fix the /etc/fstab and create the xen config file"

# umount $BASEDIRMOUNT/$IMGID

------------------------

Thursday, August 13, 2009

Common tasks with OpenVZ

You just want to skip all the reading about OpenVZ and start using it ?!
This is just for you.
It will install the openvz kernel and utilities and have a container ready.
Feel free to execute all or just a few commands.

### 
# info http://wiki.openvz.org/Quick_installation
# install script

cd /etc/yum.repos.d
wget http://download.openvz.org/openvz.repo
rpm --import  http://download.openvz.org/RPM-GPG-Key-OpenVZ
yum -y install ovzkernel

# edit grub.conf if you want to change labels etc

reboot

yum install vzctl vzquota
/sbin/service vz start


### 
# info http://wiki.openvz.org/OS_template_cache_preparation
# os templates

# to make templates
# utilities
yum install vzpkg vzyum vzrpm43-python vzrpm44-python vzctl-lib

# metadata
yum search vztmpl

# create cache
vzpkgcache centos-4-i386-minimal



# Precreated template cache 
# YOU NEED TO DO THIS - there are many templates
# download from http://wiki.openvz.org/Download/template/precreated


#  Create and start a container 
# To create and start a container, run the following commands:
# 
# [host-node]# vzctl create CTID --ostemplate osname
# [host-node]# vzctl set CTID --ipadd a.b.c.d --save
# [host-node]# vzctl set CTID --nameserver a.b.c.d --save
# [host-node]# vzctl start CTID
# 

###########
vzctl create 1 --ostemplate centos-5-x86
vzctl set 1 --ipadd 10.0.51.254 --save
vzctl set  1 --nameserver 192.168.1.20 --save
vzctl start 1


# Here CTID is the numeric ID for the container; osname is the name of the OS template for the container, and a.b.c.d is the IP address to be assigned to the container.
# Your freshly-created container should be up and running now; you can see its processes:
# 
[host-node]# vzctl exec CTID ps ax
# 
# Enter to and exit from the container
# 
# To enter container give the following command:
# 
[host-node]# vzctl enter CTID
# entered into container CTID
# [container]#
# 
# To exit from container, just type exit and press Enter:
# 
[container]# exit
# exited from container VEID
# [host-node]#
# 
# Stop and destroy the container
# 
# To stop container:
# 
[host-node]# vzctl stop CTID
# Stopping container ...
# Container was stopped
# Container is unmounted
# 
# And to destroy container:
# 
[host-node]# vzctl destroy CTID
# Destroying container private area: /vz/private/CTID
# Container private area was destroyed
# 


Thursday, February 7, 2008

Xen install via CFengine on linux CentOS5.0

Objective:

Have a linux host with the xen kernel on CentOS5.0
The hosts OS has 5 machines inside that run CentOS 4.4 with different applications.