cd / opt / debootstrap --variant=minbase --include=dhcp-client,ssh,vim,make,psmisc,mini-httpd,net-tools,iproute,iputils-ping,procps,telnet,iptables,wget,tcpdump,curl,gdb,binutils,gcc,libc6-dev,lsof,strace --exclude=locales,aptitude,gnupg,cron,udev,tasksel,rsyslog,groff-base,manpages,gpgv,man-db,apt,debian-archive-keyring,sysv-rc,sysvinit,insserv,python2.6 --arch i386 etch etch 'http://archive.debian.org/debian'
Get
/opt/etch
as the file of the required operating system. Note that the package selected here contains basic network commands such as ip, dhclient, etc.
Download the tools for generating mirrors
mainly use https://github.com/killinux/jslinux_reversed/blob/master /contrib/createimage.sh
cd / var / www / html / git clone https://github.com/killinux/jslinux_reversed mv /opt/etch /var/www/html/jslinux_reversed/contrib/squeeze ./createimage.sh
Generate hda.img
file By default when linux starts, /sbin/init is called first,
so check the correctness of the init file
mkdir hda
mount -o loop hda.img hda
vim hda/sbin/init
#!/bin/sh show_boot_time 2>/dev/null echo "JSLinux started, initializing..." export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin export HOME=/root export TERM=vt100 mount -n -t proc /proc /proc mount -n -t sysfs /sys /sys mount -n -t devpts devpts /dev/pts mount -n -t tmpfs /tmp /tmp mkdir -p "/tmp/root" ip link set up dev lo main() { echo >/dev/clipboard while :; do setsid sh -c "exec bash 0<>/dev/ttyS0 1>&0 2>&0" done } #. /dev/clipboard main "$@"
Comment out #. /dev/clipboard
Note that if the startup fails, you may need to add
/sbin/mdev -s
to initialize the files under /dev. The key point
here is to mount the three file systems of /proc /sys and /dev
Yes With the bzImage kernel and hda.img image
, you can create a virtual machine
qemu-system-i386 -kernel bzImage -drive file=hda.img,if=ide,cache=none -append "console=ttyS0 root=/dev/sda rw rdinit=/sbin/init notsc=1" -nographic
or
qemu-system-i386 -kernel bzImage -hda hda.img -append "console=ttyS0 root=/dev/sda rw rdinit=/sbin/init notsc=1" -nographic
-hda or -drive mode
cache parameter can use
writethrough write-through mode: write data to disk cache while mobilizing write to write data
writeback writeback mode: write data to disk cache and return
none to close cache
btw , if you don't want to destroy the original hda.img and
use incremental build vm ,
you can specify hda.img as backing_file
qemu-img create -f qcow2 -o backing_file=hda.img hda_hasbacking_file.qcow2
That is, hda.img is used as the basic template, and
the new hda_hasbacking_file.qcow2 saves the incremental part
of hda.img. The vm created by hda_hasbacking_file.qcow2 will not cause damage to the original image
qemu-system-i386 -kernel bzImage -drive file=hda_hasbacking_file.qcow2,if=ide,cache=none -append "console=ttyS0 root=/dev/sda rw rdinit=/sbin/init notsc=1" -nographic
If you add -boot order=dc, menu=on
can control the boot order, and whether to display the boot menu
d is the optical drive, c is the first hard disk
If you add a network, use the -net parameter
qemu-system-i386 -kernel bzImage -drive file=hda_hasbacking_file.qcow2,if=ide,cache=none -append "console=ttyS0 root=/dev/sda rw rdinit=/sbin/init notsc=1" -nographic -boot order=dc,menu=on -net nic,vlan=0,macaddr=52:54:00:12:34:22,model=e1000,addr=08 -net tap,ifname=tap1,script=no,downscript=no
-net nic is a necessary parameter to indicate that this is a network card configuration
vlan indicates the blan number, the default 0
macaddr is the mac address, after entering the virtual machine
ctrl+ac switch to monitor mode
info network to view the network card
root@(none):/# QEMU 2.5.1 monitor - type 'help' for more information (qemu) info network hub 0 \ hub0port1: tap.0: index=0,type=tap,ifname=tap1,script=no,downscript=no \ hub0port0: e1000.0: index=0,type=nic,model=e1000,macaddr=52:54:00:12:34:22 (qemu)
You can see that the mac address
52:54:00:12:34:22
is the model specified when we created the vm
as the network card type. You can check qemu to see what the types of network cards are.
qemu-system-i386 -net nic,model=? qemu: Supported NIC models: ne2k_pci,i82551,i82557b,i82559er,rtl8139,e1000,pcnet,virtio
For more network-related information, you can refer to Create a virtual machine with qemu by
bridging : http://haoningabc.iteye.com/blog/2306736 Create a virtual machine
with qemu by NAT :
http://haoningabc.iteye.com/blog /2306952