[Ubuntu]Set charging threshold for Thinkpad (a.k.a Extend Your Battery Life)

I’m running a Ubuntu on my Thinkpad W510 at a daily basis and battery is always the pain in the butt. What is worse is that the battery is dying fast without any charging threshold set. I didn’t pay attention to it until my battery died two weeks ago, so I looked into the issue. Fortunately, Thinkpad provides a kernel module named tp_smapi for remedy and it is easy to set up.

First of all, we need to install the kernel module using apt-get. Use modprobe to check if the module is installed successfully. If not, it will throw a fatal error.

sudo apt-get install -y tp-smapi-dkms
modprobe tp_smapi

Once the module is installed, set thresholds for starting/stopping charging, respectively.

# start charging when the percentage falls down to 50%
sudo echo 50 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
# stop charging when the percentage reaches 99%
sudo echo 99 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh

Hopefully it will save you tens of bucks for replacing battery for your Thinkpad.

Posted in Linux | 1 Comment

Telnet over SSL

Problem

telent only works for plain applications but not those on top of SSL.

Solution

Use openssl s_client , e.g.

openssl s_client -connect https://abc.com:8443

Then everything should be as same as what you see in telnet.

Posted in Misc. | Leave a comment

Metadata-Aware Scheduler for Apache Storm

Problem

Storm assigns spouts/bolts in a topology to supervisors using its default scheduler, with which users can hardly predict where the spout/bolt goes. But you may want to control where they go based on certain metadata (e.g. location, sequence number) in some use cases. In this case, the default scheduler will not work well for you.

Background

Since 0.8.0, Storm allows users to use custom scheduler for task scheduling. It also allows users to specify scheduling-specific metadata in supervisor’s configuration. The new feature favors us in resolving the problem.

Use Case

To showcase the solution, we assume that we submit a topology with spouts/bolts tagged with “group ID” and want them to be assigned to supervisors with the same “group ID” as shown below.
storm-sched

Solution

The solution consists of 3 steps:

  1. Add metadata, i.e. group ID in this scenario, to supervisors
  2. Tag spouts/bolts with group IDs
  3. Implement custom scheduler that reads the metadata and associates the spouts/bolts with supervisors properly

Step 1

Storm preserves a field supervisor.scheduler.meta in each supervisor’s configuration file, $STORM_HOME/conf/storm.yaml, for specifying custom metadata. Any key-value pairs can be put in this field. The metadata won’t be used by Storm’s core. In our scenario, we will put a “group-id: 1” pair for supervisor in Group 1 as below. Remember restart the supervisor daemon after modifying the configuration in order to have the updates applied.

...
supervisor.scheduler.meta:
    group-id: 1
...

Step 2

After tagging supervisors with “group-id”, we then tag the spouts/bolts accordingly so that the scheduler can associate the spouts/bolts with supervisors correctly. The tagging is done using addConfiguration(key, value) method when building the topology with TopologyBuilder. The example is shown below.

...
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("Spout_1", new ExampleSpout(), 1).addConfiguration("group-id", 1);
builder.setBolt("Bolt_1", new ExampleBolt(), 1).shuffleGrouping("Spout_1").addConfiguration("group-id", 1);
builder.setBolt("Bolt_2", new ExampleBolt2(), 1).shuffleGrouping("Spout_1").addConfiguration("group-id", 2);
builder.setBolt("Bolt_3", new ExampleBolt3(), 1).globalGrouping("Bolt_1").globalGrouping("Bolt_2").addConfiguration("group-id", 3);
StormSubmitter.submitTopology("example-topology", builder.createTopology());
...

Step 3

This step is important as it makes the magic happen. The custom scheduler is deployed on Nimbus and should be referenced in the configuration file. Now let’s go through it step by step.

To implement a custom scheduler, we need to implement the IScheduler interface as shown below.

import java.util.Map;

import backtype.storm.scheduler.Cluster;
import backtype.storm.scheduler.IScheduler;
import backtype.storm.scheduler.Topologies;

public class GroupingScheduler implements IScheduler{

	@Override
	public void prepare(Map conf) {
		...
	}

	@Override
	public void schedule(Topologies topologies, Cluster cluster) {
		...
	}
}

The interface has two methods to be implemented. The prepare(Map conf) method is used for initializing the scheduler. It comes with a system-wide configuration. The custom scheduling policy is implemented in the schedule(Topologies topologies, Cluster cluster) method. It is called by Storm core periodically. The topologies is a wrap-up of all topologies submitted to the Storm cluster. It contains a collection of TopologyDetails instances, each of which contains all the details about a topology, including custom metadata we set before. The collection can be acquired by calling getTopologies() method. The cluster represents the Storm cluster, which has a getSupervisors() method to get a collection of SupervisorDetails instances. A SupervisorDetails instance encapsulates all the information about a supervisor, including the metadata we set for each supervisor before.

Note that the complexity of matching up group IDs on spouts/bolts and supervisors is O(total number of spouts/bolts * total number of supervisors) . Since the number of supervisors is relatively static, we can store the supervisors in a hash map and index them using the metadata, i.e. group ID in this scenario, so that the complexity can be lowered to O(total number of spouts/bolts). The metadata on each supervisor can be derived by calling getSchedulerMeta() method, which returns metadata in key-value pairs. The supervisor map will be frequently updated as the schedule() method is called periodically, so the scheduler will be aware of newly added supervisors. Till now, the code should look like what is shown below.

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import backtype.storm.scheduler.Cluster;
import backtype.storm.scheduler.IScheduler;
import backtype.storm.scheduler.SupervisorDetails;
import backtype.storm.scheduler.Topologies;
import backtype.storm.scheduler.TopologyDetails;


public class GroupingScheduler implements IScheduler{

	@Override
	public void prepare(Map conf) {
		
	}

	@Override
	public void schedule(Topologies topologies, Cluster cluster) {
		Collection<TopologyDetails> topologyDetails = topologies.getTopologies();
		Collection<SupervisorDetails> supervisorDetails = cluster.getSupervisors().values();
		Map<Integer, SupervisorDetails> supervisors = new HashMap<Integer, SupervisorDetails>();
		
		// to accelerate supervisor lookup
		for(SupervisorDetails s : supervisorDetails){
			Map<String, Object> metadata = (Map<String, Object>)s.getSchedulerMeta();
			if(metadata.get("group-id") != null){
				supervisors.put((Integer)metadata.get("group-id"), s);
			}
		}
	}

}

As we may have a number of submitted topologies, we need to iterate over them to check if they need to be scheduled. Storm cluster offers a method, needsScheduling(TopologyDetails topology), for checking if a topology needs to be scheduled. The spouts/bolts details in a topology are encapsulated in the StormTopology, which can be derived by calling getTopology(). Now the code should look like this.

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import backtype.storm.generated.Bolt;
import backtype.storm.generated.SpoutSpec;
import backtype.storm.generated.StormTopology;
import backtype.storm.scheduler.Cluster;
import backtype.storm.scheduler.IScheduler;
import backtype.storm.scheduler.SupervisorDetails;
import backtype.storm.scheduler.Topologies;
import backtype.storm.scheduler.TopologyDetails;


public class GroupingScheduler implements IScheduler{

	@Override
	public void prepare(Map conf) {
		
	}

	@Override
	public void schedule(Topologies topologies, Cluster cluster) {
		Collection<TopologyDetails> topologyDetails = topologies.getTopologies();
		Collection<SupervisorDetails> supervisorDetails = cluster.getSupervisors().values();
		Map<Integer, SupervisorDetails> supervisors = new HashMap<Integer, SupervisorDetails>();
		for(SupervisorDetails s : supervisorDetails){
			Map<String, Object> metadata = (Map<String, Object>)s.getSchedulerMeta();
			if(metadata.get("group-id") != null){
				supervisors.put((Integer)metadata.get("group-id"), s);
			}
		}
		
		for(TopologyDetails t : topologyDetails){
			if(cluster.needsScheduling(t)) continue;
			StormTopology topology = t.getTopology();
			Map<String, Bolt> bolts = topology.get_bolts();
			Map<String, SpoutSpec> get_spouts = topology.get_spouts();
		}
	}
	
}

The map keys are names of spouts/bolts, which will be referenced later. Bolt and SpoutSpec are similar in structure. Both of them have a get_common() method that returns a ComponentCommon object. The custom metadata is stored as a JSON string returned by get_json_conf(). To parse the JSON string, you need to pick up your preferred JSON API, such as json-simple, Jackson, etc. In this example, we use json-simple.

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import backtype.storm.generated.Bolt;
import backtype.storm.generated.SpoutSpec;
import backtype.storm.generated.StormTopology;
import backtype.storm.scheduler.Cluster;
import backtype.storm.scheduler.IScheduler;
import backtype.storm.scheduler.SupervisorDetails;
import backtype.storm.scheduler.Topologies;
import backtype.storm.scheduler.TopologyDetails;


public class GroupingScheduler implements IScheduler{

	@Override
	public void prepare(Map conf) {
		
	}

	@Override
	public void schedule(Topologies topologies, Cluster cluster) {
		Collection<TopologyDetails> topologyDetails = topologies.getTopologies();
		Collection<SupervisorDetails> supervisorDetails = cluster.getSupervisors().values();
		Map<Integer, SupervisorDetails> supervisors = new HashMap<Integer, SupervisorDetails>();
		for(SupervisorDetails s : supervisorDetails){
			Map<String, Object> metadata = (Map<String, Object>)s.getSchedulerMeta();
			if(metadata.get("group-id") != null){
				supervisors.put((Integer)metadata.get("group-id"), s);
			}
		}
		
		for(TopologyDetails t : topologyDetails){
			if(cluster.needsScheduling(t)) continue;
			StormTopology topology = t.getTopology();
			Map<String, Bolt> bolts = topology.get_bolts();
			Map<String, SpoutSpec> spouts = topology.get_spouts();
			JSONParser parser = new JSONParser();
			try{
				for(String name : bolts.keySet()){
					Bolt bolt = bolts.get(name);
					JSONObject conf = (JSONObject)parser.parse(bolt.get_common().get_json_conf());
					if(conf.get("group-id") != null && supervisors.get(conf.get("group-id")) != null){
						Integer gid = (Integer)conf.get("group-id");
					}
				}
				for(String name : spouts.keySet()){
					SpoutSpec spout = spouts.get(name);
					JSONObject conf = (JSONObject)parser.parse(spout.get_common().get_json_conf());
					if(conf.get("group-id") != null && supervisors.get(conf.get("group-id")) != null){
						Integer gid = (Integer)conf.get("group-id");
					}
				}
			}catch(ParseException pe){
				pe.printStackTrace();
			}
		}
	}
	
}

With the topology components’ group IDs in hand, it’s time to assign them to the supervisors correctly. Since we cached supervisors by their group IDs before, we can simply retrieve them back now. In Storm, a supervisor’s system resource is partitioned into a number of worker slots. So we actually assign a component to an available worker slot on a particular supervisor. We use getAvailableSlots(SupervisorDetails supervisor) method to get a list of available worker slots on the supervisor. On the other hand, a topology component may consist of a number of exectutors, which are threads making progress on data processing. Similarly, we also need to get the executors for each component using getNeedsSchedulingComponentToExecutor(TopologyDetails topology). The method returns a map consisting of “<component-name, executors>” pairs, so we can retrieve the right executors with the component name. Before the assignment, make sure that there are available worker slots on the supervisor and there are executors for the component waiting for scheduling. Finally, we use assign(WorkerSlot slot, String topologyId, Collection executors) method to do the assignment. We assume that there is at least one worker slot available on each supervisor and we pick up the first available slot to run the component. The completed scheduler is listed below.

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import backtype.storm.generated.Bolt;
import backtype.storm.generated.SpoutSpec;
import backtype.storm.generated.StormTopology;
import backtype.storm.scheduler.Cluster;
import backtype.storm.scheduler.ExecutorDetails;
import backtype.storm.scheduler.IScheduler;
import backtype.storm.scheduler.SupervisorDetails;
import backtype.storm.scheduler.Topologies;
import backtype.storm.scheduler.TopologyDetails;
import backtype.storm.scheduler.WorkerSlot;


public class GroupingScheduler implements IScheduler{

	@Override
	public void prepare(Map conf) {
		
	}

	@Override
	public void schedule(Topologies topologies, Cluster cluster) {
		Collection<TopologyDetails> topologyDetails = topologies.getTopologies();
		Collection<SupervisorDetails> supervisorDetails = cluster.getSupervisors().values();
		Map<Integer, SupervisorDetails> supervisors = new HashMap<Integer, SupervisorDetails>();
		for(SupervisorDetails s : supervisorDetails){
			Map<String, Object> metadata = (Map<String, Object>)s.getSchedulerMeta();
			if(metadata.get("group-id") != null){
				supervisors.put((Integer)metadata.get("group-id"), s);
			}
		}
		
		for(TopologyDetails t : topologyDetails){
			if(cluster.needsScheduling(t)) continue;
			StormTopology topology = t.getTopology();
			Map<String, Bolt> bolts = topology.get_bolts();
			Map<String, SpoutSpec> spouts = topology.get_spouts();
			JSONParser parser = new JSONParser();
			try{
				for(String name : bolts.keySet()){
					Bolt bolt = bolts.get(name);
					JSONObject conf = (JSONObject)parser.parse(bolt.get_common().get_json_conf());
					if(conf.get("group-id") != null && supervisors.get(conf.get("group-id")) != null){
						Integer gid = (Integer)conf.get("group-id");
						SupervisorDetails supervisor = supervisors.get(gid);
						List<WorkerSlot> availableSlots = cluster.getAvailableSlots(supervisor);
						List<ExecutorDetails> executors = cluster.getNeedsSchedulingComponentToExecutors(t).get(name);
						if(!availableSlots.isEmpty() && executors != null){
							cluster.assign(availableSlots.get(0), t.getId(), executors);
						}
					}
				}
				for(String name : spouts.keySet()){
					SpoutSpec spout = spouts.get(name);
					JSONObject conf = (JSONObject)parser.parse(spout.get_common().get_json_conf());
					if(conf.get("group-id") != null && supervisors.get(conf.get("group-id")) != null){
						Integer gid = (Integer)conf.get("group-id");
						SupervisorDetails supervisor = supervisors.get(gid);
						List<WorkerSlot> availableSlots = cluster.getAvailableSlots(supervisor);
						List<ExecutorDetails> executors = cluster.getNeedsSchedulingComponentToExecutors(t).get(name);
						if(!availableSlots.isEmpty() && executors != null){
							cluster.assign(availableSlots.get(0), t.getId(), executors);
						}
					}
				}
			}catch(ParseException pe){
				pe.printStackTrace();
			}
		}
	}
	
}

Installation

The scheduler should be exported as a jar file for installation. It is recommended to use Apache Maven to package it but you can choose you favorite toolkit to do that too. With the jar file ready, you need to copy it to Storm’s library directory on Nimbus as follow.

cp grouping-scheduler.jar $STORM_HOME/lib

Then tell Nimbus to use the scheduler.

...
storm.scheduler: "storm.custom.scheduler.GroupingScheduler"
...

Remember to restart Nimbus daemon after modifying the configuration.

Improvements

The example scheduler is very simple as it is designed for showcasing how to acquire and use user metadata in a scheduler. Designing a production-ready scheduler is a delicate work. We will not discuss how to improve the scheduler line by line here, but you may want to take the following situations into consideration when doing the design:

  1. How to mix regular and custom scheduling in a single scheduler?
  2. What if there are multiple supervisors with same metadata tag (e.g. group ID)?
  3. What if there are no worker slots available on a particular supervisor?
  4. If multiple scheduling policies are introduced, how to manage priorities?
  5. Is it possible to distribute executors over multiple worker slots/supervisors for load balancing purpose?

I believe there are more interesting points around this topic. I will try out several of them in the future.

Reference

This post is inspired by Twitter Storm: How to develop a pluggable scheduler.

Posted in Storm | 16 Comments

Install Xen 4.3.1 on Ubuntu 12.04 LTS from source

0. Install Xen Dependencies

