How to automate virtual machine creation and runing on virtualbox by command line

June 29, 2011 by · 2 Comments
Filed under: linux, virtualization 

Many times we need to create a linux virtual machine by command line.
It is very useful for batch vm operation, automation, regression test, integration test…
Here’s the steps to create a functional linux virtual machine (works on windows host && linux host).

These steps has been tested on Debian squeeze x64 with kernel version of 2.6.32, and windows server 2003 x64 .
Note for windows users: Make sure you have put virtualbox directory to PATH variable. (Press Win+Break , click “Advanced”-> “Environment Variables”, find the PATH variable, and append virtualbox path to the variable.)

1.Create a virtualbox vm and register the vm

vboxmanage createvm -name testvm -register
vboxmanage showvminfo testvm

The showvminfo command shows information about created virtual machine.

2.Specifiy network adapter and setting boot order

vboxmanage modifyvm “testvm” –memory 768 –vram 64 –acpi on –boot1 dvd –nic1 bridged –bridgeadapter1 eth0

vboxmanage list ostypes

vboxmanage modifyvm “testvm” –ostype “linux26”

The list command shows all available system types. If you don’t want your vm connect to network directly by bridged network,
then change the arguments after –nicX, see manual:

3.Create virtual disk for file storage with specified size(2G)

vboxmanage createvdi –filename “/data/vm/testvm-disk01.vdi” –size 2048 –remember

4.Set boot up order and add an IDE controller
vboxmanage storagectl testvm –name “IDE Controller” –add ide
vboxmanage modifyvm “testvm” –boot1 dvd –hda “/data/vm/testvm-disk01.vdi” –sata on

Now a virtual machine has been created and register, let’s go to step 5 specify the booting iso file,
and boot into linux.

5.Specify ISO file as DVD (the installation iso or live iso)
I use tinycore, and put the iso at /data/vm.

Attach virtual disk testos.vdi to the 0th port at device 0:
vboxmanage storageattach testvm –storagectl “IDE Controller” –port 0 –device 0 –type hdd –medium “/data/vm/testvm-disk01.vdi”

Attach the ISO at the 1th port at device 0:
vboxmanage storageattach testvm –storagectl “IDE Controller” –port 1 –device 0 –type dvddrive –medium /data/vm/tinycore_3.6.iso

vboxmanage modifyvm “testvm” –dvd /data/vm/tinycore_3.6.iso

6、Boot the virtual machine

vboxmanage startvm “testvm”

For linux users , if error like “The character device /dev/vboxdrv does not exist, lease install the virtualbox-ose-dkms package and the appropriate headers, most likely linux-headers” occured.

Then you probably run the following command by root:
modprobe vboxdrv
modprobe vboxnetflt

To poweroff the virtual machine, just run the command:
vboxmanage controlvm testvm poweroff

To boot the virtual machine in headless, so it starts without virtual box gui, it is useful for virtual server.
And you can put the command to start up script, it works on windows and linux:
vboxmanage startvm “testvm” –headless

To show detail information of the virtual machine:
vboxmanage showvminfo testvm –details

Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

debian squeeze搭建最简xfce4开发环境(二 常用软件及问题解决)

May 27, 2011 by · Comments Off on debian squeeze搭建最简xfce4开发环境(二 常用软件及问题解决)
Filed under: linux to install xfce4 and choose x window manager

sudo apt-get install xfce4
sudo update-alternatives –display x-window-manager
sudo update-alternatives –config x-window-manager

中文支持参考:Debian简明中文支持 32 bit applications:

sudo apt-get install ia32-libs
sudo apt-get install ia32-libs-gtk

then qq, forti ssl vpn client all works.

3. how to change locale & time

sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime


u also may use tzselect to change time zone.

4. how to automatically keep an active network always on desktop, && use wireless network

sudo apt-get install network-manager
sudo apt-get install wicd
sudo apt-get install firmware-iwlwifi

sudo apt-get install network-manager-gnome

To use network-manager-gnome in Xfce (or Gnome) you need to have the applet running in the sytem tray.
In Gnome this is automatic but in Xfce you need to set it up initially. Fortunately this is very easy:

Alt + F2 to run a command:  nm-applet –sm-disable

