Advertisement
metalx1000

Create Mini Linux System for Qemu Kernel Initrd

Jun 24th, 2015 (edited)
1,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.72 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. start=$PWD
  4. initramfs=${start}/initramfs
  5. ARCH="x86_64"
  6. ARCH2="x86"
  7. linux="linux-6.0"
  8. lv="$(echo $linux|cut -d\- -f2|cut -d\. -f1)"
  9.  
  10. mkdir $initramfs
  11. cd $initramfs
  12. mkdir -pv bin lib dev etc mnt/root proc root sbin sys
  13. mknod -m 666 dev/null c 1 3
  14. mknod -m 666 dev/tty c 5 0
  15. mknod -m 666 dev/zero c 1 5
  16. mknod -m 666 dev/random c 1 8
  17.  
  18. echo "nameserver 8.8.8.8" > etc/resolv.conf
  19. echo "search 8.8.8.8" >> etc/resolv.conf
  20.  
  21. #Create INIT startup script
  22. cat << EOS > init
  23. #!/bin/sh
  24.  
  25. mknod -m 666 dev/null c 1 3
  26. mknod -m 666 dev/tty c 5 0
  27. mknod -m 666 dev/zero c 1 5
  28. mknod -m 666 dev/random c 1 8
  29.  
  30. /bin/mount -t proc none /proc
  31. /bin/mount -t sysfs sysfs /sys
  32.  
  33. cat <<'EOF'
  34.  __  __ _       _   _     _                  
  35. |  \/  (_)_ __ (_) | |   (_)_ __  _   ___  __
  36. | |\/| | | '_ \| | | |   | | '_ \| | | \ \/ /
  37. | |  | | | | | | | | |___| | | | | |_| |>  <
  38. |_|  |_|_|_| |_|_| |_____|_|_| |_|\__,_/_/\_\
  39.  
  40. EOF
  41. echo 'Enjoy your new mini system!'
  42.  
  43. /bin/sh
  44. EOS
  45.  
  46. chmod 755 init
  47.  
  48.  
  49. cd bin
  50. wget -c "https://busybox.net/downloads/binaries/1.35.0-x86_64-linux-musl/busybox" -O busybox
  51. chmod +x busybox
  52.  
  53. ./busybox  --help | \
  54. sed -e '1,/^Currently defined functions:/d' \
  55.     -e 's/[ \t]//g' -e 's/,$//' -e 's/,/\n/g' | \
  56. while read app ; do
  57.   if [ "$app" != "" ]; then
  58.     echo "linking ${app}..."
  59.     ln -sf "./busybox" "$app"
  60.     ls -ld "$app"
  61.   fi
  62. done
  63.  
  64. cd $initramfs
  65. find . -print0 | cpio --null -ov --format=newc > ../initrd.cpio
  66.  
  67. cd $start
  68. wget -c "https://www.kernel.org/pub/linux/kernel/v${lv}.x/${linux}.tar.xz"
  69. tar xf ${linux}.tar.xz
  70. cd ${linux}
  71. make allnoconfig
  72. #make menuconfig
  73. make
  74.  
  75. cp arch/$ARCH2/boot/bzImage $start
  76. cd $start
  77. qemu-system-$ARCH -kernel bzImage -initrd initrd.cpio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement