неделя, 17 април 2016 г.

How to restart touchpad without reboot

I'm so happy with this one.
When my laptop is very VERY loaded, sometimes (though not often), the touchpad decides it doesn't exit. No idea why, the mouse pointer just freezes on the screen and that's it. So today I found out how I can fix this without rebooting, which probably saved me 40 cpu/hours of calculations. Yay!
So here is what I did (following this). In the konsole:
$su
$equo install xinput
$ xinput --list
You see the id of the touchpad - mine is Elantech touchpad and was #13
$xinput disable 13
$xinput enable 13
And voila, I have touchpad again! And that's fantastic, because in my case even when I plugged the USB mouse, it didn't work, so it was a life-saviour. I love linux :)
P.S. Btw, while trying to figure out how to restart the touchpad I found this great site for kde shortcuts. I didn't know you could change the virtual desktop with ctrl+f1, ctrl+f2. Awesome...

понеделник, 11 април 2016 г.

My fight with qemu, part 2: ssh from host to guest

Ok, my next step is to install the planned guest OS and to run ssh on it. So this is my log of it.

1. Find an .iso.
For some reasons, the network install wasn't that glorious, though I tried only once.
So let's do it with the iso.
Note to self: don't xkill qemu while trying to install new OS, because it falls asleep, gets in d state and needs a restart to fix.
Second note to self: Don't install new guest OS from ISO while doing calculations on the PC which will prevent you to restart. Facepalm and go to sleep.
The iso I chose:
http://ubuntu.ipacct.com/xubuntu/14.04/release/
the x64 desktop version. I need something light and stable for the perversions I planned. So we start with XUBUNTU.
2. Install it on the virtual machine.
I made a new virtual machine with a 20GB raw partition and then mounted the iso as a cdrom from Machine->Details->Cdrom.
After that I started the machine and installed Xubuntu. Not much surprise there.
3. Try not to ruin your new install in the first 5 minutes.
A little surprise was that a software update crashed and I had to do:
$sudo dpkg --configure -a
once or twice and to restart to fix it.
4. Install ssh
To install ssh I followed this ubuntu tutorial.
Basically I did:
$sudo asudo apt-get install openssh-server 
then
$sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.factory-defaults
$sudo chmod a-w /etc/ssh/sshd_config.factory-defaults
 and
$sudo gedit /etc/ssh/sshd_config
 where I didn't change much, maybe just disabled password-less authentication and allowd X-forwarding (as stupid as it sounds for a virtual machine). 
Then:
$sudo restart ssh
to apply the changes. 
5. Connect to your ssh-server :) 
From your host machine do
$ssh user@home-ip
and from my host machine I could ssh to the virtual machine.
Now that's awesome! And quite easy! Still can't get ssh-server to work on my Sabayon. Oh, well, that's why I chose Ubuntu for the virtual machine.
 


  

неделя, 10 април 2016 г.

My fight with qemu, part 1: bridge wifi to guest machine

The situation - I need a virtual machine on one of bigger hards say /hda1. Ideally, it would be a light linux box for experiments, which should communicate with the host with "ssh".

I had this windows virtual machine I set up some time ago,so I decided to use it for a test. So starting qemu, the first thing I see is that I don't have access to my virtual machine - permission denied. Because it resided on /run/media/user/hd1 and of course, the qemu user didn't have permission to mess with /run/media.

To fix this, you need to edit the following file and to change the user to either your user or root. Both work. 
$nano /etc/libvirt/qemu.conf 
# The user for QEMU processes run by the system instance. It can be
# specified as a user name or as a user id. The qemu driver will try to
# parse this value first as a name and then, if the name doesn't exist,
# as a user id.
#
# Since a sequence of digits is a valid user name, a leading plus sign
# can be used to ensure that a user id will not be interpreted as a user
# name.
#
# Some examples of valid values are:
#
#       user = "qemu"   # A user named "qemu"
#       user = "+0"     # Super user (uid=0)
#       user = "100"    # A user named "100" or a user with uid=100
#
user = "root"

# The group for QEMU processes run by the system instance. It can be
# specified in a similar way to user.
group = "root"

# Whether libvirt should dynamically change file ownership
# to match the configured user/group above. Defaults to 1.
# Set to 0 to disable file ownership changes.
#dynamic_ownership = 1 
 
