Monday, January 19, 2009

Shrinking and Compressing Linux Virtual Image with Linux Host

I was always short of disk, because I have several virtual machines with my laptop. The virtual disk sizes grows fast, even the actual disk sizes I saw in the guest machine are much smaller. So, it's really necessary to shrink the disks from time to time. And, I also need a good compressor which can provide better compressing rate.

Since I run Linux guests in Linux host, it's a little tricky to shrink the disks. After googling and trying several approaches, I got following solutions:

Shrinking with X Based vmware-toolbox


vmware-toolbox is easy to use, but it requires X. Of cause, for most of my vms, I don't want a X server in them. So, remote X server helps now. With xauth (Debian package xbase-clients, or Yum package xorg-x11-auth), X forwarding works with SSH:

ssh -X user@vm

Then vmware-toolbox can be called, and the window will be forwarded to your desktop.

Notice: vmware-toolbox doesn't support logical volume. Please see the following section for shrinking virtual disk with logical volume.

Shrinking with Command Line


If there's no X forwarding for the guest machine, the virtual image can be shrinked with command line also. The brief steps are:

* Download VMWare Server 2 package and unpack vmware-vdiskmanager from it. I'm still using VMWare Server 1 now, since the browser based client doesn't work well with my Linux. But the vmware-vdiskmanager doesn't provide the feature of disk shrinking.
* Create symbol links for libcrypto.so.0.9.8 and libssl.so.0.9.8 . Assuming the vmware-vdiskmanager is placed in folder /usr/local/bin, then the symbol links are:

sudo mkdir -p /usr/local/bin/libdir/lib/libcrypto.so.0.9.8/
sudo ln -s /usr/lib/libcrypto.so.0.9.8 /usr/local/bin/libdir/lib/libcrypto.so.0.9.8/libcrypto.so.0.9.8
sudo mkdir -p /usr/local/bin/libdir/lib/libssl.so.0.9.8/
sudo ln -s /usr/lib/libssl.so.0.9.8 /usr/local/bin/libdir/lib/libssl.so.0.9.8/libssl.so.0.9.8

Now, the new vmware-vdiskmanager with disk shrinking (-p and -k) works.

