Friday, February 29, 2008

Virtual drives on linux

One of the issues I was facing in my linux migration efforts was how to create and use virtual drives, so that I can mount ISO images of CDs etc.

So here is how to do it..

Virtual devices are achieved in linux using loop devices.
To create a new loop device, we use the losetup command. For eg. say we need to mount the cd image file /temp/varmathe/damn-small-linux.iso ad a cd drive. Here is how to do it.

1. Locate the first available loop device
opensuse103-vm:/temp/varmathe # losetup -f
/dev/loop0
2. Associate this device node to the iso file
opensuse103-vm:/temp/varmathe # losetup /dev/loop0 damn-small-linux-3.4.4.iso
3. Now mount the cd somewhere on our filesystem hierarchy.
opensuse103-vm:/temp/varmathe # mount -t iso9660 /dev/loop0 /mnt/vcd
opensuse103-vm:/temp/varmathe # cd /mnt/vcd
opensuse103-vm:/mnt/vcd # ls
boot index.html KNOPPIX lost+found
Additionally, it might be a wise idea to mount cd/dvd images etc as read only..

4. Use the volume.. (he he :D )

5. Now that we are done and want to unmount the device and release the file
opensuse103-vm:/temp/varmathe # umount /mnt/vcd
opensuse103-vm:/temp/varmathe # losetup -d /dev/loop0
The -d option detaches the file from the loop device

Steps 1,2, and 3 can be combined into a single step as
opensuse103-vm:/home/varmathe # mount -t iso9660 -o loop /temp/varmathe/damn-small-linux-3.4.4.iso /mnt/vcd
While the above single step approach looks like it should have been explained first; I deliberately explained the broken approach for a reason. If you only need the device node, say for eg, to pass that on to a virtual machine; then you don't need to do the mount.. The "losetup" steps alone would do.

.

Wednesday, February 20, 2008

C++ language standards

Find the official standards for the language at

http://www.open-std.org/jtc1/sc22/wg21/

A GPL licensed thorough c++ reference

http://www.icce.rug.nl/documents/cplusplus/

A bunch of open source c++ libraries

http://www.boost.org

.

Wednesday, February 13, 2008

Setting up qemu with networking on a linux host

I wanted to install Qemu with networking enabled on my linux box (Which incidentally is on a Virtual Machine built on vmware). Through the setting up process, I had a tough time figuring out how to go about with the whole thing as I could not find any single document which precisely described what I wanted. But anyways, now I've figured it all out.. And so I've decided to share whatever I've garnered with you through this post.

Objective: To set up Microsoft Windows XP on a Qemu simulated PC with an OpenSUSE 10.3 linux box serving as host.

Host machine: OpenSUSE 10.3 linux on Intel i386 based PC

Packages used:
qemu-0.9.1-i386.tar.gz : http://fabrice.bellard.free.fr/qemu/
vde2-2.1.6.tar.gz : http://vde.sourceforge.net/

I wanted to compile qemu from source, but apparently qemu needs the gcc3.x compilers whereas OpenSUSE 10.3 I have on my system has the gcc4.x version.

Step1: extract qemu-0.9.1-i386.tar.gz int '/' as root.

Step2: extract vde2-2.1.6.tar.gz into a temporary location and build it
./configure
make
and then as root

make install
Step3: (As root) set up a VDE switch with one port connected to the host using a tap interface
host$ vde_switch -s /tmp/switch -tap tap0 -m 666 [-daemon]