network manager is used for keeping an active network always for desktop.
Wireless network is disabled by default, rith click on the desktop network icon, choose “Enable Wireless”, it shall works.
默认无线是关闭的,右键点击桌面工具栏上的网络连接图标,选中”Enable Wireless”,即可使用无线网络.


WICD network manager,网络的连接和中断通知默认是关闭的,可以在Preferences里面勾上 Notification.
如果没有在Preferences里面输入wireless interface,WICD默认是找不到无线网络的,通常输入wlan0即可。

Wicd network manager -> Network -> Find a hidden network

5. no auto completion in shell ?
default shell is sh, change user’s default shell to bash in /etc/passwd

6. common tools
krusader, firefox, eclipse, gedit, geany
execute query, rdesktop
File manager: gnome-commander, Tux commander, emelFM2  —————–

—- sudo apt-get install tuxcmd tuxcmd-modules
sudo apt-get install gnome-commander

gnome-commander is a two panel file manager with drag & drop support ( tux does not support drag & drop)

xfce4-terminal: a terminal support tab & copy, paste
sudo apt-get install xfce4-terminal

geany is a full functional text editor in xfce.
geany 的快捷键与scim的Ctrl+Space有冲突,切换不了中文输入法,更改快捷键后即可。

sudo apt-get install netwox ssh nmap rdesktop less
sudo apt-get install ftp curl aria2 unrar-free unzip xarchiver
sudo apt-get install subversion git git-svn rapidsvn meld diffuse
sudo apt-get install memcached mongodb redis-server nginx memcachedb mysql-server

sudo apt-get install epdfview evince
sudo apt-get install to install flash player for fixfox?

sudo apt-get install flashplugin-nonfree


download flash player from adobe, extract the compressed file, copy to /usr/lib/mozilla/plugins
sudo cp /usr/lib/mozilla/plugins
then restart firefox

8. change daily updatedb settings in :
vi /etc/cron.daily/locate

9. multiple monitor support
sudo apt-get install grandr


10. how to control services to automatically start
sudo apt-get install rcconf
sudo rcconf

or :

sudo update-rc.d -f {SERVICE-NAME} remove

For example to stop xinetd service at boot time, type the command as follows:
# update-rc.d -f xinetd remove

11. 退出图形界面后,键盘按键没反应,但可以按Alt+Tab切换应用程序,切到其他的应用再切回来就ok了。

这个问题很有历史了。 Debian BTS 见 [1][2] , Ubuntu Launchpad 见 [3] 。                                                        2
这个问题很有历史了。 Debian BTS 见 [1][2] , Ubuntu Launchpad 见 [3] 。
解决办法,一是 patch libX11 ,二是改 scim 配置文件,但后者会影响欧洲字符的输入。


sudo vi /etc/scim/config
vi ~/.scim/config

logout, 重新登录

12.debian apt-get下载的包存放在哪里?


13.如何使得apt-get install下载的更快

从 下载,



chmod +x

sudo cp /usr/local/bin
推荐使用 apt fat with aria2c 来从多个源下载来提高速度,


chmod +x

sudo cp /usr/local/bin
然后使用 install xxxx来安装软件包,设置多个mirrors时,速度会快上很多倍。比如安装mplayer, smplayer以及cd播放器:
sudo install mplayer smplayer cdcd

14. 没有正确的电源状态显示

Problem: acpi could not detect battery status, and shows unkown battery as:


Battery 0: Unknown, 0%


比如Acer的很多笔记本默认BIOS的ACPI支持不好,我的是Aspire 4745G, 需要刷bios。
Aspire 4745G 可以在这里下载,下载之后在windows下运行程序刷新bios。

然后,确保内核支持acpi, 并在启动参数中增加acpi=on,debian squeeze安装的默认内核是支持acpi的, 增加acpi=on即可:
vi /boot/grub/grub.cfg:

linux   /boot/vmlinuz-2.6.32-5-amd64 root=/dev/hda9 ro acpi=on quiet


sudo apt-get install powertop cpufrequtils laptop-mode-tools



Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

debian squeeze搭建最简xfce4开发环境(一 Debian简明中文支持)

May 27, 2011 by · 2 Comments
Filed under: linux 

