Skip to content

Instantly share code, notes, and snippets.

@tuxmartin tuxmartin/howto.md
Last active Aug 17, 2016

Embed
What would you like to do?
Okamzite spousteni prikazu ve virtualu

Ukazka

YouTube video:

ukazka

Instalace

mkdir -p /home/martin/qemu/data
cd /home/martin/qemu/data
qemu-img create -f qcow2 /home/martin/qemu/debian.qcow2 8G
wget http://debian.superhosting.cz/debian-cd/8.5.0/amd64/iso-cd/debian-8.5.0-amd64-CD-1.iso -O /home/martin/Stažené/debian-8.5.0-amd64-CD-1.iso

qemu-system-x86_64 -enable-kvm -m 512 -smp 2 -boot once=d -drive file=/home/martin/qemu/debian.qcow2,media=disk,format=qcow2 -drive file=/home/martin/Stažené/debian-8.5.0-amd64-CD-1.iso,media=cdrom -localtime -device e1000,netdev=user.0 -netdev user,id=user.0,hostfwd=tcp::2222-:22,smb=/home/martin/qemu/data

Nainstalovat Debian s SSH serverem.

Po instalaci Debianu do virtualu se do nej prihlasit a vytvorit soubor /usr/local/bin/asdf s obsahem:

#!/bin/bash

MD5=""
while true ; do
	MD5_TMP=`md5sum /mnt/qemu/cmd.sh`
	if [ "$MD5" != "$MD5_TMP" ]; then
		MD5=$MD5_TMP
		cat /mnt/qemu/cmd.sh | bash > /dev/tty1
	fi
	sleep 1
done
 

Dalsi veci... :

chmod a+x /usr/local/bin/asdf
sed -i 's/deb cdrom/#deb cdrom/g' /etc/apt/sources.list
apt-get update
apt-get install cifs-utils
mkdir /mnt/qemu
sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
systemctl restart ssh.service 
sed -i 's/GRUB_TIMEOUT=5/GRUB_TIMEOUT=0/g' /etc/default/grub
update-grub

do /etc/rc.local pridat pred radek exit 0:

/usr/local/bin/asdf &

do /etc/fstab pridat (nakonec dat prazdny radek):

mount -t cifs -o guest //10.0.2.4/qemu /mnt/qemu
//10.0.2.4/qemu /mnt/qemu cifs  guest  0  0

Pridat do virtualu svuj SSH klic:

ssh-copy-id -p 2222 root@localhost

Pouzivani

Spustit virtual

qemu-system-x86_64 -enable-kvm -m 512 -smp 2 -drive file=/home/martin/qemu/debian.qcow2,media=disk,format=qcow2 -localtime -device e1000,netdev=user.0 -netdev user,id=user.0,hostfwd=tcp::2222-:22,smb=/home/martin/qemu/data

a do souboru /home/martin/qemu/data/cmd.sh pridat libovolne prikazy.

echo "echo 'Hello world z virtualu'" > /home/martin/qemu/data/cmd.sh
echo "echo 'text z virtualu' > /mnt/qemu/vystup.txt" >> /home/martin/qemu/data/cmd.sh

ihned po ulozeni souboru se prikazy ve virtualu vykonaji (posilaji se pres rouru do bashe pod rootem).

Do virtualu se da prihlasit pres ssh: ssh -p 2222 root@localhost (bez hesla, prihlasovani klicem).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.