Log in

No account? Create an account
The Conversation Pit [entries|archive|friends|userinfo]
Rob Landley

[ website | My Website ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

kvm and the art of unicyle maintenance. [Dec. 16th, 2010|10:10 pm]
Rob Landley
[mood |contemplativecontemplative]

So, if you need a debian chroot for some reason, here's whatcha do. (As root, assuming you install all these commands.)

debootstrap lenny ~/lenny
chroot lenny
passwd # set the root password

Now make an ext2 image out of it.

genext2fs -z -d ~/lenny -i 1024 \
-b $((1024*(($(du -m -s ~/lenny | awk '{print $1}')*12)/10))) lenny.ext2
resize2fs lenny.ext2 2048M
tune2fs -c 0 -i 0 -j lenny.ext2

(I have no idea why genext2fs won't calculate the number of blocks it needs, that -b blob calculates is the amount of space it's using plus 20% for various administrative overhead like inode tables and such. It then fluffs it up to 2 gigabytes as a separate step; you could just tell genext2fs to make a big image but for some reason its behavior is nonlinear so that takes over 10 minutes to do that while the two steps separately are a few seconds each. Oh, and genext2fs creates an 11 megabyte _empty_ lost+found directory, you might want to delete that.)

Now you can chown lenny.ext2 back to a non-root user and switch over to there, build a kernel, and boot it up under kvm:

kvm -m 1024 -kernel arch/x86/boot/bzImage -no-reboot -hda ~/lenny.ext2 \
-append "root=/dev/hda rw panic=1" -net nic,model=e1000 -net user

When it boots up, you'll need a bit more configuration (starting with "dhclient eth0", maybe "aptitude update", and lots of aptitude install packages), but that's another post.