1.1 for chinese locale support:
dpkg-reconfigure locales

select all locales like zh_CN.***, zh_TW.***

1.2 how to install chinese fonts

apt-get install ttf-bitstream-vera msttcorefonts  (seems no use)
apt-get install xfonts-wqy ttf-wqy-zenhei

for MS windows fonts, copy Chinese font to /usr/local/share/fonts
sudo cp /data/debian/fonts/* /usr/local/share/fonts
sudo fc-cache

for free fonts:
sudo apt-get install ttf-arphic-*




cp fonts.conf_.txt  ~/.fonts.conf
cp local.conf_.txt  /etc/fonts/local.conf

set firefox Chinese minimal font to 14-15, Western font to 18.

1.3 input method:
apt-get install scim scim-pinyin scim-tables-zh

vi /etc/X11/Xsession.d/95xinput
to create a new file 95xinput with the following content:
/usr/bin/scim -d
export GTK_IM_MODULE=xim

the last line is meant to be able to use scim input method in firefox

1.4 support chinese in jdk gui.
Here is the way (two steps):
1). make a directory fallback under JavaHome/lib/fonts/
2). add a Chinese TrueType or Type 1 font under fallback

An example:
mkdir /usr/lib/j2sdk1.5-sun/jre/lib/fonts/fallback
ln -s /usr/share/fonts/truetype/arphic/gbsn00lp.ttf .
ln -s /usr/local/share/fonts/simhei.ttf .


Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

debian 6.0(Squeeze)硬盘安装

April 11, 2011 by · Comments Off on debian 6.0(Squeeze)硬盘安装
Filed under: linux 

在linode上搭起来了服务器,根据淘宝朋友的推荐,选了debian操作系统。考虑到软件的多样性,os对网络的依赖度,在笔记本上选择装上debian发行版,下载了debian的8张DVD,这样就不用基于网络安装软件了, 直接挂载iso。 原本debian的网络安装很方便,谁让我们在TG。

由于光驱不太好用,就试着从硬盘安装squeeze, squeeze比原先的woody,etch好装了不少, 从windows安装还是不如ubuntu,自动的iso挂载也只能挂载fat32分区的, 由于fat32分区存不了4G的dvd iso,只能放安装的CD ISO,debian里面的第1张CD里面没有gnome/kde,我安装时选了X window,装X Window是从网络安装的,花了1个多小时,还是宽带是5M的,不然不可想象要花多长时间。 如果能用光驱,建议用刻盘来安装。 总结一下安装步骤:

1. 准备好grub。由于我的操作系统是windows 7, grub用起来不如XP方便,就先装了Maxdos 8,然后把grub4dos解压后放到fat32分区。

如果是Windows NT/2000/XP直接修改C:\boot.ini,增加这样一行:

2. 准备一个fat32分区,把安装的iso cd拷贝到某个fat32分区的根目录。 iso cd可以从任一一个镜像下载,如: (中国访问这个比较快) (中国访问这个比较快)

由于硬盘上都是ntfs分区,我就拿usb的分区(fat32)来访iso cd。
同时下载 debian硬盘安装需要的3个引导文件(这步很重要)vmlinuz, initrd.gz, boot.img.gz,拷贝到c:\盘根目录


3.编辑前面解压的grub2dos中的menu.lst, 加入如下内容
title hd – Install Debian
root (hd0,0)
kernel /vmlinuz
initrd /initrd.gz

这一步骤可省略, 若省略,后面启动grub后,手工进入grub的command交互控制台,输入对应的root, kernel, initrd几个命令,再输入boot回车来启动debian安装界面。

4. 引导进入grub:启动机器,进入maxdos,再选择进入纯dos。 然后cd 到grub所在目录,运行grub.exe进入grub引导界面。

5.在grub引导界面选择”Install Debian”启动debian安装过程。若第3步没有编辑menu.lst,则可以手工输入grub命令来引导。

6.安装的过程中,会自动从fat32分区查找iso文件。 找到后根据提示执行安装即可。 如果网络状况不好,用iso cd装就不要选择X Window图形界面了, 装好了基本系统启动后再通过命令安装X Window,因为第1张iso cd里面没有X Window。

Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)