It’s a bit inconvenient to create an image of the root file system and compress it over and over again every time you make a change inside it. The remedy is mounting the root file system through NFS (Network File System) by the help of which you can see any change you make in the root file system take effect at that very moment. Your root file system can be found on any other machine on the network including your host machine. I’m going to continue from the previous example in which we connected our QEMU guest to a real network. It’s not mandatory to connect your guest OS running on QEMU to the network. You can place the root file system on your host and still make use of NFS.
Let’s begin by installing nfs kernel server which is prerequisite in using network file system. Hence our host machine can host the root file system which the guest will mount using NFS.
$ sudo apt-get install nfs-kernel-server
Create the directory for our root file system.
$ sudo mkdir -p /srv/nfs
Change its privileges for a normal user. Check your user id by typing the following commad.
uid=1000(egenc) gid=1000(egenc) groups=1000(egenc),4(adm),20(dialout),24(cdrom),46(plugdev),111(lpadmin),119(admin),121(nopasswdlogin),122(sambashare)
My user id and group id values are both 1000. Probably same as yours.
Open the exports file.
$ sudo gedit /etc/exports
Add the following line. (There should no space between the words in parantheses)
And export it.
$ sudo exportfs -av
In order to check the functionality of NFS try to mount the folder we created to a custom point.
$ mkdir /home/egenc/check_nfs
Change the owner as normal user
$ sudo chown -R egenc /srv/nfs $ sudo service nfs-kernel-server restart $ sudo mount 127.0.0.1:/srv/nfs /home/egenc/check_nfs
Verify whether it mounted with success
$ sudo mount
If it worked you can unmount it
$ sudo umount /home/egenc/check_nfs $ rmdir /home/egenc/check_nfs
Now copy your root file system (_install directory under busybox folder) to /srv/nfs
Create a file named “inittab” under /srv/nfs/_install
$ cd /srv/nfs/_install/etc $ sudo gedit inittab
Copy the following content:
::sysinit:/etc/init.d/rcS ::respawn:/sbin/getty -n -l /bin/sh -L 115200 tty1 vt100 ::restart:/sbin/init
Save and close the file. Note that we are NOT making it an executable file.
Now we are going to modify our rcS file so that our guest will be automatically assigned an IP over DHCP. It’s not neccessary though. You can enter the IP and routing table values manually later on when the guest OS boots.
Let’s take the laborious way which will save us time later.
$ gedit /srv/nfs/_install/etc/init.d/rcS
Edit the content as follows.
#!/bin/sh mount -t proc none /proc mount -t sysfs none /sys mount -t ramfs ramfs /dev /sbin/mdev -s echo " emreboy: assign localhost." ifconfig lo 127.0.0.1 up route add -net 127.0.0.0 netmask 255.255.0.0 gw 127.0.0.1 lo echo " emreboy: Getting IP via DHCP, wait…" #ifconfig eth 0 0.0.0.0 up | logger -t rcS udhcpc -n -q -R -s /etc/udhcpc.script | logger -t rcS
As you might have noticed I commented out the line “ifconfig eth0 0.0.0.0 up | logger -t rcS”
Let me explain why. We are going to start QEMU by assigning a temporary IP address which is available on the network. Hence the kernel will be able to mount the root file system. Then by the help of “udhcpc” utility we will get an IP and routing table information from the server. If we assign the IP 0.0.0.0 after the root file system is mounted the system will be stuck. Its connection with the root file system which is working on NFS will be broken.
Notice that I modified the file according to my previous examples. If you have a different rcS file try to add the lines above without corrupting the integrity of yours.
Make sure that your network configuration is right.
$ sudo /etc/qemu-ifup tap0
Now run QEMU with a temporay IP address.
$ sudo qemu-system-arm -M versatilepb -m 128M -kernel zImage -append "root=/dev/nfs nfsroot=188.8.131.52:/srv/nfs/_install rw ip=184.108.40.206 rdinit=/sbin/init" -net nic -net tap,ifname=tap0,script=no,downscript=no
When you’re done with it you can restore your original network configuration
$ sudo /etc/qemu-ifdown tap0