febootstrap is a tool to create Fedora bootable systems. This is similar to the more popular debootstrap utility on Debian based systems. Most people use it to create a chroot-able environment to test something out. Another common use is to create a minimalistic Fedora system that you can boot through qemu/KVM. Here is how I went about setting such a system up for myself. Of course, this may not be the only way (or the best, for that matter) of doing it.
Preparation:
- If febootstrap is not installed, install it:
yum install febootstrap
- Ensure you have internet connection or access to a local Fedora repository.
- Ensure you have at least 1GB of free disk space.
Steps:
1) Create a disk image: First, create a normal file on the disk by reading from /dev/zero. It's size is what the size of your guest is going to be. 1GB is plenty if you are doing a minimal install.
dd if=/dev/zero of=fedora-12-image bs=1G count=1
2) Create file system: Create a file system in that file:
mkfs.ext3 ./fedora-12-image
3) Loop mount: Loop mount the created file system:
mount -o loop ./fedora-12-image ./mnt
4) Install using febootstrap: Use febootstrap to populate the mount point with Fedora packages. By default febootstrap installs packages in the "Core" group of Fedora.
febootstrap fedora-12 ./mnt
If you have a local mirror of Fedora please provide that as the last argument. In the absense of that it pulls packages from public Fedora repos. This step installed 160 packages and took just a few minutes to complete for me.
Now you already have a chroot-able Fedora environment that you can use.
chroot /mnt
5) Install additional packages: As I mentioned above, febootstrap has only installed packages in the "Core" group. Hence some of the packages you need might not have been installed. You can install them now by doing this:
First, bind mount a few directories from the base system into this environment. This is essential to let yum succeed.
cd /mnt
sudo mount --bind /dev ./dev
sudo mount -t proc nodev ./proc
sudo mount --bind /etc ./etc
Now install the packages you need. Here, I installed "strace". febootstrap-run just runs the specified command in the chroot-ed environment.
febootstrap-run /mnt yum install strace
Now unmount the mounts:
umount /mnt/dev /mnt/etc /mnt/proc
6) Fix up: Copy /etc/fstab and /etc/resolv.conf from the base system. These wouldn't have been done by febootstrap.
cp /etc/fstab /mnt/etc
cp /etc/resolv.conf /mnt/etc
Edit the fstab in the installed system to fix things up. Specifically, edit the mount point of / and don't mount any other real disk partitions. My fstab looks like this:
/dev/vda specifies that I will be using virtio for disk IO. It could be /dev/sda or /dev/hda depending on your KVM setup.
7) Set root password for the installed system:
chroot /mnt
passwd
Now create another login, if you wish, using useradd
8) Unmount the loop mount.
umount /mnt
Now the system is ready to be booted through KVM. However, it does not have a kernel, initrd or grub. You will have to specify the kernel and initrd to use while starting the virtual machine. Here is what I use:
qemu-system-x86_64 -name f12-kvm -drive file=./fedora-12-image,if=virtio -m 512 -kernel /arch/x86/boot/bzImage -append "root=/dev/vda noapic selinux=0"
Notice the -kernel parameter being passed to specify the kernel to use. If you need to pass an initrd, use -initrd option. Additional options will be needed to configure network, etc.
Advantages of this approach:
- Speed of booting. The system boots up in just a few seconds. (4-5 seconds for me).
- Ease of changing the guest kernel. Just compile the kernel on the host, restart KVM pointing it to the new kernel. Hence this is excellent for testing your kernel modifications. You could also just point the guest to the kernel installed on the host.
- Very small size of the guest. The base Fedora-12 system is less than 500MB in size. You can have one such image as your 'base' image, create additional images with various packages to use in different environments.
Nice post. Doing this with openSUSE is cooler. http://susestudio.com/ rocks.
ReplyDeleteDon't forget that in addition to KVM, the Linux kernel also includes Linux Native Containers (LXC) which is similar to a chroot environment but with greater isolation. I primarily use OpenVZ for containers but LXC is coming along nicely.
ReplyDeleteI'd like to see your recipe modified to creating a Linux LXC container.
reallu enjoyed your blog very interesting,
ReplyDeletehttp://wallpapers302.blogspot.com/en
ReplyDelete