User Tools

Site Tools


qemunet:debian

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
qemunet:debian [2016/09/09 14:46] – [Some Advanced Tips for QemuNet] orelqemunet:debian [2016/09/14 08:01] (current) – removed orel
Line 1: Line 1:
-====== How to install a Debian Linux System for QemuNet? ====== 
- 
-QemuNet uses standard QEMU disk file in raw format. So you can follow any tutorial available for QEMU. Here is a simple example on how to install a //debian8// system for QEMU.  
- 
-==== Build a Standard QEMU Image ==== 
- 
-Depending on your host configuration, it is recommanded to build light VM system in text mode, without graphical interface and heavy desktop manager! 
- 
-<code> 
-# download the iso for your favorite system 
-wget http://cdimage.debian.org/debian-cd/8.x.x/amd64/iso-cd/debian-8.x.x-amd64-netinst.iso 
- 
-# create a disk image for your VM (8G) 
-qemu-img create debian.img 8G 
- 
-# install your VM from cdrom 
-qemu-system-x86_64 -enable-kvm -hda debian.img -cdrom debian-8.3.0-amd64-netinst.iso -boot d -m 512 
- 
-# after installation is complete, reboot your VM and test it 
-qemu-system-x86_64 -enable-kvm -hda debian.img -m 512 
- 
-</code> 
- 
-__Nota Bene__ : If you would like to copy/paste this latter line, unfortunately this is not possible with the standard QEMU display based on SDL. However, the //xterm// QemuNet option, described in the previous section will help you ;-) 
- 
-In order to use your //debian8// in QemuNet, you need to add a new entry in //qemunet.cfg//. 
- 
-<code bash qemunet.cfg> 
-# IMGDIR="/absolute/path/to/raw/system/images"  
-if [ -z "$IMGDIR" ] ; then IMGDIR="$(dirname $(realpath $0))" ; fi 
- 
-# debian testing 
-SYS[debian8]="linux" 
-FS[debian8]="$IMGDIR/images/debian8/debian.img" 
-QEMUOPT[debian8]="-localtime -m 512" 
-</code> 
- 
-Now, you can test your system in QemuNet in __standalone mode__. This mode is useful to complete your installation before to use it for virtual networking. In this mode, you have a direct access to disk image in raw format. 
- 
-<code> 
-./qemunet.sh -l debian8 
-</code> 
- 
-==== Resize your Image File ==== 
- 
-If you need to resize your VM image file, for instance, to add 1GB... 
- 
-<code> 
-qemu-img resize debian.img +1G 
-</code> 
- 
-Then after booting the VM, you can use fdisk to remove all partitions (command 'd') and create a new Linux one (n) with default options. Check /etc/fstab and correct it if required. The reboot your VM. 
- 
-After that, use resize2fs on the / partition: 
- 
-<code> 
-df -h /                # -> /dev/sda1 
-resize2fs /dev/sda1 
-</code> 
- 
-__More details__: https://gist.github.com/larsks/3933980 
- 
- 
-==== Some Basic Tips for QemuNet ==== 
- 
-==Remove root password==  
- 
-Removing the root password in your VM will make your life easier...  
- 
-<code> 
-passwd -d root 
-</code> 
- 
-==Install your packages== 
- 
-<code> 
-apt-get install emacs-nox jed vim nano python-scapy tcpdump tshark \ 
-  dnsmasq dsniff xterm apache2 telnetd ftpd openvpn openssl vlan bridge-utils 
-</code> 
- 
-==Upgrade your system== 
- 
-First, edit "/etc/apt/sources.list" and replace it with the following lines to use an //unstable// release. 
- 
-  deb http://ftp.fr.debian.org/debian/ unstable main contrib non-free 
-  deb-src http://ftp.fr.debian.org/debian/ unstable main contrib non-free 
- 
-Then update your system... 
- 
-<code> 
-apt-get update 
-apt-get upgrade 
-apt-get install linux-image-xxx  # to get the most recent linux kernel 
-apt-get autoremove 
-apt-get autoclean 
-</code> 
- 
- 
-==Disable dynamic configuration for eth0==  
- 
-Edit /etc/network/interfaces and remove all the configuration lines for eth0. It will prevent some system boot problem with different network topolgy, that are not connected to Internet! However, as it will disable DHCP, you will require to launch the dhclient manually in standalone mode: 
- 
-<code> 
-dhclient eth0 
-</code> 
- 
-==Closing standalone session== 
- 
-<code> 
-rm /etc/resolv.conf 
-history -c 
-poweroff 
-</code> 
- 
-==== Some Advanced Tips for QemuNet ==== 
- 
-QemuNet provides some advanced options, that are specific for "linux" system. 
- 
- 
-== Mount shared directory == 
- 
-The mount option (-m, by default) is useful to share files between host and guest system files. In your QemuNet session directory (-s session_dir), you will find a directory for each VM that is connected to /mnt/host in the VM system file. For instance, let consider a VM named "myvm": the host directory "session/myvm/" is directly linked to the "/mnt/host/" directory of the myvm's system file and you got read/write permission. 
- 
-To do this, you just need to add the following line in /etc/fstab of your VM system file: 
- 
-  host  /mnt/host  9p  trans=virtio,defaults,nofail  0  0 
- 
-Dont forget to create /mnt/host directory. Here, //nofail// is important to enable the VM to boot without the '-m' option. 
- 
-For more details on this option in QEMU, please visit : http://wiki.qemu.org/Documentation/9psetup 
- 
-== Run VM in xterm terminal == 
- 
-The xterm option (-x) is useful to launch your Linux VM in no-graphic mode inside xterm, instead of the native SDL mode. For instance, it allows copy/paste with other VM xterm windows. Moreover, you can resize the xterm window without any problem. Simply, type commands: //resize// and/or //reset// to update xterm.   
- 
-To do this, you need to extract both kernel and initrd files from the VM raw disk image, and to provide it to QemuNet configuration file.  
- 
-Basically, you can get these files by copying them from /boot to the /mnt/host shared directory (see previous tips). Easy ;-) 
- 
-Else, you can try the following instructions on your host, that requires root privilege. 
- 
-<code> 
-sudo losetup /dev/loop0 debian.img 
-sudo kpartx -a /dev/loop0 
-sudo mount /dev/mapper/loop0p1 /mnt 
-cp /mnt/boot/initrd.img-4.3.0-1-amd64 initrd 
-cp /mnt/boot/vmlinuz-4.3.0-1-amd64 vmlinuz 
-</code> 
- 
-Then, update //qemunet.cfg// with KERNEL and INITRD arrays. 
- 
-<code bash qemunet.cfg> 
-# IMGDIR="/absolute/path/to/raw/system/images"  
-if [ -z "$IMGDIR" ] ; then IMGDIR="$(dirname $(realpath $0))" ; fi 
- 
-# debian8 
-SYS[debian8]="linux" 
-FS[debian8]="$IMGDIR/images/debian8/debian.img" 
-QEMUOPT[debian8]="-localtime -m 512" 
-KERNEL[debian8]="$IMGDIR/images/debian8/vmlinuz" # optional, but useful for -x option 
-INITRD[debian8]="$IMGDIR/images/debian8/initrd"  # optional, but useful for -x option 
-</code> 
- 
-== Startup script with SystemD == 
- 
-It is very useful to execute a user-defined script on startup, as for instance ///mnt/host/start.sh//. Indeed, it is a flexible way to configure each VM (hostname, ip, route, ...) without using qcow2 image. 
- 
-Make sure your //start.sh// script is executable and the first line is #!/bin/sh. Then create the //start.service// file in /etc/systemd/system as follow. 
- 
-<code text start.service> 
-[Unit] 
-Description=startup script 
- 
-[Service] 
-Type=oneshot 
-ExecStart=/mnt/host/start.sh 
- 
-[Install] 
-WantedBy=multi-user.target 
-</code> 
- 
- 
-== Startup script with rc.local (deprecated) == 
- 
-It is very useful to execute a //rc.local// script on startup, that launches a user-defined script ///mnt/host/start.sh// located in the shared directory (see previous tip). It is a flexible way to configure each VM (hostname, ip, route, ...) without using qcow2 image. 
- 
-<code bash /etc/init.d/rc.local> 
-#!/bin/sh -e 
-MYSTART="/mnt/host/start.sh" 
-if [ -e "$MYSTART" ] ; then sh $MYSTART ; else exit 1 ; fi 
-</code> 
- 
-<code bash /mnt/host/start.sh> 
-#!/bin/bash 
-echo mydebian > /etc/hostname 
-</code> 
- 
-Then set up the rc.local script... 
-<code> 
-chmod +x /etc/init.d/rc.local 
-chmod +x /mnt/host/start.sh 
-update-rc.d rc.local defaults 
-</code> 
- 
  
qemunet/debian.1473432394.txt.gz · Last modified: 2024/03/18 15:05 (external edit)