# apt-get install bridge-utils build-essential libncurses-dev python-dev uuid uuid-dev libglib2.0-dev libyajl-dev bcc gcc-multilib iasl libpci-dev mercurial flex bison libaio-dev build-essential gettext libpixman-1-dev bin86 gawk bridge-utils iproute libcurl3 libcurl4-openssl-dev bzip2 module-init-tools transfig tgif texinfo texlive-latex-base texlive-latex-recommended texlive-fonts-extra texlive-fonts-recommended pciutils-dev mercurial make gcc libc6-dev zlib1g-dev python python-dev python-twisted libncurses5-dev patch libvncserver-dev libsdl-dev libbz2-dev e2fslibs-dev git-core uuid-dev ocaml ocaml-findlib libx11-dev bison flex xz-utils libyajl-dev

1. Download Xen Source Code

# git clone git://xenbits.xen.org/xen.git ~/xen
# cd ~/xen
# git checkout -b RELEASE-4.3.1 RELEASE-4.3.1

2. Compile and Install Xen from Source

# ./configure
# ./make -j4 dist
# ./make install 

Note that the option “-j4” tells the compiler to use 4 cores(it uses 2 cores by default).

3. Update GRUB
Delete duplicate entries in /boot

# cd /boot
# rm -rf xen.gz xen.4.3.gz xen.4.3.1.gz xen-syms-4.3.1

Set priority for loading Xen-compatible kernel at boot

# mv /etc/grub.d/20_linux_xen /etc/grub.d/09_linux_xen
# update-grub

4. Load Xen Services at Boot

# update-rc.d xencommons 20 19
# update-rc.d xendomains 21 22
# update-rc.d xen-watchdog 23 22

5. Update /etc/ld.so.conf

# ldconfig

This step is important since the system will complain about missing library files if not do so.

6. Configure Virtual Network
Assuming we use DHCP for VMs. Modify the network configuration as follow.

# vi /etc/network/interfaces
auto eth0
iface eth0 inet manual

auto xenbr0
iface xenbr0 inet static
        bridge_ports eth0
        address 10.10.100.2
        netmask 255.255.255.0
        network 10.10.100.0
        broadcast 10.10.100.255
        gateway 10.10.100.1

7. Manage Storage for VMs
Assuming we use LVM to manage storage for VMs. It is suggested to spare a dedicated partition for VM storage.

# pvcreate /dev/sda3
# vgcreate vg0 /dev/sda3

Now you can find the volume group at /dev/vg0

8. Reboot

9. Create a VM for Test
Check if Dom0 is running

# xl list
Name                                        ID   Mem VCPUs	State	Time(s)
Domain-0                                     0 11962     8     r-----    8582.6

Check Xen’s configuration

# xl info

Create a logical volume(LV) for a new VM

lvcreate -nwin7 -L20G vg0

Create the .cfg file for the VM. Here we’ll install Window 7 32-bit on a VM.

# vi win7.cfg
kernel = 'hvmloader'
builder = 'hvm'

## number of cores ##
vcpus = '2'

## memory size ##
memory = '4096'
device_model_version="qemu-xen-traditional"

## storage: use the LV we just created ##
disk = [
        'phy:/dev/vg0/win7,hda,w'
]
## name of the VM ##
name = 'windows'

## network configuration ##
vif = [ 'mac=00:16:3E:51:20:4C,bridge=xenbr0,model=e1000' ]

## events policy ##
on_poweroff = 'destroy'
on_reboot = 'restart'
on_crash = 'restart'

## boot priority ##
boot = 'dc'
acpi = '1'
apic = '1'
viridian = '1'
xen_platform_pci='1'
sdl = '0'

## VNC configuration ##
vnc = '1' ## 1 or larger numbers to turn on; 0 to turn off ##
vnclisten = '0.0.0.0' ## network it listens to ##
vncdisplay = '6' ## VNC port ##
vncpasswd = ''

stdvga = '0'
usb = '1'
usbdevice = 'tablet'

10. VIew the VM via VNC Viewer
Use a computer with GUI to do so. Assuming we use a computer with Ubuntu running on it.

We need to install a VNC viewer first. Any type of VNC viewer should work. Here we use gvncviewer.

# apt-get install -y gvncviewer

Then connect to the VM with it

# gvncviewer 10.10.100.2:6

You will get a view of the VM if everything goes smoothly. Have fun!

11. Troubleshooting

  • libxlutil.so.4.3: cannot open shared object file: No such file or directory
  • Solution:

    ldconfig
Posted in Xen | 2 Comments

OpenStack: Add External Network to VMs

First of all, create a network as an external network for your tenant.

# quantum net-create --tenant_id 084b76c9a70247cf950c23b8144a5a46 ext_net --router:external=True

Then create a subnet for the external network. Note that you should disable DHCP.

# quantum subnet-create --tenant-id 084b76c9a70247cf950c23b8144a5a46 --allocation-pool start=1.2.3.5,end=1.2.3.8 --gateway 1.2.3.1 ext_net 1.2.3.0/24 --enable_dhcp=False

Attach the external network to your virtual router. You may list your networks and routers first to get their ids.

# quantum router-list
+--------------------------------------+-------------+--------------------------------------------------------+
| id                                   | name        | external_gateway_info                                  |
+--------------------------------------+-------------+--------------------------------------------------------+
| 020f48d9-182e-4e33-a73f-813333533092 | router-demo | {"network_id": "9a457578-8f85-486b-9cd0-f7f04922ba0c"} |
+--------------------------------------+-------------+--------------------------------------------------------+

# quantum net-list
+--------------------------------------+----------+----------------------------------------------------+
| id                                   | name     | subnets                                            |
+--------------------------------------+----------+----------------------------------------------------+
| 07e10f48-0637-46bb-a444-695646e6bd15 | net-demo | c042e65e-3892-45bc-aeb0-625ce5f4aaaf 50.50.1.0/24  |
| 9a457578-8f85-486b-9cd0-f7f04922ba0c | ext_net  | 0bcccf59-be17-48c7-8032-e00fd4f15b46 1.2.3.0/24 |
+--------------------------------------+----------+----------------------------------------------------+

# quantum router-gateway-set 020f48d9-182e-4e33-a73f-813333533092 9a457578-8f85-486b-9cd0-f7f04922ba0c

Now you have the external network set up. The next step is to add following security rules, to make your VMs pingable from the Internet.

nova --no-cache secgroup-add-rule default icmp -1 -1 0.0.0.0/0
nova --no-cache secgroup-add-rule default tcp 22 22 0.0.0.0/0

Note that the status of ports for the external network(including floating IPs and the gateway) will stay DOWN, even they actually work. You can check the status of ports with the following command.

quantum port-list -c status -c fixed_ips
Posted in KVM, OpenStack | Leave a comment

Create a Solaris 10 x86 Image for OpenStack

0. Install Packages
If you have OpenStack or DevStack installed on your machine, you can skip this step. You have all the tools we need. If you don’t have it, try DevStack, it is easy to set up and a good tool to test your image. See details at: http://devstack.org/. At least, you need Qemu-KVM, libvirt, virt-manager and bridge-utils running on your machine. In Ubuntu, you can install them with following code:

# apt-get install -y qemu-kvm libvirt-bin virt-manager bridge-utils

1. Download Solaris 10 ISO and Virt-IO Block Driver
You can download the ISO file from Oracle’s website, the link is http://www.oracle.com/technetwork/server-storage/solaris10/downloads/index.html.

Since OpenStack runs VMs with Virt-IO for better performance, we need to install Virt-IO driver. There’s no officially released Virt-IO drivers for Solaris from Oracle. The only driver I can get from the Internet is the Virt-IO block driver. The download link is http://zaytsev.su/solaris-virtio/packages/sol10/vioblk-1.3-itu.iso.

2. Install Solaris
First of all, create a QCOW2 image. There are several installation options for Solaris 10, but believe me you want a developer’s installation. You want bash, you want SSH, say yes… A developer’s installation needs about 6GB space, so it’s safe to create a image larger than 6GB

qemu-img create -f qcow2 solaris.qcow2 7G

Then you need a libvirt.xml file to start the VM. libvirt.xml is a configuration file for a VM. You can define everything about the VM in this file, including the number of cores, memory size, disk, network, etc. The following listing is a template of libvirt.xml used for Solaris installation.

<domain type="kvm">
  <uuid>6ced4832-66f5-4a16-871c-6b400d6791e6</uuid>
  <name>sol-dev</name>
  <memory>2048576</memory>
  <vcpu>1</vcpu>
  <sysinfo type="smbios">
    <system>
      <entry name="manufacturer">OpenStack Foundation</entry>
      <entry name="product">OpenStack Nova</entry>
      <entry name="version">2013.2</entry>
      <entry name="serial">5014fd00-5b80-89e0-1d7b-047d7bfefbcd</entry>
      <entry name="uuid">6ced4832-66f5-4a16-871c-6b400d6791e6</entry>
    </system>
  </sysinfo>
  <os>
    <type>hvm</type>
    <boot dev="cdrom" />
    <boot dev="hd"/>
    <smbios mode="sysinfo"/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <clock offset="utc">
    <timer name="pit" tickpolicy="delay"/>
    <timer name="rtc" tickpolicy="catchup"/>
  </clock>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type="file" device="disk">
      <driver name="qemu" type="qcow2" cache="none"/>
      <source file="/path/to/your/image/solaris.qcow2"/>
      <target bus="virtio" dev="vda"/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/path/to/iso/sol-10-u11-ga-x86-dvd.iso'/>
      <target dev='hda' bus='ide'/>
      <readonly/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/path/to/virtio/driver/vioblk-1.3-itu.iso'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
    </disk>
   <interface type="bridge">
<!--  <model type="virtio"/> -->
      <source bridge="virbr0"/>
   </interface>
    <serial type='pty'>
      <source path='/dev/pts/3'/>
      <target port='0'/>
      <alias name='serial0'/>
    </serial>
    <input type="tablet" bus="usb"/>
    <graphics type="vnc" autoport="yes" keymap="en-us" listen="127.0.0.1"/>
  </devices>
</domain>

Note that the VM needs more than 2GB memory, otherwise kernel panic will occur and the installation won’t proceed.

With some changes to paths, you can launch the VM.

virsh create libvirt.xml

3. Install Driver
Once the VM is launched, you can view the console with virt-manager. After “Configuring devices”, you will see 6 options. Select No.5, “Apply driver updates”, and then select “[1] CD/DVD devices”. If you see following information, it means the driver has been installed successfully.

Extracting Driver Updates from /dev/dsk/c0t0d0p0 (QEMU QEMU DVD-ROM 1.1.).
Installing Driver Updates onto miniroot.
Installing Virtio Block driver as <SUNWvioblk>
WARNING: vioblk0: Using legacy interrupts
NOTICE: vioblk0: host features: 710006d4, guest features: 10000276
NOTICE: vioblk0: Host features: Generic ( INDIRECT_DESC ) Vioblk ( SEG_MAX GEOMETRY BLK_SIZE SCSI FLUSH TOPOLOGY )
NOTICE: vioblk0: Negotiated features: Generic ( INDIRECT_DESC ) Vioblk ( SEG_MAX GEOMETRY BLK_SIZE FLUSH )
NOTICE: vioblk0: nblks=125829120 blksize=512  num_seg=126, seg_size=4096, maxxfer=516096
NOTICE: vioblk0: Allocated 128 entries for vq 0:I/O request (16384 incdirect descs)
NOTICE: vioblk0: devid 00000000000000000000
Installation of <SUNWviobl> was successful.

Then just following the instructions. Enable the network and DHCP, select developer’s installation option and then restart the VM.

4. Install Virt-IO Driver to Kernel
Once the VM is restarted, you should have Internet connection. Log in and install the Virt-IO driver to kernel with following command.

pkgadd -d http://zaytsev.su/solaris-virtio/packages/sol10/SUNWvioblk-1.3 

5. Remove unwanted packages
Following this post: http://jackngblog.blogspot.com/2008/08/remove-unwanted-packages-rev-10.html

6. Test on OpenStack
Upload the image to your OpenStack.

glance --os-username=admin --os-password=password --os-tenant-id=c14e056d937d461e96a5875d85e82c6f --os-auth-url=http://[host IP]:5000/v2.0 image-create --name="solaris" --is-public=true --container-format=bare --disk-format=qcow2 < solaris.qcow2

