Advertisement
metalx1000

Create a Mini Debian Virtual Machine IMG Qemu

Mar 7th, 2015
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.60 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ ! -f "/usr/bin/qemu-system-i386" ]
  4. then
  5.   sudo apt-get install qemu-system
  6. fi
  7.  
  8. boot_img="http://archive.debian.org/debian/dists/etch/main/installer-i386/current/images/floppy/boot.img"
  9. root_img="http://archive.debian.org/debian/dists/etch/main/installer-i386/current/images/floppy/root.img"
  10.  
  11. #make clean
  12. rm -fr root.img boot.img tmp
  13.  
  14. echo "Getting Mini Debian Boot IMG File..."
  15. wget -c "$boot_img"
  16. echo "Pulling Kernel from IMG File..."
  17. mkdir tmp
  18. sudo mount boot.img tmp
  19. cp tmp/linux ./
  20. sudo umount tmp
  21.  
  22. echo "Getting Mini Debian RootFS IMG File..."
  23. wget -c "$root_img"
  24.  
  25. echo "Mounting Root Image and Retrieving initrd..."
  26. sudo mount root.img tmp
  27. cp tmp/initrd.gz ./
  28. sudo umount tmp
  29.  
  30. #cleanup
  31. rm -fr root.img boot.img tmp
  32.  
  33. mkdir rootfs
  34. cd rootfs
  35. zcat ../initrd.gz |cpio -i -H newc -d
  36.  
  37. echo "Setting default shell for boot time..."
  38. cat << EOF > etc/inittab
  39. # /etc/inittab
  40. # busybox init configuration for debian-installer
  41. # main rc script
  42. ::sysinit:/bin/busybox sh
  43. # main setup program
  44. ::respawn:/sbin/poweroff
  45. #
  46. # # convenience shells
  47. vc/2::askfirst:-/bin/sh
  48. vc/3::askfirst:-/bin/sh
  49. #
  50. # logging
  51. vc/4::respawn:/usr/bin/tail -f /var/log/syslog
  52. #
  53. # # Stuff to do before rebooting
  54. ::ctrlaltdel:/sbin/shutdown > /dev/null 2>&1
  55. #
  56. # re-exec init on receipt of SIGHUP/SIGUSR1
  57. ::restart:/sbin/init
  58. EOF
  59.  
  60. echo "Recompressing initrd IMG..."
  61. find | cpio -o -H newc | gzip -2 > ../initrd.gz
  62.  
  63. cd ../
  64. echo "Starting Qemu virtual machine..."
  65. qemu-system-i386 -kernel linux\
  66.   -initrd initrd.gz\
  67.   -append 'root=/dev/ram0 console=ttyS0 console=ttyS0 rw'\
  68.   -nographic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement