Showing posts with label how-to. Show all posts
Showing posts with label how-to. Show all posts

Wednesday, January 13, 2010

Watching TV and Linux

This all started a couple of weeks ago when I finally got around to putting the tv capture card I had picked up a year or two ago into my computer. Happily like most things in Linux, it just worked, that was a great plus. Sadly the software packages in existence that I ran across were either too much or too little, nothing was just right.

What I wanted was to be able to open up a window, tack it to the desktop in always on top mode, and leave it in the corner taking up some but not all of my screen real estate. I also wanted the ability to pause it, so that I could get up, grab a cup of coffee, hit the head, or what ever. Guess what, this falls into the "good luck with that" category of having had someone scratch that particular coding itch.

For the watching TV in a window, I found several applications, such as tvtime and xawtv. Both are good and configurable. Excellent for what they were designed for which was simply just watching TV, either in a window or fullscreen. Sadly of all of the light weight applications I played with they all lacked the second critical function, the ability to pause. So while I decided to keep tvtime on my system because it is rather a nice piece of software the search must continue.

I decided then to explore mythtv. I had read about it several times over the years and finally had a reason to do more than think about it. I knew that it had the ability to record TV, watch movies, and basically handle being a home theater system. Holy unfriendly overkill batman. By the time I had it compiled (I was doing this on a Funtoo system) I was mildly annoyed at the collection of dependencies that had to be pulled in. That annoyance was nothing compared to trying to configuring it.

Between the documentation, complete and utter lack of editable configuration files, a configuration UI that is among the unfriendliest and unintuitive I have ever seen, and an IRC help channel slightly less friendly than the Spanish Inquisition. I think maybe I would prefer to spend a month at a nudist colony with a porcupine infestation than get near that project again.

OK, enough of a sideline about mythtv, needless to say I did get it up and running. I then decided that while it was not completely unsuited to that task at hand, it was exactly what I did not want. Not to mention it still didn't do exactly what I wanted. Which was simply a window in the corner that I could play/pause.
** It was brought to my attention that mythtv will indeed start in a windowed mode
** thanks for correcting my misstatement Dinotrac. Still it's a level of overkill I do not need.

So I decided to set about doing for myself what I could not find an existing application for. While I had been playing with the capture card and software for it, I found that I could watch TV using mplayer, or record TV using mencoder (part of mplayer). Armed with this dangerous knowledge I figured I could wrap everything up in a script to do what I wanted. I was right too. With one script I can watch TV, play/pause, and as an added bonus, when I close the window I was using to watch TV, it asks me if I want to save the streams I had been watching.

There are only two packages that you need for this script, mplayer and xdialog. Actually xdialog is only if you want it to ask you if you want to save the streams and easy file clean up. Alternately you could just change that portion of the script to : rm $location/$filename.avi to have it clean out all the files when you shut mplayer off.

So here you go:
Click here for the script

UPDATE:
Added file rename when save file is selected. Cleaned up spurious text for those using dialog rather than xdialog. Broke up the mencoder command for easier reading and added deinterlacing to it.

Version 2 of the script

Blogspot mangles code snippets, so its in a pastebin. Personally I dropped the script into /usr/bin/ did chmod 755 on it, and use it as I would any other program. So you could make a desktop shortcut, add it to a menu or do what I did. I mapped it to a spare unused key on my keyboard, so now I have TV at the push of one button.

Saturday, June 13, 2009

Automated LVM mounting script

After having had enough of walking people through how to mount a LVM from a LiveCD I finally got eternally tired of if. This script was done entirely in self defense, however as it is meant to be run to rescue an installation that was done on LVM, it might be handy for a few others as well as it boils down to just 4 commands ... OK one of them is a chained command, but whose counting.

Please note, this script needs to be run with root priveledges and was written to run using LVM2.

I hope it helps someone else.

p.s. sorry for the text size, but it was the only way to keep the formatting correct.