Then you should be able to launch a VM via OpenStack’s dashboard, Horizon. Once a VM is launched, you can check it via VNC viewer embedded in the dashboard.

7. Networking Issue
You may find a problem that the VM’s network is not properly configured, that is caused by lack of Virt-IO network driver. OpenStack uses Virt-IO for both block and network devices. So you need to avoid using Virt-IO for the network.

Firstly you should shutdown the VM. Then find libvirt.xml of the VM, it should be located in the VM’s directory. For DevStack, it’s located at stack/data/nova/instance/{VM_id}/libvirt.xml. Find the Virt-IO line and comment it out.

--- <model type="virtio"/>
+++ <!--  <model type="virtio"/> -->

After changing the file, you restart the VM. The network should work properly now.

Posted in KVM, OpenStack, Solaris | 16 Comments

DevStack: CRITICAL nova [-] ‘module’ object has no attribute ‘packs’

Cause
It is caused by the revision of kombu modules, in which methods packs and unpacks are deprecated and replaced by packb and unpackb. See details at: https://github.com/celery/kombu/pull/143

Solution
Replace the msgpack.packs and msgpack.unpacks with msgpack.packb and msgpack.unpackb where the error occurs. Typically the module should be /usr/lib/python2.7/dist-packages/kombu/serialization.py, if msgpack-python is installed via apt-get.

--- registry.register('msgpack', msgpack.packs, msgpack.unpacks,
+++ registry.register('msgpack', msgpack.packb, msgpack.unpackb,
Posted in OpenStack | 2 Comments

Set up DNS Service on Ubuntu

OS: Ubuntu 13.04
Install dnsmasq

apt-get install -y dnsmasq

Map hostnames and IP addresses
Edit /etc/hosts and add the map.

vi /etc/hosts
##############
127.0.0.1       localhost
127.0.1.1       server.com

[ip-1]   [hostname1]
[ip-2]   [hostname2]
...
Posted in Linux | Leave a comment

Kernel Panic During Solaris 10 x86 Installation on KVM

I wonder if the problem is caused by insufficient allocation of memory, since installation proceeded when I allocated 2G memory to the VM, but reported kernel panic when it was 1G. So if you have large RAM, just allocate more memory to the VM.
The problem is caused by variable $ISADIR in Grub. Making following changes will make it work.

kernel/$ISADIR/unix -> kernel/unix
/boot/$ISADIR/x86.miniroot -> /boot/x86.miniroot

Posted in KVM, OpenStack, Solaris | Leave a comment

Solaris VM Keeps Rebooting on OpenStack

Host OS: Ubuntu 13.04
VM OS: Solaris 11
Platform: DevStack
Hypervisor: KVM
Problem: VM keeps rebooting and kernel panic occurs finally.
Why?

Solaris VM cannot run as a qcow2 instance with KVM, but OpenStack runs images in raw format as qcow2 instances as default.

If it’s a solution

I don’t figure out how to make changes to openstack code to have Solaris VM running, but come up with a solution to this problem by manually configure the VM. Since Solaris can run as a raw-formatted instance and OpenStack controls VMs with libvirt, we should replace the qcow2 image with a raw one and edit the libvirt.xml.

Once Nova creates and runs a new instance, it will download the image from Glance and keeps both raw and qcow2 images for the instance. The raw image is in the _base directory and the qcow2 image is in the directory named by the instance id. Copy the libvirt.xml to _base and make some changes.

vi $STACK_HOME/data/nova/instances/_base/libvirt.xml
####################################################
...
<disk type="file" device="disk">
#     <driver name="qemu" type="qcow2" cache="none"/>
      <driver name="qemu" type="raw" cache="none"/> #Change the type from qcow2 to raw
      <source file="/path/to/raw-image-file"/> #Point to the raw image
#     <target bus="virtio" dev="vda"/> 
      <target bus="ide" dev="vda"/> #Change the bus from virtio to ide, since virtio can't access to raw image

Save the changes, and run it with [em]virsh[/em].

virsh create libvirt.xml

You’ll see the Solaris VM runs successfully.

Posted in KVM, OpenStack | 1 Comment