Skip to content

Instantly share code, notes, and snippets.

@tuxmartin tuxmartin/

Last active Aug 17, 2016
What would you like to do?
Okamzite spousteni prikazu ve virtualu


YouTube video:



mkdir -p /home/martin/qemu/data
cd /home/martin/qemu/data
qemu-img create -f qcow2 /home/martin/qemu/debian.qcow2 8G
wget -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:


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

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

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 // /mnt/qemu
// /mnt/qemu cifs  guest  0  0

Pridat do virtualu svuj SSH klic:

ssh-copy-id -p 2222 root@localhost


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/ pridat libovolne prikazy.

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

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.