Friday, June 24, 2011

Generate MySQL PASSWORD using command line

$ echo -n foo | openssl sha1 -binary | openssl sha1 | tr 'a-z' 'A-Z' | sed 's/^/\*/'

Make sure old_passwords=0 in your /etc/my.cnf

Wednesday, June 15, 2011

Qemu creates a spurious 23.1 MB ATA QEMU HARDDISK

I invoke qemu as follows

$ sudo kvm -drive file=ub-master.qcow2,if=virtio,index=0 -drive file=/home/amitava/iso/ubuntu-1104-mini.iso,media=disk,boot=on -m 512 -net nic -net tap -vnc -monitor stdio

By specifying the cdrom as in the 2nd -drive above, it creates a spurious drive "23.1 MB ATA QEMU HARDDISK" and ubuntu-1104-mini.iso installer fails to install grub properly. The fix is easy enough, just use the traditional -cdrom option instead as

$ sudo kvm -drive file=ub-master.qcow2,if=virtio,index=0 -cdrom /home/amitava/iso/ubuntu-1104-mini.iso -m 512 -net nic -net tap -vnc -monitor stdio

Thursday, June 9, 2011

Solution to jruby bug# 5730 - gem update --system fails

ashee:hooks amitava$ ruby --version
jruby 1.6.2 (ruby-1.9.2-p136) (2011-05-23 e2ea975) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_24) [darwin-x86_64-java]
ashee:hooks amitava$ gem update --system
Updating RubyGems
ERROR: While executing gem ... (NoMethodError)
undefined method `version' for nil:NilClass
ashee:hooks amitava$ gem update --system -V --backtrace
Updating RubyGems
ERROR: While executing gem ... (NoMethodError)
undefined method `version' for nil:NilClass
/Users/amitava/.rvm/rubies/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/commands/update_command.rb:137:in `update_rubygems'
/Users/amitava/.rvm/rubies/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/commands/update_command.rb:54:in `execute'
/Users/amitava/.rvm/rubies/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/command.rb:278:in `invoke'
/Users/amitava/.rvm/rubies/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:133:in `process_args'
/Users/amitava/.rvm/rubies/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:103:in `run'
/Users/amitava/.rvm/rubies/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:63:in `run'
/Users/amitava/.rvm/rubies/jruby-1.6.2/bin/gem:25:in `(root)'

rvm install jruby does not install the rubygems-udpate gem on which gem update --system relies on.

Just install rubygems-update and re-run gem update --system

ashee:~ amitava$ gem install rubygems-update
Fetching: rubygems-update-1.8.5.gem (100%)
Successfully installed rubygems-update-1.8.5
1 gem installed
ashee:~ amitava$ gem update --system
Updating RubyGems
Updating RubyGems to 1.8.5
Installing RubyGems 1.8.5
RubyGems 1.8.5 installed

=== 1.8.5 / 2011-05-31

* 2 minor enhancement:

* The -u option to 'update local source cache' is official deprecated.
* Remove has_rdoc deprecations from Specification.

* 2 bug fixes:

* Handle bad specs more gracefully.
* Reset any Gem paths changed in the installer.


RubyGems installed the following executables:

ashee:~ amitava$

Monday, June 6, 2011

KVM bare metal as non-privileged user

I usually drive kvm via libvirt. Mostly via handcrafted xml files. But I want to run kvm (qemu-system-x86_64) directly without virsh and libvirt and ran into the following permission issue.

open /dev/kvm: Permission denied

Turns out ubuntu 10.04 does not grant permissions to "kvm" group on /dev/kvm. So I had to add an udev rule as specified in FAQ.

$ cat /etc/udev/rules.d/40-permissions.rules
KERNEL=="kvm", GROUP="kvm"

Trying to run on SDL did not work for me. I have a minimalistic host

(!) Direct/Util: opening '/dev/fb0' failed
--> Permission denied
(!) DirectFB/FBDev: Error opening framebuffer device!
(!) DirectFB/FBDev: Use 'fbdev' option or set FRAMEBUFFER environment variable.
(!) DirectFB/Core: Could not initialize 'system_core' core!
--> Initialization error!
Could not initialize SDL - exiting

-curses option did not work for me either, so I used vnc on a local port.

Here's the final command to launch kvm

$ qemu-system-x86_64 -hda ub1104-master.qcow2 -m 512 -boot d -cdrom /home/amitava/iso/ubuntu-1104-mini.iso -vnc ""

And here's the command in my macbook to create an ssh tunnel for my vnc client (Chicken of the VNC)

$ ssh -L 5905: # invoke vnc client afterwards

Now I have a master qcow2 image that I can clone in less than a minute to spawn a vm guest. And it takes just 14Mb for a guest with nginx-light - thanks to qemu's copy-on-write (COW).

On a final note - ubuntu 11.04 guest (minimal vm guest) boots fine but fails to show the login prompt. I had to switch to virtual console 2 and back to 1 (Ctrl+Alt+2 & Ctrl+Alt+1) to get the prompt.