The "-daemon" part is option; it will cause vde_switch to run in the background, whereas, if you do not give it, you get access to the switch console
Step4: (As root) set up an ip address for the newly created tap interface on the host
host$ ifconfig tap0 10.0.0.1
Step5: set up our virtual machine. For this,
5.1 Create a working directory for the machine and copy bios files into it.
host$ mkdir qemu-vm
host$ cd qemu-vm
host$ cp /usr/local/share/qemu/{bios,vgabios-cirrus}.bin ./
5.2 Create a disk for the machine.
host$ qemu-img -f qcow win-xp.qcow 4G
5.3 Now start the virtual machine as follows, with the windows-XP CD in the /dev/cdrom drive. Have the Product key ready at hand.
host$ vdeqemu -L . -m 128 -boot d -hda win-xp.qcow \
-cdrom /dev/cdrom -soundhw all -localtime -M pc \
-net nic,vlan=0 -net vde,vlan=0,sock=/tmp/switch
here, "-m 128" gives the virtual machine 128 mb RAM
"-boot d" makes cdrom as the default boot device.. Later you can set this to "-boot c" once you have an OS installed on the hard disk, to make hard disk as the default
"-net nic,vlan=0" adds one network interface card onto the virtual machine
"-net vde,vlan=0,sock=/tmp/switch" connects the above NIC to the switch we created.

5.4 When the system boots up, install windows on this guest machine. You will notice that it has one ethernet adapter for which the cable is already plugged (to our switch as we specified).

5.5 Configure IP address on this interface so that this interface is on the same Network (subnet) as the host's tap interface. In our case, we use "10.0.0.2" as the IP. Also set the guest's default gateway as 10.0.0.1 and provide your service provider's DNS ip to the guest.
Step6: Now you can try pinging 10.0.0.1 from the guest and 10.0.0.2 from the host. You will see that the pings go through successfully. However, the guest still cannot access the internet. For this we need to set up NAT (Network Address Translation) on the host ( or some form of bridging b/w the tap0 interface and the host's eth0 interface)

Step7: (As root) Set up the NAT.
host$ echo "1" > /proc/sys/net/ipv4/ip_forward
host$ iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
host$ iptables -A FORWARD -i tap0 -o eth0 -j ACCEPT
host$ iptables -A FORWARD -i eth0 -o tap0 \
-m state --state RELATED,ESTABLISHED -j ACCEPT
Now we are up and running!!



References:
[1] http://wiki.virtualsquare.org/index.php/VDE_Basic_Networking

.

Tuesday, February 12, 2008

FreeBSD

Check out the freeBSD operating system.

Another member of the family of UNIX operating systems.

Ports to most common comp architectures available.

http://www.freebsd.org

.

qemu

A sexy emulator !

Qemu: http://fabrice.bellard.free.fr/qemu/
Qemu for Windows: http://www.h7.dion.ne.jp/~qemu-win/

This program can emulate x86, MIPS, Sparc, ARM, PPC etc. I tried both the windows and linux x86 versions.. on the windows version, I tried loading a linux livecd.. And on the linux version, I tried out Windows XP

The project is still under development though.. Some bugs here and there are evident. I didn't like the networking support for the thingy. And I hate having to type out configs.. vmware virtualPC etc are gorgeous for their GUI alone, I'd say. Yet, neither vmware nor virtualPC support that entire gamut of processors, and best of all, this thing is FREE !

------------------------------------
Related links I found to be useful..

The OpenVPN tool which can be used for host-only networking / bridged networking on a windows host: http://openvpn.net/
- a how to for the same: http://www.h7.dion.ne.jp/~qemu-win/TapWin32-en.html

VDE - Virtual Distributed Ethernet, to use for host-only / bridged networking on linux hosts: http://vde.sourceforge.net/
- how to: http://wiki.virtualsquare.org/index.php/VDE_Basic_Networking

.

autobook

A free online book on Autoconf Automake and Libtool..
http://sourceware.org/autobook/

For all those people who have been mystified by
./configure
make
make install
I'm yet to read the book.. Placing this post lest I lose the url

--------- --------- --------- --------- --------- --------- --------- ---------
(2008-05-12)
Another book on auto-tools

http://www.freesoftwaremagazine.com/books/autotools_a_guide_to_autoconf_automake_libtool

.

Saturday, February 9, 2008

Linux from the scratch !

Learn to
- install linux from source yourself
- build liveCDs and distributions
- build embedded linux systems
and lot more

http://www.linuxfromscratch.org/

.

Thursday, February 7, 2008