相撲外:Running Universal Debian GNU/Linux in an emulator on a PC

Other GNU/Linux on the Universal tips

This is useful for instance when you cannot use the Universal temporarily and want to update, or install software, etc. I've used it when my Universal was in service, to update the software.

All of the steps below, refer to actions you will take on a Debian GNU/Linux PC, not on the Universal.

  1. Install QEMU
    # aptitude install qemu
  2. Get an armel kernel, initrd, and root filesystem from the QEMU armel page, originally found here.
    $ wget -c http://sumoudou.org/uni/vmlinuz-2.6.24-1-versatile
    $ wget -c http://sumoudou.org/uni/initrd.img-2.6.24-1-versatile
    $ wget -c http://sumoudou.org/uni/debian_lenny_armel_small.qcow.gz
  3. Gunzip the root filesystem.
    $ gunzip debian_lenny_armel_small.qcow.gz
  4. Create a QEMU img file to contain the Universal root filesystem for PC manipulation.
    $ qemu-img create uni.img 6GB
    The 6GB refers to the image size, make it big enough, so that the whole Universal root filesystem fits inside it.
  5. Create the emulator armel.sh launch file.
    $ echo 'qemu-system-arm -M versatilepb -hdb uni.img -kernel vmlinuz-2.6.24-1-versatile -initrd initrd.img-2.6.24-1-versatile -hda debian_lenny_armel_small.qcow -append "root=/dev/sda1" -m 256 -localtime' > armel.sh
  6. Make the emulator launch file executable.
    $ chmod 755 armel.sh
  7. Run the emulator for the first time to create a filesystem on the img file.
    $ ./armel.sh
    When the emulator boots, you can login as user with password user or as root with password root. Login as root.
  8. Elementary networking now works, you can access the web, however ping doesn't work.
    Install dbus. Otherwise you will get the Can not write log, openpty() failed (/dev/pts not mounted?) error later on in chroot, when installing with apt-get or aptitude.
    # aptitude update
    # aptitude install dbus
  9. Create one partition to span the whole img file mounted as /dev/sdb
    # cfdisk /dev/sdb
  10. Create an ext2 filesystem on the partition.
    # mkfs.ext2 /dev/sdb1
  11. Shutdown the QEMU emulated system.
    # halt
  12. Back in the PC Debian GNU/Linux system, you need to figure out how to mount the img file so that you can write to it.
    # fdisk -ul uni.img
    You will get output similar to the following text:
    You must set cylinders.
    You can do this from the extra functions menu.

    Disk uni.img: 0 MB, 0 bytes
    133 heads, 62 sectors/track, 0 cylinders, total 0 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Disk identifier: 0x00000000


    Device Boot Start End Blocks Id System
    uni.img1 62 8386181 4193060 83 Linux

    To figure out the offset, necessary to specify in the mount command to mount the img file multiply the start sector, in the above case 62, with the number of bytes in a sector, in the above case 512. Therefore in this example, the loop offset would be 31744.
  13. Utilizing the offset number, figured out in the above step, mount the uni.img file on the PC.
    # mount -o loop,offset=31744 uni.img /mnt
  14. Now the image file is mounted as /mnt/
    Copy the Universal root filesystem you wish to work on to /mnt/
  15. When finished copying, copy /etc/resolv.conf file in the mounted /mnt/ system to /etc/resolv.conf.uni
    # cp -P /mnt/etc/resolv.conf /mnt/etc/resolv.conf.uni
  16. Unmount the mounted img file.
    # umount /mnt
  17. Start the QEMU emulator again.
    $ ./armel.sh
    Login as root.
  18. In the armel emulated system create a Universal chroot launch file.
    # echo "mount /dev/sdb1 /mnt" > /usr/local/bin/uni
    # echo "mv /mnt/etc/resolv.conf /mnt/etc/resolv.conf.uni" >> /usr/local/bin/uni
    # echo "cp /etc/resolv.conf /mnt/etc/" >> /usr/local/bin/uni
    # echo "mount -o bind /dev /mnt/dev" >> /usr/local/bin/uni
    # echo "mount -o bind /dev/pts /mnt/dev/pts" >> /usr/local/bin/uni
    # echo "mount -o bind /proc /mnt/proc" >> /usr/local/bin/uni
    # echo "mount -o bind /dev/shm /mnt/dev/shm" >> /usr/local/bin/uni
    # echo "mount -t tmpfs none /mnt/tmp" >> /usr/local/bin/uni
    # echo "mount -t tmpfs none /mnt/var/run" >> /usr/local/bin/uni
    # echo "mount -t tmpfs none /mnt/var/lock" >> /usr/local/bin/uni
    # echo "mount -t tmpfs none /mnt/var/tmp" >> /usr/local/bin/uni
    # echo "chroot /mnt/" >> /usr/local/bin/uni
    # echo "rm /mnt/etc/resolv.conf" >> /usr/local/bin/uni
    # echo "mv /mnt/etc/resolv.conf.uni /mnt/etc/resolv.conf" >> /usr/local/bin/uni
    # echo "umount /mnt/var/tmp" >> /usr/local/bin/uni
    # echo "umount /mnt/var/lock" >> /usr/local/bin/uni
    # echo "umount /mnt/var/run" >> /usr/local/bin/uni
    # echo "umount /mnt/tmp" >> /usr/local/bin/uni
    # echo "umount /mnt/dev/shm" >> /usr/local/bin/uni
    # echo "umount /mnt/proc" >> /usr/local/bin/uni
    # echo "umount /mnt/dev/pts" >> /usr/local/bin/uni
    # echo "umount /mnt/dev" >> /usr/local/bin/uni
    # echo "umount /mnt" >> /usr/local/bin/uni
  19. Make the chroot launch file executable.
    # chmod 755 /usr/local/bin/uni
  20. Now you can launch the Universal chroot, which will put you in the Universal environment.
    # uni
    Here you can install software, run aptitude update and aptitude full-upgrade, etc. Elementary networking will work, allowing you to access the internet. ping will not work, as it needs root privileges on the host system side, but apt-get and aptitude will work.
  21. When finished, exit the chroot.
    # exit
    This will have unmounted the Universal image file and brought you back to the QEMU armel emulated environment.
  22. Exit the QEMU armel emulated environment.
    # halt
    After the QEMU armel emulated environment is halted you can close the QEMU window.
  23. Now you can mount the uni.img file in the same way as described above and copy the root filesystem off of it to the SD card you use in the Universal.

© sumoudou.org 2008