Friday, December 28, 2012

Downgrade VMDK from HW version 8 to HW version 7 (Workstation 8 to ESXi 4.1 )

Introduction

When you create a VM using VMWare workstation, which you want to deploy on a ESXi server at a later moment, you should plan in advance which Version you will use for your Virtual machine (and thus your vmx config file). If you don't, your ESXi-server can complain about a unsupported version. But don't panic just yet, it might be fixable.

Which version to use?

When you still need to create a new VM in workstation you should think before choosing a version. The wizard to create a VM provides you with all the necessary information you need. But to choose the correct version it is easier to have a table with an overview. For this reason I present it to you:

Workstation version Compatible products Limitations
Workstation 8.0 ESX 5.0
Fusion 4.0
Workstation 8.0
64GB memory limit
8 processor limit
10 network adapter limit
2 TB disk size limit
No HD Audio
Workstation 6.5-7.x ACE 2.5 - 2.7
ESX 4.x
ESX 5.0
Fusion 2.x
Fusion 3.x
Fusion 4.0
Server 2.x
Workstation 6.5
Workstation 7.x
Workstation 8.0
32GB memory limit
8 processor limit
10 network adapter limit
2 TB disk size limit
Workstation 6.0 ACE 2.0
ACE 2.5 up to 2.7
ESX 4.x
ESX 5.0
Fusion 1.1
Fusion 2.x
Fusion 3.x
Fusion 4.0
Server 2.x
Workstation 6.x
Workstation 6.5
Workstation 7.x
Workstation 8.0
8 GB memory limit
2 processor limit
10 network adapter limit
950 GB disk size limit
No HD Audio
No CPU hot plug
No device hot plug
No memory hot plug
No LSI Logic SAS SCSI controller
No printer support
Workstation 5.x ACE 2.0
ACE 2.5 up to 2.7
ESX 4.x
ESX 5.0
Fusion 1.1
Fusion 2.x
Fusion 3.x
Fusion 4.0
Server 2.x
Workstation 5.x
Workstation 6.0
Workstation 6.5
Workstation 7.x
Workstation 8.0
3.5 GB memory limit
2 processor limit
4 network adapter limit
950 GB disk size limit
No HD Audio
No USB 2.0
No multiple monitor display
No battery status
No CPU hot plug
No device hot plug
No memory hot plug
No LSI Logic SAS SCSI controller
No VMCI support
No printer support
Workstation 4.x ACE 1.0
ACE 2.0
ACE 2.5 up to 2.7
ESX 4.x
ESX 5.0
Fusion 1.1
Fusion 2.x
Fusion 3.x
Fusion 4.0
GSX Server 3.x
Server 1.x
Server 2.x
Workstation 4.x
Workstation 5.x
Workstation 6.0
Workstation 6.5
Workstation 7.x
Workstation 8.0
3.5 GB memory limit
1 processor limit
4 network adapter limit
128 GB IDE disk size limit
256 GB SCSI disk size limit
No HD Audio
No USB 2.0
No multiple monitor display
No battery status
No 64-bit guests
No 3D graphics acceleration
No CPU hot plug
No device hot plug
No memory hot plug
No LSI Logic SAS SCSI controller
No VMCI support
No printer support
No clone support

So prior to selecting a version you should determine which features you need (think long-term for this!). Next you need to find a version for which your product (e.g. ESXi server) is in the compatibility list. If it has limitations that conflict with your features, you will need to upgrade.

How to downgrade a version?

Suppose you have a version 8 how do you downgrade to a version 7. I didn't find an official way but as long as you don't have features that are not supported by the version you wish to go to. Then you can just change the version numbers in the vmx file. For example if you want to go from version "8" to version "7" you can open it in your favorite editor and search for "8" and replace it with "7". (For your search replace, make sure you use the double quotes!)

Does it work?

I cannot give any promises if it works for you but I tried it on a VM with an Application server and an Oracle DB and it worked! After you change the file you can just create an OVF of it and deploy it on an ESXi 4.1 server. Which is not possible if you would create it from the original VM.

Sunday, September 23, 2012

How to set GPIO on Raspberry PI in assembly.

While reading the nice free courses 'Baking Pi: Operating Systems Development by Alex Chadwick' that explain how to write your own OS for your raspberry Pi, I couldn't figure out how the setup of the GPIO pins was done. I was able to copy the code from the lesson and thus to make it work on my raspberry PI but I wanted to understand what I was doing. For the people who also want a better understanding of how you can use the GPIO pins on the raspberry PI I'll share my findings.

As explained in the OK1 course the GPIO pins our grouped by 10 and there are 3 bits per GPIO pin to select its function. On page 90 of the Soc_pheripherals manual you can see what these 3 bits do:

000 = GPIO Pin 9 is an input 
001 = GPIO Pin 9 is an output 
100 = GPIO Pin 9 takes alternate function 0 
101 = GPIO Pin 9 takes alternate function 1 
110 = GPIO Pin 9 takes alternate function 2 
111 = GPIO Pin 9 takes alternate function 3 
011 = GPIO Pin 9 takes alternate function 4 
010 = GPIO Pin 9 takes alternate function 5

(This is a small extract of the BCM2835 ARM Peripherals manual.  Copyright is property of Broadcom corporation). 

In the course we want to set the 16th pin to an output pin so we need to write 001 to the 3 bits corresponding with the 16th pin.

When we make a drawing of the bits (starting from the GPIO address, so our bit 0 is address 0x20200000 in the tutorial). We get the following layout:

The upper row denotes the bit numbers. The second row will number the bytes and in the 3th row we mark the pin that corresponds with the bits. As explained in the course lesson, there corresponds 10 pins with 4 bytes.

The 4th row illustrates what happens if we write value one to 0x20200000.

ldr r0,=0x20200000
mov r1,#1
str r1,[r0]

The 5th row illustrates what happens if we write the shifted register to 0x20200000

ldr r0,=0x20200000
mov r1,#1
lsl r1,#18
str r1,[r0]

The 6th row shows the bits that are written when we write to [r0+4]. Because ARM uses a byte aligned layout the word will be written to bytes 4-7. So the full code part from the course lesson will give the result shown in row 7. The code fragment from the lesson was:

ldr r0,=0x20200000
mov r1,#1
lsl r1,#18
str r1,[r0,#4]

Next we need to now how to set the pin on (LED OFF) and how to set it off (LED ON).

The pin is cleared by writing a 1 to the relevant bit This is done using address 0x 7E20 0028 [GPCLR0] ( see Soc-Peripherals page 90). This word will be used for setting pins 0-31 , the next word will be for pins 32-54.

As denoted in the course we need to set the pin to 0 to set voltage high (led ON). We write a 1<<16 to the address 0x7E200028. But 0x28 = 40 so this gives the following to activate the LED:

mov r1,#1
lsl r1,#16
str r1,[r0,#40]

GPIO Pin Output set Register to set the pin on (LED OFF). This is done using address 0x 7E20 001C [GPSET0] ( see Soc-Peripherals page 90). This word will be used for setting pins 0-31 , the next word will be for pins 32-54.

Now we will set the 16th bit for the address with offset 0x1C = 28. This results in the code

mov r1,#1
lsl r1,#16
str r1,[r0,#28]

So now that you know this, you should head back to http://www.cl.cam.ac.uk/freshers/raspberrypi/tutorials/os and continue the courses. I think they are very good and it is good that the authors are so generous to share them for free with the rest of the world!

Friday, June 15, 2012

Shutdown an internal server using php (apache) in a more efficient matter.

In a previous post I explained a possible way to shutdown a server with a php page. (here)

Now I will provide a more efficient way using a cgi-script.

Pre-requisites for apache

In order for the code to work you'll have to make sure that the correct modules are loaded. We need the following to modules:

 LoadModule cgi_module /usr/lib/apache2/modules/mod_cgi.so
 LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so
 LoadModule suexec_module /usr/lib/apache2/modules/mod_suexec.so

When that is done we need to add a directory where we want to place our shutdown-script. e.g. /var/www/bin

 ScriptAlias /bin/ /var/www/bin/

We also need to define a user with whom we want to execute the script. This must not be a system user (i.e. it must be possible to login as the user account and uid must be greater then 500.)

 SuexecUserGroup username groupname

This will be all for the Apache configuration.

The script

First we create the directory and we make sure that the directory is owned by the same user as whom is going to execute the script.

 sudo mkdir /var/www/bin
 sudo chown username.groupname /var/www/bin

Within the script we just call the shutdown command. So create a script /var/www/bin/shutdown.cgi with contents:

 #!/bin/bash
 echo -e "Content-type: text/html\n" 
 # ^ Necessary HTTP header, needs to be finished with an empty line
 sudo /sbin/shutdown -h now

Give the script execute permissions:

 chmod +x /var/www/bin/shutdown.cgi 

Sudo without a password

If you were paying attention when reading the previous script you have noticed that we used sudo. The first time you use sudo you will be prompted for a password. But our command is executed in a script and we don't have a shell to enter the password! Luckily it is possible to setup sudo so no password is needed. Launch visudo to edit the configuration of sudo (If you have a favorite command-line editor you can set it temporary by executing 'export EDITOR=' before you start visudo. (You have to use -E argument for sudo to make sure you preserve the environmental variables) e.g.:

 export EDITOR=vi
 sudo -E /usr/sbin/visudo

Now add the following config rule to the configuration file:

 username   ALL=(ALL:ALL) NOPASSWD: /sbin/shutdown

This rule let you execute the /sbin/shutdown command on ALL hosts which are OWNED by ALL (=anyone) and part of group ALL (any group) and this without a password.

Test it

Make sure you restart apache and then test it!

 /etc/init.d/httpd restart
or
 /etc/init.d/apache2 restart

if you get an warning 'Warning: SuexecUserGroup directive requires SUEXEC wrapper.' then install the extra package for suexec 'sudo apt-get install apache2-suexec' and try to restart apache again.

When the server is restarted you an browse to http:///bin/shutdown.cgi and your system will shutdown immediatly. (No need for a cronjob anymore :-P).

Complete configuration file for apache:

Place it in a .conf file in the folder /etc/apache2/conf.d/ or /etc/httpd/conf.d/ (depending on your installation). For example shutdown.conf:
 
 LoadModule cgi_module /usr/lib/apache2/modules/mod_cgi.so
 
 
 LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so
 

 
 LoadModule suexec_module /usr/lib/apache2/modules/mod_suexec.so
 
 ScriptAlias /bin/ /var/www/bin/
 SuexecUserGroup username groupname

References

Sunday, April 8, 2012

Shutdown an internal server with a php page.

A more efficient way is posted on my more recent post .

For some reason, don't ask me why, it was very useful to me to shutdown a server using a http-request. This way I didn't have to go to the server to shut him down which is handy if it is locked away. Only for boot up I have to access the machine.

Pre-requisite is off course that a webserver is running on the machine, as there are plenty of tutorials to setup an Apache server I am not going to address that here.

Concept of the solution


In my solution I will be running a simple script every minute to check if a file exists. I the file exists, the script will remove the file and will shutdown the server, if not the script will do nothing. The reason I chose this solution is because it doesn't require much work :-).

The script


The content of the script is:

#!/bin/bash
if [ -f /tmp/shutdown ]
then
echo "HttpServerShutdown script called" >> /var/log/syslog
/bin/rm /tmp/shutdown
/sbin/shutdown -h now
fi

This script is saved as /var/remoteShutdown.sh. It is important to use the full path to the commands. If you use just the command it is probably not part of the path and it will not execute properly.

Trigger the script every minute.


We want to execute the script every minute. Luckily Linux has something like cronjobs. Because we use the shutdown command which should be executed with appropriate privileges, we will set cronjobs with sudo. To do this execute:
 sudo crontab -e 
If you have never added a cronjob, you can chose an editor to use. As I am a vi fan I use vi but if you don't know via chose another one :-). Nano is rather straightforward. Using the text editor append a line with the following content:

 * * * * * /var/remoteShutdown.sh


Make sure you save the crontab file.

PHP-page


As I have a default installation of Apache, my PHP pages are kept in /var/www. Create a file called shutdown.php with the following contents:

<?
echo "shutdown";
$file=fopen("/tmp/shutdown",'w');
fwrite($file,"pretty please");
fclose($file);
?>


That's it. Now you can browse to http://<serverIP>/shutdown.php and your server will shutdown.