Last week, I wrote a blog post explaining how to copy files to a qemu image by mounting the qemu image in the host. This is only useful if emulated platform does not support networking.
If networking is enabled, using SSH (Secure Shell) or NFS (Network File System) is more convenient.
Using SSH with Qemu
To initiate the SSH connection from qemu, there is actually nothing extra to do as long as you have sshd installed and running on the host. If it is not installed simply run sudo apt-get install openssh-shell on the host. This will install and automatically sshd.
To initiate the SSH connection from the host, you’ll have to redirect the ssh port to an unknown port and start qemu as follow (for overo):
1 |
sudo qemu-system-arm -M overo -m 256 -drive file=./overo_sd_alip.img,if=sd,cache=writeback -clock unix -serial stdio -device usb-kbd -device usb-mouse -redir tcp:2222::22 |
Please refer to Beagleboard Emulator in Ubuntu with Qemu for the detailed instructions on how to setup qemu to emulate beagleboard or overo (OMAP3 Platforms)
Then install dropbear – a lightweight SSH server – in qemu:
1 |
sudo apt-get install dropbear |
This will also start dropbear automatically.
Once this is done, you can access qemu from the host as root or another user you may have added (Please note that 192.168.0.101 is the IP of the host):
1 2 3 4 5 6 7 8 9 10 |
ssh -p 2222 root@192.168.0.101 The authenticity of host '[192.168.0.101]:2222 ([192.168.0.101]:2222)' can't be established. RSA key fingerprint is e1:3d:e2:0a:aa:2b:23:9e:7a:f9:97:48:3a:78:11:3b. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[192.168.0.101]:2222' (RSA) to the list of known hosts. root@192.168.0.101's password: Welcome to Linaro 11.08 (GNU/Linux 3.0.0-1004-linaro-omap armv7l) * Documentation: https://wiki.linaro.org/ root@linaro-alip:~# |
If you do not wish to enter the password each time you connect, follow the instructions at No password SSH – Login to a SSH server with private/public keys
No SSH access is working fine, simply use scp to copy files between the host and qemu, for example:
1 |
scp -P 2222 overo_start.sh root@192.168.0.101:~ |
Using NFS with Qemu
You can basically follow the instructions given on Setting Up an NFS Server on Ubuntu to configure the host, with the difference that you’ll need to add the insecure option or the NFS connection will be denied (NFS4ERR_PERM) as the insecure option allows to use IP ports that are above 1024. So the /etc/exports file would look like:
1 |
/mnt/nfs *(rw,no_root_squash,async,no_subtree_check,insecure) |
Once the NFS server is configured on the host, you should be able to mount the NFS share in qemu:
1 2 3 4 5 |
root@linaro-alip:~# mkdir /mnt/nfs root@linaro-alip:~# mount 192.168.0.101:/mnt/nfs /mnt/nfs root@linaro-alip:~# mount | grep nfs 192.168.0.101:/mnt/nfs on /mnt/nfs type nfs (rw,vers=4,addr=192.168.0.101,clientaddr=10.0.2.15) root@linaro-alip:~# |
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress
Is this post up to date with the QEMU 1.4.0 Ubuntu 13.04 distribution?
I mean if all the required support are avaible to do ssh communication are enablead for beagleboard or overo machines?
Is there a setup on the emulation code that has to be done before been able to ssh? (by this I meen that for been able to use more than one uart on bealge I had to add more serial_hds arguments to this function :omap3_mpu_init(cpu_model, ram_size, NULL, NULL, serial_hds[0], NULL) in bealge.c and I wonder If I have to do somthing like this for ethernet type connections)
@Franc
I assume the redir option should still work. When I tried beagleboard emulator did not support Ethernet, only the Overo one had support.
I installed Open-ssh-client and server on both guest and host. I also installed dropbear on both.
Qemu cmd used:
sudo qemu-system-arm -M overo -m 512 -sd ./test.img -clock unix -device usb-mouse -device usb-kbd -serial pty -serial pty -serial pty -monitor pty -redir tcp:2222::22
I do an info usernet on QEMU<s monitor to get this:
(qemu) info usernet
VLAN 0 (user.0):
Protocol[State] FD Source Address Port Dest. Address Port RecvQ SendQ
TCP[HOST_FORWARD] 7 * 2222 10.0.2.15 22 0 0
then on the host side I use :
$ ssh -p 2222 root@192.168.0.101
ssh: connect to host 192.168.0.101 port 2222: Connection refused
ssh -p 2222 root@10.0.2.15
I tryied on guest side to ssh the host and this is what I get:
# ssh -p 2222 root@192.168.0.101
ssh: connect to host 192.168.0.101 port 2222: Network is unreachable
ssh -p 2222 root@10.0.2.15
ssh: connect to host 10.0.2.15 port 2222: Network is unreachable
ssh: connect to host 10.0.2.15 port 2222: Connection refused
using ifconfig on guest side I get this:
# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
usb0 Link encap:Ethernet HWaddr A6:21:64:EB:98:E5
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
basicly I have no Ethernet device. But A last check with info qtree showed this:
dev: lan9118, id ""
mac = 52:54:00:12:34:56
vlan = 0
netdev = hub0port0
bootindex = -1
mode_16bit = 0
irq 1
mmio ffffffffffffffff/0000000000000100
(qemu) info network
hub 0
\ user.0: index=0,type=user,net=10.0.2.0,restrict=off
\ lan9118.0: index=0,type=nic,model=lan9118,macaddr=52:54:00:12:34:56
Could you help me with this?