#! /bin/bash
## This script is released under the GPL version 2
## copyright (2009) James Cook
## Thanks goes to Klaus Knopper who reminded me of something
## very simple that I had forgotten at the time, thanks bud.
## the author may be contacted at:
## azerthoth (at) gmail.com

## Check for user is root
## Thanks to micia for the suggestion
if [ $UID -ne 0 ]; then
echo "You need to be root to run this script!"
exit 1
fi
## get them all into /dev/mapper
modprobe dm-mod 2> /dev/null || :
vgscan --ignorelockingfailure --mknodes || :
vgchange -aly --ignorelockingfailure || return 2
clear
mkdir /LVM
cd /dev/mapper
## Create directories and mount
for FILE in *; do
test -b "$FILE" && mkdir /LVM/$FILE && mount /dev/mapper/$FILE /LVM/$FILE 2>/dev/null
done
## List good partitions
echo "Cleaning up LVMs that were swap partitions or with unsupported"
echo "File Systems from the list. This will not effect those partitions"
echo "There is just no need to list or parse them"
rmdir /LVM/Vol* 2>/dev/null"
echo " "
echo "The following LVM(s) were mounted for you and are ready to use"
echo " "
ls /LVM
echo " "
echo "You can find them in /LVM"

Sunday, March 1, 2009

Mounting LVM

Mounting an LVM may seem a bit intimidating, it's not. In reality, despite the length of this entry, you will only be running a handful of commands, and most of those just to get the needed information. Do not despair, this will be as painless as possible. All of these commands will be run as root from a terminal. Please also remember that your volume names may differ from the guide, please make sure to adjust accordingly.

# pvs

This should give you an output similar to

sabayonx86 sabayonuser # pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a- 7.88G 32.00M
If we look closely we can see that /dev/sda2 holds a lvm that is 7.88 gig in size. In this case, thats the one we want, as it is the only one.

So now we want to see what is actually in that lvm

# lvdisplay /dev/VolGroup00

sabayonx86 sabayonuser # lvdisplay /dev/VolGroup00

--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID SWp2V0-1xPU-0tOP-UnPs-snxF-THUl-pZMKb2
LV Write Access read/write
LV Status available
# open 0
LV Size 6.88 GB
Current LE 220
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 251:0

--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID MGBeJP-ohrX-KLju-5V78-iJOi-pP3w-huaOmC
LV Write Access read/write
LV Status available
# open 0
LV Size 992.00 MB
Current LE 31
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 251:1
We are looking for two things out of that list. LV name and LV Size. We have one that is 6.88 GB and one that is 992 MB. We can safely assume that the smaller of the two is /swap so the larger must be our real filesystem. That one is named /dev/VolGroup00/LogVol00.

So now we have all the information that we need. We need only to make a mount point and actually mount the volume.

# cd /mnt
# mkdir lvm
# vgscan --mknodes
# lvchange -ay /dev/VolGroup00/LogVol00
# mount /dev/VolGroup00/LogVol00 /mnt/lvm


If all went well then can now get inside and look around, make changes, chroot in, or whatever caused us to want to mount the LVM in the first place.

See that wasn't so hard now was it. ~Az

Thursday, October 16, 2008

Making a Bootable USB from DVD image

One of the big problems of making a bootable USB is file size. Almost all of the how-to's out there that allow to pass kernel commands during the boot process require the use of syslinux, which uses FAT16/FAT32 formated partitions. This comes with the drawback of limiting your maximum file size to 2 Gigabyte if using FAT32. A DVD release has it's main file, livecd.squashfs that can run up to nearly 4 Gigabyte, twice the maximum allowable size. In other words, Epic Fail. Here is a way around that.

This How-To will be covering use of a variation of a syslinux bootable USB drive, extlinux. As you might figure from it's name it allows you to use ext2/ext3 to format your partitions, thereby removing the 2 Gigabyte limit and allowing you to fit that monster livecd.squashfs onto your thumbdrive. For this example I will be using a 4 Gigabyte thumbdrive and Sabayon Linux 3.5 32 bit.

