This post is about creating a simple file system and load with QEMU(X86).
Requirements
- QEMU
- Kernel BzImage
- Busy box
Step 1: For Installing QEMU on ubuntu machine
sudo apt-get install qemu-system Step 2: Download kernel from kernel.org and compile the kernel for bzImage
Step 3: Download the busybox from http://git.busybox.net/busybox/?h=1_22_stable
/* Create a folder for holding folders*/ $ mkdir myfilesys /* Go to busybox folder and compile*/ $ make menuconfig <-- In this step select "Statically linked busybox" $ make $ make install CONFIG_PREFIX=path/to/myfilesys /* Create the standard directories */ $ mkdir dev etc etc/init.d bin proc mnt tmp var var/shm $ chmod 755 . dev etc etc/init.d bin proc mnt tmp var var/shm /* dev folder settings */ $ mknod tty c 5 0 $ mknod console c 5 1 $ chmod 666 tty console $ mknod tty0 c 4 0 $ chmod 666 tty0 $ mknod ram0 b 1 0 $ chmod 600 ram0 $ mknod null c 1 3 $ chmod 666 null /* etc folder settings */ $ cd myfilesys/etc/ $ vi init.d/rcS <-- Create a file name "rcS" and add the following command #! /bin/sh mount -a # Mount the default file systems mentioned in /etc/fstab. $ chmod 744 init.d/rcS $ vi fstab <-- Create fstab file and copy the following content proc /proc proc defaults 0 0 none /var/shm shm defaults 0 0 $ chmod 644 fstab $ vi inittab <-- Create inittab file ::sysinit:/etc/init.d/rcS ::askfirst:/bin/sh $ chmod 644 inittab /* Create an ext2 filesystem image by running these commands */ $ dd if=/dev/zero of=my.img bs=1M count=2 $ mkfs.ext2 -N 512 my.img /* mount the filesystem and copy the folders which created early (myfilesys contents)*/ $ mount -t ext2 my.img /mnt $ cp -fr myfilesys/* /mnt $ umount /mnt Step 4: Now we have bzImage, file system and installed QEMU. Issue the following command for loading our images.
$ qemu-system-i386 -kernel bzImage -hda my.img -append=/dev/sda Now QEMU loads newly build kernel and file system. Hurrayyyyyyy !!! We made it. If you want to explore further , try creating new directories, do some extra stuff :)
References
Hey,Jey.Thanks for your post!This article just helped me a lot.But i think the BusyBox should be static builed,or the Linux kernel can't mount the img file rightly.
ReplyDelete