Then, shrink the disk:
(Following content are based on http://communities.vmware.com/message/257602 .)
* Power on the guest machine, fill the file system with zero:

dd if=/dev/zero of=zerofile bs=1024k count=2048
rm zerofile

And swap partition also (assuming /dev/sda5 is the swap partition):

sudo swapoff
sudo if=/dev/zero of=/dev/sda5 bs=1024k count=2048

* Shutdown the virtual machine.
* Mount the virtual drive using the vmware-mount command; e.g.

sudo vmware-mount.pl debian40server.vmdk 1 -t ext3 /tmp/debian40/

* Using the vmware-vdiskmanager prepare disk for shrinking; e.g. using v: as mounted drive:

sudo /usr/local/bin/vmware-vdiskmanager -p /tmp/debian40/

* Unmount the drive.
* Shrink the disk (it's recommended to execute the following command with common user, instead of root):

/usr/local/bin/vmware-vdiskmanager -k debian40server.vmdk


Now, the disk is shrinked.

If there file system is in a logical volume of the virtual disk, manual operations of LVM are required for the shrinking (based on information available at http://seattlecentral.edu/cgi-bin/cgiwrap/dmartin/moin.cgi/VMware#head-b6e75c6b7ea67c9dd57b2adb91c9367ccaa24bcd and http://www.debuntu.org/how-to-install-ubuntu-over-lvm-filesystem):

# Make sure the VG in your VM is not the same as any VGs you have anywhere on your host box.
# Stop the VM
# load the nbd (Network Block Device) module into the running kernel
# Make sure you have /dev/nb* (use "MAKEDEV nb" if you don't)
# run "vmware-loop -p filename.vmdk" and note which partition you have your LVM on
# run "vmware-loop filename.vmdk partition-number /dev/nb*" to attach the file to the network block device
# run "lvmdiskscan" to make it re-scan the disks
# run lvscan to see the nice list
# run 'lvchange -ay volgroup' where volgroup is the volume group on your VM (Please try sudo modprobe dm-mod on "Incompatible libdevmapper" error.)
# run lvscan to see the nice list, this time with your VM's LVs listed as ACTIVE
# Mount and play with LVs
# Then jump to the step of vmware-vdiskmanager -p

Shrinking with Command Line


Then, comes to the second goal: a compressor with better compressing rate. I archived a virtual machine folder with GZIP, BZIP2 and 7Z. Following are the archive files I got:

-rwxrwx--- 1 root plugdev 195722873 2009-01-19 20:28 debian40server.7z
-rwxrwx--- 1 root plugdev 262460006 2009-01-19 20:29 debian40server.tar.gz
-rwxrwx--- 1 root plugdev 229599667 2009-01-19 20:34 debian40server.tar.bz2


Of cause, 7Z provides better compressing rate (and requires much longer compressing time). But, for me, it's worthy when comparing to the disk usage of versions of VM backups and transferring time cost over the network.

Labels: , ,

Saturday, January 17, 2009

Web API for Getting Latitude & Longitude with Address or GSM Cell ID

I developed a small web application, which provide a Web API for geting latitude and longitude with address or GSM cell ID.

To use it, just access it with the address or GSM cell ID/lac as parameters in URL:

http://marklet.appspot.com/geolocator/cellid?cellid=30559&lac=4471
http://marklet.appspot.com/geolocator/address?addr=北京王府井&of=xml


UTF-8 is supported for parameter addr.

Accepted of(output format) values:

  • text
  • xml


This Web API is implemented based on Google Maps service.

Labels: , , ,

Wednesday, January 7, 2009

Ubuntu IEs4Linux Installation

IEs4Linux is good. I used to access OWA(outlook web access) with Firefox, but OWA provides a very poor UI for browsers other than IE. I tried to provide a faked Agent field, but the page is incompatible with Firefox.

So, I tried IEs4Linux, and got IE 6 works with Ubuntu and OWA now. But I did found some issues during the installation.

* Corrupted DCOM98.EXE. Solution:

./ies4linux --no-gui

* swflash.cab: no valid cabinets found. Solution: download http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 manually, place the file in ~/.ies4linux/downloads, and install it again.

Update: Beautifying Chinese fonts for Wine.

Labels: , ,

地图偏移真和谐

自己随便拿 GSM Cell ID 做了个 Google Map 跟踪玩,赫然发现地图都便得厉害,差不多800米吧。查了一下,据说是:“这是国际惯例。大多数政府都规定航拍图必须人工加入位置偏移,不能给真实的GPS信息。这都有算法。”当然,看看后面,不明真相的群众们不会这么接受有XX特色的国际惯例的。

虽然有人说:“Google 地图手机版图层误差消失。“我试了一下,一般的搜索是没有偏了,可当我查询经纬度(如 39.974496,116.301469)时,还是有的。

很好,很和谐。广大不明真相的群众都在踊跃修正地图。

Labels: ,

Saturday, January 3, 2009

Multiple Keys Wireless Mouse for X Windows

I bought a Rapoo 7100 wireless mouse weeks ago. It works with Ubuntu without changes of settings. But the multiple keys at left side act as right key and middle key. I tried ZAxisMapping of xorg.conf and xmodmap but it doesn't help. So, I found evdev.

Following are some configuration files I used:

/etc/hal/fdi/policy/10-x11-input.fdi for enabling hal for evdev:


<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
<device>
<!-- FIXME: Support tablets too. -->
<match key="info.capabilities" contains="input.mouse">
<merge key="input.x11_driver" type="string">mouse</merge>
<match key="/org/freedesktop/Hal/devices/computer:system.kernel.name"
string="Linux">
<merge key="input.x11_driver" type="string">evdev</merge>
</match>
</match>

<match key="info.capabilities" contains="input.keys">
<!-- If we're using Linux, we use evdev by default (falling back to
keyboard otherwise). -->
<merge key="input.x11_driver" type="string">keyboard</merge>
<match key="/org/freedesktop/Hal/devices/computer:system.kernel.name"
string="Linux">
<merge key="input.x11_driver" type="string">evdev</merge>
</match>
</match>
</device>
</deviceinfo>


Disable other input devices for xorg in xorg.conf:

# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig: version 1.0 (buildmeister@builder26) Thu Feb 14 18:13:41 PST 2008

# nvidia-settings: X configuration file generated by nvidia-settings
# nvidia-settings: version 1.0 (buildmeister@builder26) Wed Sep 12 14:29:53 PDT 2007
# xorg.conf (xorg X Window System server configuration file)
#
# This file was generated by failsafeDexconf, using
# values from the debconf database and some overrides to use vesa mode.
#
# You should use dexconf or another such tool for creating a "real" xorg.conf
# For example:
# sudo dpkg-reconfigure -phigh xserver-xorg

Section "ServerLayout"
Identifier "Default Layout"
Screen 0 "Screen0" 0 0
# InputDevice "Generic Keyboard"
# InputDevice "Configured Mouse"
# InputDevice "Synaptics Touchpad"
Option "AutoAddDevices" "off"
EndSection

Section "Files"
EndSection

Section "Module"
Load "glx"
Load "v4l"
EndSection

Section "ServerFlags"
Option "Xinerama" "0"
EndSection

#Section "InputDevice"
# Identifier "Generic Keyboard"
# Driver "kbd"
# Option "CoreKeyboard"
# Option "XkbRules" "xorg"
# Option "XkbModel" "pc105"
# Option "XkbLayout" "us"
#EndSection

#Section "InputDevice"
# Identifier "Configured Mouse"
# Driver "mouse"
# Option "CorePointer"
# Option "Device" "/dev/input/mice"
# Option "Protocol" "ImPS/2"
# Option "ZAxisMapping" "4 5"

# Option "ZAxisMapping" "6 7"
# Option "Buttons" "7"
# Option "ButtonMapping" "1 2 3 6 7 8 9 10 11"

# Option "Emulate3Buttons" "true"
#EndSection

#Section "InputDevice"
# Identifier "Synaptics Touchpad"
# Driver "synaptics"
# Option "SendCoreEvents" "true"
# Option "Device" "/dev/psaux"
# Option "Protocol" "auto-dev"
# Option "HorizScrollDelta" "0"
#EndSection

Section "Monitor"
Identifier "Failsafe Monitor"
VendorName "Generic LCD Display"
ModelName "LCD Panel 1280x800"
HorizSync 31.5 - 50.0
VertRefresh 56.0 - 65.0
Gamma 1
ModeLine "800x600@56" 36.0 800 824 896 1024 600 601 603 625 +hsync +vsync
ModeLine "800x600@60" 40.0 800 840 968 1056 600 601 605 628 +hsync +vsync
ModeLine "1280x768@60" 80.1 1280 1344 1480 1680 768 769 772 795 -hsync +vsync
ModeLine "1280x720@60" 74.5 1280 1336 1472 1664 720 721 724 746 -hsync +vsync
ModeLine "1280x800@60" 83.5 1280 1344 1480 1680 800 801 804 828 -hsync +vsync
EndSection

Section "Monitor"

#
Identifier "monitor1"
VendorName "Plug 'n' Play"
ModelName "Plug 'n' Play"
Gamma 1
ModeLine "640x480@60" 25.2 640 656 752 800 480 490 492 525 -hsync -vsync
EndSection

Section "Monitor"
Identifier "Monitor0"
VendorName "Unknown"
ModelName "Seiko"
HorizSync 30.0 - 75.0
VertRefresh 60.0
EndSection

Section "Device"
Identifier "Failsafe Device"
Driver "nvidia"
BoardName "vesa"
Option "NoLogo" "true"
BusID "PCI:1:0:0"
Screen 0
EndSection

Section "Device"

#
Identifier "device1"
Driver "nvidia"
BoardName "vesa"
Option "NoLogo" "true"
BusID "PCI:1:0:0"
Screen 1
EndSection

Section "Device"
Identifier "Videocard0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BoardName "Quadro NVS 135M"
EndSection

Section "Screen"
Identifier "Default Screen"
Device "Failsafe Device"
Monitor "Failsafe Monitor"
DefaultDepth 24
SubSection "Display"
Virtual 1280 800
Depth 24
Modes "1280x800@60" "1280x720@60" "1280x768@60" "800x600@60" "800x600@56"
EndSubSection
EndSection

Section "Screen"

#
Identifier "screen1"
Device "device1"
Monitor "monitor1"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "640x480@60"
EndSubSection
EndSection

Section "Screen"
Identifier "Screen0"
Device "Videocard0"
Monitor "Monitor0"
DefaultDepth 24
Option "TwinView" "0"
Option "metamodes" "1280x800_60 +0+0; 800x600@60 +0+0"
Option "NoLogo" "true"
Option "RenderAccel" "True"
Option "AddARGBGLXVisuals" "True"
SubSection "Display"
Depth 24
Modes "nvidia-auto-select"
EndSubSection
EndSection

Section "Extensions"
Option "Composite" "Enable"
EndSection

Labels: , ,