The first step to this is making sure you have syslinux installed. So depending on your distribution, apt-get install, emerge, urpmi -i, equo install ... etc etc etc, syslinux. This, if your distribution is any where near current, will also include extlinux.

You might as well go root and stay there. Yes, lots of this can be accomplished via GUI apps, and there are a plethora out there that you can use to accomplish a good chunk of these tasks. Command line though brings us to a common point that all your GUI apps are bolted on to anyway. That and because it's my preferance. From here on out I am going to assume that you are root (Ubuntu users this means 'sudo su -').

The next step to this is formatting the USB drive.
First identify your thumbdrive.

fdisk -l

If you read the output of this the first line of each device will tell you the size of the device, which makes it pretty easy to see which is a hard drive and which is not.

In my case /dev/sdb as shown below:

Disk /dev/sdb: 4016 MB, 4016045568 bytes
255 heads, 63 sectors/track, 488 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0004adbb

Make sure to substitute your device, /dev/sd(?)
fdisk /dev/sdb

Command (m for help): d
Selected partition 1

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-16065, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1015, default 1015):
Using default value <hit enter here for defualt>

Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 83

Command (m for help): a
Partition number (1-4): 1

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

mkfs.ext2 -j /dev/sdb1


Next is to install the syslinux boot sector, I know we said we were going to be using extlinux, but bear with it for a few. Thumbdrives don't come with a boot sector, so we have to make one and that's what we are doing here.

dd if=/usr/lib/syslinux/mbr.bin of=/dev/sdb


Please note that this is the location of the syslinux mbr.bin for Gentoo and Sabayon, your distribution may hide it somewhere else. The command 'find / -name mbr.bin' will pin it down for you, this command will scan your entire hard drive so it is kind of slow. Just substitute the absolute path to mbr.bin in the command above.

Now we need to make a few mount points and mount the ISO and the thumbdrive, remember to substitute your thumbdrive location for the one in the example.

mkdir /mnt/iso
mkdir /mnt/usb
mount /dev/sdb1 /mnt/usb
mount -o loop -t iso9660 /path/to/iso /mnt/iso

(as an example mount -o loop -t iso9660 /home/jim/Sabayon-Linux-x86-3.5.iso /mnt/iso)

Now we copy things over that we will need.

cp -rvp /mnt/iso/boot isolinux livecd livecd.squashfs README.txt /mnt/usb

This could take awhile with a DVD iso image. The livecd.squashfs is a monster. Go get a cup of coffee and check back in a few minutes. After it is finished copying we can continue on by running the following commands which set up the files for use by extlinux and make the needed changes to the boot sector.

cd /mnt/usb
mv isolinux extlinux

mv extlinux/isolinux.cfg extlinux/extlinux.conf
rm extlinux/isolinux.bin
cd /mnt
extlinux -i /mnt/usb/extlinux


Your done, wasn't that easy. The final piece to this is unmounting everything we mounted earlier.

umount /mnt/usb
umount /mnt/iso


Now you can reboot into the USB drive by selecting to boot from USB, the ways the various BIOS's handle this though are too numerous to list. Typically there will be an interupt option during the POST to select boot device. If not you'll probably have to go into the BIOS itself and find out where to select it.

Have Fun
~Az

Sunday, April 27, 2008

CD/DVD install with no CD/DVD

Want to install a DVD release of Linux but dont have a DVD drive or recorder? Your CD/DVD drive has died but you still want to install a new or updated version of Linux? You can, and you can do it all from your hard drive without burning a single CD or DVD.

To start we need to make a partition for the image to reside on. Two bits of advice, put the partition at the very end of the drive so you can recover the HD space later on if you wish. It's easy to add more room to the end of a partition but nearly impossible to add more room at the beginning of a partition. The second bit is, if you have no working CD/DVD drive at all you will need another way to resize your drives, for this I recommend going to http://www.pendrivelinux.com. They have a great list of thumb drive installs and how-to's, as well as their own version aptly called pendrivelinux which is great. You'll have to install gparted on it but still, very handy and a must have for your toolkit.

Okay, one way or another we now have a way to resize the drive, my personal preference is gparted. For the next step the size of the .iso we will be working with is needed. The one I will be using in this example is 3.9 Gig so I need 3.9 Gig plus a little bit for a fudge factor. A few hundred meg should be sufficient, however in my case I want to also back up some critical data so I bumped it to 5 Gig. You dont have to, but this is a great way to back up things you want to have readily available after you install. The minimum though is .iso size plus a bit, say 10% of .iso size.

You can use gparted to make this partition ext2 or you can issue the following command to do it. As root:

mkfs -t ext2 /dev/sda4

Where /dev/sda4 is the partition you just created, /dev/sda4 was mine. Make sure to change it to the one you actually made.

Next we need to get ready to start putting things together. All of the commands we will be using for this need to be issued as root so you might as well go there and stay there for awhile.

mkdir /mnt/iso
mkdir /mnt/target
mount -t ext2 /dev/sda4 /mnt/target

(note here, /dev/sda4 needs to changed to the one you made)

mount -o loop -t iso9660 /path/to/image /mnt/iso

(note here, for me this would be /home/jim/dls/Sabayon-Linux-x86-3.5-Loop2-r2.iso . Yours will differ, adjust accordingly)

cp -rvp /mnt/iso/* /mnt/target

Great almost done, but now your going to have to do a little thinking. We have to get what we just did to boot. Since the example I'm using probably wont be the one you will be using I will point out the changes you need to make. Regardless it's fairly straightforward.

We need to figure out the configuration we need to feed to GRUB to actually fire this up. Luckily 99% of this has already been done for us by whoever released the liveCD/DVD.

cd /mnt/target
ls -l


look around here for either isolinux.cfg or syslinux.cfg, if it is not in this directory

cd isolinux
ls -l


and look for it in this directory.

Once you have found it:

cat isolinux.cfg (syslinux.cfg if thats what you have)

You are going to get a lot of stuff here, we are actually only concerned with a little bit. The line LABEL is what we are looking for, the first one usually but read the LABEL to make sure its the one your looking for. In my case:

LABEL sabayon
menu label ^Start SabayonLinux 3.5 Loop2
kernel /boot/sabayon
append root=/dev/ram0 initrd=/boot/sabayon.igz aufs init=/linuxrc cdroot looptype=squashfs max_loop=64 loop=/livecd.squashfs splash=silent,theme:sabayon vga=791 CONSOLE=/dev/tty1 quiet music --

Is the one I want. When you see the next line that says LABEL, that is a seperate boot entry and you wont need it. Now we need to make a few changes to it, to make it bootable from GRUB.

title sabayon
root (hd0,3)
kernel /boot/sabayon root=/dev/ram0 aufs init=/linuxrc cdroot=/dev/sda4 looptype=squashfs max_loop=64 loop=/livecd.squashfs splash=silent,theme:sabayon vga=791 CONSOLE=/dev/tty1 music quiet --
initrd /boot/sabayon.igz

First you'll see I changed it from LABEL to title and removed the menu label line.

Second you'll see I added root(hd0,3). You'll need to adjust this to match where you extracted the .iso image. GRUB counts from 0 so drive 1 = 0 and partition 4 = 3. sda3 would be (hd0,2) sdb3 would be (hd1,2) and so on.

Third you will see that I left the kernel line alone.

Fourth you will see that I removed the word append and then moved the whole thing up so it follows the original kernel line. Then moved initrd=/boot/sabayon.igz to it's own line at the very bottom. Following that a bit further you will also find that where it says cdroot I added the actual partition where we extracted the .iso.

Note that while it looks complex, and the one you will be looking at will probably look significantly different your only actually making a small handful of changes. Just make the small edits as described leaving the rest alone and you'll be golden.

Okay, lets say you now have your entry figured out. Now you simply have to edit /boot/grub/grub.conf and add it to the very end of that file. This file has to be edited as root, and make sure you dont over write anything that is in there already.

Save the file, reboot, and you should see the entry for the LiveCD/DVD as an option in your boot menu.

Once your done you can safely remove the partition you made and reclaim the space using gparted again, or leave it in place and have an emergency boot, although you will have to add the lines back into GRUB if you overwrote your last one if/when you installed.

I wish I could take full credit for this, however I cant. I was working on making a USB variant of this, and was almost there but was having a few problems with it when jvj posted an almost line for line how to in the sabayon wiki. I want to thank him for pointing out that cdroot needed to be pointed to the partition, which is where I was stuck at. Since we both use Sabayon and Loop2 is the most current beta at the time of the writing that is why so much of his wiki entry and my how to look so similar.

Anyway, thanks jvj, and to the rest of you, happy computing.

~Az

*UPDATE* 07July08

I'm happy to say that Sabayon 3.5 has officially been released and that the above how-to has been tested against it and it worked perfectly. Here is the grub.conf entry I used to get it working on my laptop.

title Sabayon 3.5 Install/LiveDVD

root (hd0,3)
kernel /boot/sabayon root=/dev/ram0 aufs init=/linuxrc cdroot=/dev/sda4 looptype=squashfs max_loop=64 loop=/livecd.squashfs splash=silent,theme:sabayon vga=791 CONSOLE=/dev/tty1 quiet --
initrd /boot/sabayon.igz
Remember you will have to adjust root (hd0,3) and cdroot=/dev/sda4 to reflect your actual system as explained in the above article. Due to formatting issues of the blog I should point out that everything from kernel /boot/sabayon to quiet -- is actually one long line.

**UPDATE** 17Oct08
I finally did a write up for how to make a bootable USB from a DVD image. If you have a 4 Gig or larger thumbdrive handy give it a try.
Again, Happy Computing
~Az

Tuesday, July 24, 2007

Debian Etch: Custom Install

The following is a how-to that was on my original blog and also posted at www.debian-administration.org. It is the first I ever did, and as such has a few rough edges.

As a not completely new Linux user I have been frustrated over and over again at all the extra bloat and apps that I will never use that gets loaded onto my system when I do an install. Debian was the second distro that I tried and have used many others since, but I keep coming back.
With Etch I finally decided to get my system MY WAY(tm). No excess junk and no excess apps. After I had played for a little while I came up with the way to do it, and since I had found very little in the way of easily human understandable documentation I thought I would share the process.

Now understand that what we are going to do is start from where I changed the installation.

1: netinst CD and an internet connection.

2: start the normal install process and proceed all the way to where it asks if you want to use a network mirror.

3: select NO for network mirror (we will change this in a minute)

4: reboot and log in root

5: edit the sources.list

nano /etc/apt/sources.list


add these lines

deb http://ftp.debian.org/debian etch main contrib non-free
deb-src http://ftp.debian.org/debian etch main contrib non-free



Then make sure to comment out the line with the CD in it with a # otherwise it will drive you nuts asking for that blasted CD that has nothing of anymore use on it.

Close and save the file (double check your spelling and make sure you didnt fat finger any keys like I constantly do)

6: type in the command

apt-get update


7: type in

apt-get install xserver-xorg-core xorg


There will be a few questions at the end, for now just go with the defaults.

8: while apt is doing its thing we need to make a decision.
Which login manager do you want to use? Unless you want to run as root all the time ( #1 bad idea by the way) we need a login manager. Here are the 3 I have used and comments on them.

xdm:

smallest and works well to get you going on your way. Highly configurable.



gdm:

easily configurable and adds libraries you need if you want to use the synaptic package manager. (also contains alot of the extra functions of xdm)



kdm:

largest and bloated, I list it only because I know a few people who like it. (my opinion)



It honestly makes no differance to us which you pick. For ease of configuration I'd suggest gdm, if your just setting up a single user machine and will never change your desktop interface xdm might be the way to go. Your choice (thats what Linux is about right?)It doesnt matter which desktop environment you are going to use, any of them will fire up what ever you happen to have

So we

apt-get install xdm/gdm/kdm



9: Next decision, what desktop package to put in?

GNOME:

If you want Gnome you have just wasted time reading this, thats what you would have gotten if you had continued on with the installation normally.



KDE:

very much like the operating system that comes from redmond, and nearly as bloated with worthless junk. I have this installed only because my wife likes it.



Fluxbox:

This is the one I use. Very small, fast, and configurable. Its a low frills let our programs use system resources instead of having the desktop environment hog it approach. Nor will this one load your system up with oddbits like Gnome or KDE, however both are integrated with it. So if you install your favorite Gnome app or KDE app it automagicly appears in your menu in fluxbox.



There are others you can use as well, if you have one you like instead, use it.

So we

apt-get install fluxbox/gnome/kde



9A: If you went with fluxbox because like me you wanted to control what apps are on your system instead of letting someone else decide what is right for you. Remember this, fluxbox doesnt ship with proggies AT ALL. so at the very least you will want to add a web browser.

apt-get install firefox

(my choice, again use what you like)

10: reboot and poof you should be up and running.

For those who are wondering this worked equally well on my desktop as it did my laptop. I hope this helps someone else who like me is still learning all the wonderful things that can be done with Linux, but needs a few pointers because face it, we arent all programmers and everyone has to start the process of understanding somewhere.

Since originally writing this how-to I have changed my minimal install technique, however since at this point I have stopped using Debian or Debian derived distros completely I doubt that a new how-to will be forthcoming any time soon.

Sunday, July 1, 2007

QEMU/KVM,and a trick

Ever wanted to play with a new distro without having to burn and then reboot into a liveCD or do an install into a spare partition that you may or may not have? QEMU has been an option for awhile, but lets face it, its slow. There are several options available to run up a virtual machine, i.e. a second operating system running inside and seperate from your already running operating system. Here we will be focusing on kqemu and kvm.

If your kernel is already 2.6.20 or higher you can run kvm, if its under then you will be using kqemu.

kvm is in sid/unstable so you will have to add that to your apt sources.
go root
nano /etc/apt/sources.list

add
deb http://ftp.debian.org/debian unstable

then
apt-get update
aptitude install kvm

After kvm and associated packages are installed it would be best to edit your sources.list again and comment out the line where you added in unstable with a # at the beginning of the line.

kqemu, which is technically a qemu accelerator instead of kernel level virtualization like kvm is available in Debian stable and there for as easy to install as:

aptitude install kqemu


You should have noticed if it wasn't already installed that qemu was installed regardless of whether you went with kvm or kqemu. Thats because both packages use qemu. So no worries, we need the qemu tools anyway.

OK so now we need to set a few things up.

If you installed kqemu then we need to load that module when we boot. I use nano, you can use what ever other editor you want.

Go root, then

nano /etc/modules


and add at the bottom of whatever list might be there

kqemu


For kvm you need to know something beforehand, whether you have an Intel or an AMD processor. It makes a difference in the module we are going to load on boot.

Go root, then

nano /etc/modules


If you have an Intel processor you will add at the end of the list

kvm-intel


If you have an AMD processor you will add at the end of the list

kvm-amd


Now that we have the modules ready to load, we need to make them accessible to you as a user.

adduser $USER kvm
adduser $USER kqemu

depending on which you installed.

Congratulations, right now you should have everything just about ready to go. The problem is, even if you modprobe the modules active right now they still wont be usable to you, they need to be loaded against the kernel when you boot, so bookmark this page and reboot your computer, I'll wait here while you do.

OK so now we need to create a virtual drive to install our test distro to. I'll explain the parts of it after. From here on out everything is applicable to QEMU, Kqemu, and KVM. It is done as a normal user, so no more need to be root.

qemu-img create debian.img -f qcow 5G


The first bit is self explanatory, create an image (virtual drive) named debian.img. The next bit -f qcow tells it to format it in an inflatable structure. The 5G means a maximum physical size of 5 gig real hard drive space. The nice thing about this format is, if your VM installed only takes up 2.5 gig, then the virtual drive only takes up 2.5 gig of space on your real hard drive.

I guess the next thing that you'll be wanting to do is actually spin this up and try it out. I should note that I have had problems on occasion with KVM locking up during the install process, if this should happen to you drop back and use qemu with the same command line arguments. If you are using kqemu instead of kvm use qemu in the command line instead of kvm, kqemu is a module called by qemu when it starts. I'll be using kvm for the command line, you use what works for you.

I'm not ready yet to tell you how to start. A few things first if you don't mind. I usually make a seperate directory for my VM's because there are usually one or two files other than just the .img file. Such as an overlay file or two, which I will cover shortly and a script that simplifies launching the VM after its made. There are tons of command line arguments that can be added to the basic ones I am using here to get you started, the script is a huge time saver.

There are two basic ways to start this off, either with an .iso image or a CD/DVD. Lets start with an .iso image, the debian net-inst image in this case. We will assume for the sake of argument that the .iso is in the same folder as the virtual drive that you created is, and that it is also our working directory.

kvm -cdrom net-inst.iso -hda debian.img -m 512 -boot d


First this calls kvm and tells it that the .iso image is actually a cd drive, then the -hda debian.img is its hard drive. The -m 512 tells it that its a computer with 512 meg of memory. Careful here because this is the amount of physical memory that its going to block out for itself. Rule of thumb is no more than ½ of your actual physical memory. The final bit is -boot d, it tells it to boot from the cdrom drive.

kvm -cdrom /dev/cdrom -hda debian.img -m 512 -boot d


The only difference here is that your pointing it to your real cd drive here. If /dev/cdrom doesn't work for you then you can cat /etc/fstab and look there to see what you cdrom drive really is.

Now I mentioned that you might have problems doing an install using kvm, if this happens you have to explicitly tell qemu to not use the kvm module in the command line like this:

qemu -no-kvm -cdrom /dev/cdrom -hda debian.img -m 512 -boot d


Lets move on with the thought that you have installed your new virtual operating system. Your going to want to get in and play with it. The command for this is simply:

kvm -hda debian.img -m 512


With that you will be up and running in your new OS running inside your existing. However there is another trick that is really handy that will let you do whatever you want without permanently breaking this new creation, overlay files. Which basically takes a snapshot of your virtual drive and then run it from the overlay instead of the virtual drive. Really handy if you want to have several versions accessible but only have to do the install process once. Say like having a version of stable a version of testing and a version of unstable all available from the same install. To do this its as simple as:

qemu-img create -b debian.img -f qcow stable.ovl


To boot into this you just change the command line a little bit and tell it to use the overlay file you just made.

kvm -hda stable.ovl -m 512


As you can see the easy way to run multiple versions off the same install would be to do a base install of stable and then make your overlay file for it. Next you would make an overlay file named something like testing.ovl and another for unstable.ovl all from the debian.img that we made to start.

Then simply fire each up in turn via the overlay files, edit your /etc/sources.list to what ever you want and update yourself into debian nirvana.

My thanks to Scott Ruecker over at lxer.com for asking the question that started the process for this how-to. As I said though there are tons of switches that will add functionality to your virtual machine. More than I can adequately explain as I haven't managed to figure them all out yet either. This how to was written with the whole intent to get someone armed and dangerous before kicking them out the door and isn't intended to be all inclusive.

For more information on this topic you can start at qemu's authors site at:
http://fabrice.bellard.free.fr/qemu/qemu-doc.html

Have fun.
~Az