Then you need to restart libvertd. 
On older systems with: 
# [root@dev1 ~]# service libvirtd restart
 
On mine:
$systemctl restart libvirtd.
And that did the trick for the permissions. Now I can access my virt. machine! YAY

New problem - the virt. machine doesn't have internet. And trying to get it connected ruins the host internet connection. It turns out this is a major problem stemming from the fact you cannot bridge wifi connection with virtual network. At least not very easily. Well, luckily, it turned out it's not that impossible as it seemed in the beginning.Note: in all thing below: when I say "guest" I refer to the virtual machine OS, when I say "host" I mean the host OS as in your laptop's OS.

So this is how I did it. For the moment I have tested it only on one virtual machine, it worked, but clearly you'll have to do the arp line after each restart of the computer.
1. Start virt-manager
2. Connection details->Virtual Networks -> New (sub)network
The new network can have any name, but the network ip should be part of your network but not the same as you host network:
so if your host ip is:  192.168.1.240 and your router is at 192.168.1.1 (this is the gateway).
then the new subnetwork can be: 192.168.1.129/25
you need to know your guest ip for the last step so what I did for the DHCP is :
starting: 192.168.1.150
ending: 192.168.1.151
this will give you only 2 ips, but this way, you'll know that your host ip is either 150 or 151. If you plan to use only 1 virtual machine, even better, give it just 1 ip.
Also notice that when changing the ips, the gateway written in the text between the "network" field and the DHCP fields change. So when playing with the numbers, make sure the gateway is still the correct one and not something random (it happened to me like 3 times to get weird gateways). 
After setting up that, you click next, and next and in the final window, you choose from the falling menu
"Physical device: Wlan0" and from the second "Route".
Then you just click finish.
If you get an error: "Wlan0 already in use" the change the /25 to something different like /27 etc. IF you get some other random error, you either need to change the use in qemu.conf  to "root" or just google it and be persistent :)

After you click "Finish" and you get the message your subnetwork is ready, you need to test your host network, because if you get things wrong it will screw it. So try loading Google in host's browser or pinging it. If it works, rejoice!
If it doesn't work, stop that network from the virt-manager gui (the button is "-", or directly the "trash").
Then make a new one and try with different ips - the previous ones may be have been taken already.

If you do:
$route
you'll see info on your networks.‘virbr1’ and ‘wlan0’ shouldn’t have the same Destination. If they do, you'll need to remove virbr1 from the virt-manager gui and create a new subnetwork. Btw , if you like me get it to work from try number N, "vibr1" might be "vibr2" or more, just check the Connection details->Virtual Networks for the actual name.

Final step:
$sudo  arp -i wlan0 -Ds 192.168.1.180 wlan0 pub
where the ip you see is your GUEST ip! So in my case, I had two ips *.150 and *.151 and I did it twice.
$ sudo arp -i wlan0 -Ds 192.168.1.150 wlan0 pub
$sudo  arp -i wlan0 -Ds 192.168.1.151 wlan0 pub

After that, you are ready to give network to your virtual machine. You go to virt-manager, you click on the details of your virt. machine and from the NIC section you choose "VIRBR1" and for the device name - the hypervisor defaul. Click "Ok" (or whatever) and start your machine.With some luck, it will be finally connected!

If it is not, start over.  For better description, see the post where I found the solution + one similar which also helped.

I got it working after like 7 hours of googling and trying out solutions. But to my defence, I had no idea what all those options like "bridge, vepa, and passtrough" mean. So it could be just me, but if it's not working for you, just keep trying. The solution does work, even if it's messy and ugly.


Some resources which helped me figure out the situation:
qemu networking explained (source1, source2, source3 !!!, same as source3 but on ubuntu)

if you want to start the qemu from konsole, this link might come handy.
For eth0 bridging, I suspect things will be piece of cake, but I haven't tried them, so this link seems important.
There is aslo a script for routing from Wifi to qemu, but I couldn't make it work, probably because at the time I didn't know my guest ip. 

P.S. If after restart you don't have internet on your virtual machine you may want to 1) delete all the unnecessary connections in  Connection details->Virtual Networks and 2) run
$ sudo arp -i wlan0 -Ds 192.168.1.150 wlan0 pub before starting virt-machine, then do 
$systemctl restart libvirtd.
and then start your machine.
And or disconnect and reconnect it couple of times from inside the guest machine. At some point it starts working.