How to Partition Hard Drive with QEMU

by Mike Levin SEO & Datamaster, 07/22/2010

After all that to start the Ubuntu Server install, I’m going to backtrack for this post and talk about using a more friendly LiveCD, namely Knoppix. If you make a copy of your QEMU directory so far, you can freely go through a complete Ubuntu Server install, knowing that you have the ultimate “undo” of just going back to your backup files. This is one of the beautiful things about virtual machines–it’s a great opportunity to experiment.

But I’ve been this route a number of times. There’s nothing inherenly wrong with it, and it’s an experience you should have in the spirit of building up your knowledge. But for the sake of the Shankserver.org, it’s more important to start introducing you to the concept of building up an extremely minimal server install.

So why Knoppix, and not must selecting the “minimal install” option of Ubuntu Server? The answer is that we’re going to be using a tool called debootstrap to build our minimal Debian Linux system. This gives us a lot more control and understanding of the system. It’s almost (but not quite) like mixing our own distribution of Linux. To do so, we will need to work on our virtual hard drive without having booted from it, and a LiveCD is the way to do that. And Knoppix is a popular Debian-based LiveCD.

So simply Google on Knoppix and download the iso file. Rename it for easy typing and put into that same QEMU directory, and type off the command to start booting from the iso f ile:

qemu -hda harddrive.raw -cdrom knoppix.iso

You will be presented with a menu. You want to select the number for the Shell. Once you get a shell prompt, you want to make sure that you have root privileges. Do this by typ ing:

sudo su

You will know this worked, because your prompt will now end in a hash-mark (the number sign). That’s the way in Linux to quickly know whether you’re “root”. Once you’re root, t ype:

fdisk /dev/sda

This will trigger off the process we’ll be using to format your virtual hard drive. We only asked for a 500MB virtual hard drive, which is not a lot of room to work with, but it keeps us efficient. The series of commands you want to type off to make your primary partition are:

p (simply to view your partition table) n (make a new partition) p (make a primary partition) 1 (set the partition number you’re working on) [Enter] (Start from the first cylinder) +396MB (Use ~400MB for primary partition) n (new partition) p (primary partition) 2 (partition number 2) [Enter] (From block 50) [Enter] (to block 63) p (view the parition tables again) a (toggle bootable) 1 (make partiion 1 bootable) t (change partition’s system ID) 2 (choose partion 2) 82 (set it to Linux swap) p (view partition table again to confirm changes) w (write changes and exit fdisk)

After you’ve done all this, you are have formatted your hard drives in preparation for a minimal Linux install, with both a primary boot partition and a swap partition. It should look something like this:

At this point, there is actually some value to the harddrive.raw file, and it might be worth quitting out of Linux, and backing up the file. And now for one of your first bits of Linux indoctrination–how to shut down! You’re already logged in as root, so the hardest part is done. Now, simply type:

shutdown -h now

This stands for a “hard” shutdown (as opposed to a reboot) with no T-minus type countdown.