Advertisement
metalx1000

Create Minimal Linux system for Virtual Machine

Mar 21st, 2023 (edited)
1,209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.78 KB | None | 0 0
  1. mkdir -p os/rootfs
  2. cd os/rootfs
  3.  
  4. #create base file system
  5. mkdir dev proc sys tmp bin
  6. sudo mknod dev/console c 5 1
  7.  
  8. #copy buysbox and link all applications
  9. cp /usr/bin/busybox bin
  10. ./bin/busybox busybox --install ./bin/
  11.  
  12. #create init script
  13. echo '#!/bin/sh
  14. mount -t proc proc /proc
  15. mount -t sysfs sysfs /sys
  16. mount -t devtmpfs udev /dev
  17.  
  18. /bin/sh
  19. poweroff -f' > init
  20. chmod +x init
  21.  
  22. #create initrd
  23. find . | cpio -H newc -o | gzip > ../rootfs.cpio.gz
  24.  
  25. cd ../
  26.  
  27. #copy kernel from current system
  28. cp "$(ls /boot/vmlinuz-*|tail -n1)" linux
  29.  
  30. #run virtual machine
  31. qemu-system-x86_64 -enable-kvm -kernel linux -initrd rootfs.cpio.gz
  32. #or run it without GUI in current shell
  33. qemu-system-x86_64 -enable-kvm -kernel linux -initrd rootfs.cpio.gz -nographic -append 'console=ttyS0'
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement