1

How can I run fastboot from VM on android devices connected to the host machine?

Without running USB passthrough, since I want to keep the USB connection on the localhost.

Note: fastboot refer to the particular android fastboot tool used to access android device in bootloader.

user1947415
  • 933
  • 4
  • 14
  • 31

1 Answers1

1

Unlike adb, fastboot does not run on a client-server model. It would be possible to extend it on this way - it is open source -, but this did not happen until now.

If you type the fastboot command, it needs an usb device. This can be an emulated one in a VM, proxying to a host usb one, or it can run on the host and use a host usb device directly.

However, usb passthrough is a flexible thingy - just as you can plug in-out an usb device into your host, so can you "plug in/out" virtual usb devices to your VM. Qemu monitor port (tcp 4444 by default), virsh or in the of virtualbox, some vboxmanage commands, can remove an usb device from your host and give it to the VM (and back). The details depend on your virtualization solution.

peterh
  • 11,875
  • 18
  • 85
  • 108
  • Thanks for your answer. How to "proxying to a host usb one" from the VM? – user1947415 Dec 27 '20 at 23:29
  • @user1947415 That is usb passthrough. Usb is a cable, like an ethernet cable (the protocol on it is *very* different, but it is still a cable, where you send and receive bits). As you can proxy a network connection, so you can proxy also an usb connection. If you proxy an usb connection from a virtual machine to the host machine, that is called "usb passthourgh". The important thing is, that usb is very flexible, so it should not be ever a problem to attach-detach usb devices from the virtual machine. – peterh Dec 28 '20 at 00:20
  • @user1947415 Btw, my experiences with qemu were not the best (it is the best in all others, imho), but the vboxmanage command for virtualbox can do everything. – peterh Dec 28 '20 at 00:21
  • @user1947415 You could also set-up a passwordless ssh and run the fastboot remotely on the host. Instead fastboot, you will need to execute `ssh your.host.ip fastboot`. You can write it into a script. – peterh Dec 28 '20 at 00:28
  • Ah, I see. I thought you are referring to another way of proxy. I am trying to avoid passthrough, since I would like to keep the access on host side. – user1947415 Dec 28 '20 at 16:57
  • @user1947415 Usb passthrough can any time detach an usb device from a host or from any guest, and attach it to another. What if is you attach it always to the device on which it is used? So you won't be able to run fastboot on two devices simultanuosly, but you can not run two fastboots even on the same device simultanously. – peterh Dec 28 '20 at 19:09
  • Yes, I think that make sense. Although, in my case, it would be always one device. I just need a way that both VM and host can run fastboot on the same device connected to the host. I guess the the best option now would be to create a proxy script named "fastboot" in VM which actually proxy the request via ssh to host. – user1947415 Dec 29 '20 at 19:01
  • The only concern with that is I have to open ssh access from VM to host, which I don't want to open for all commands. Is that possible to only allow this particular file to have ssh access? – user1947415 Dec 29 '20 at 19:07
  • @user1947415 Yes, I found this with google: https://research.kudelskisecurity.com/2013/05/14/restrict-ssh-logins-to-a-single-command/ . Btw, I already once made some similar, and it worked. It required some tricking also with udev (to handle if you plug in/out the physical device) and some `vboxmanage` commands. It was harder as I tought initially (well, I used virtualbox through vagrant, this pain you will spare out), but it could be done. – peterh Dec 29 '20 at 19:41
  • @user1947415 https://unix.stackexchange.com is very useful with the details. They are the only people on the SE who really know udev. :-) – peterh Dec 29 '20 at 19:44
  • @user1947415 In your case, if you don't have some specific reason (like a driver issue) to run the fastboot on the guest, I would wrap it around a script which puts it to ssh. Although it has a disadvantage, that filesystem access will need to happen from the host (i.e. `fastboot upload test.img` will be a test image on the host). – peterh Dec 29 '20 at 21:09