Friday, May 26, 2017

Dual GPU Laptop in Ubuntu. (NVIDIA and Intel HD5200)

I just bought myself a Thinkpad Yoga 14. I'm loving its IPS FHD screen which is accompanied with NVIDIA 840m GPU in addition to its onboard Intel HD5200, which more than enough to satisfy my occasional craving to game and do 3D rendering :)

Here are some useful stuffs I learned about dual GPU setup in Ubuntu.

  1. NVIDIA isn't installed by default.
    • It's running on Intel HD5200 by default because that's what's installed with the default Ubuntu setup.
    • Instruction to install NVIDIA driver can be found here:
      • Find out the latest driver that is compatible with your GPU.
      • To ease  out the process, install the driver via apt-get (e.g. sudo apt-get install nvidia-375 if NVIDIA page says that your latest driver is 375.66)
  2. After your driver is installed according to step (1), you can switch between NVIDIA or onboard GPU via 'nvidia' program (open app search pane, type 'nvidia')
    • Unfortunately, the new GPU to be used is only applied after a logout..
  3. How to switch GPU without logging out or restarting?
    1. Fire up terminal
    2. sudo prime-switch nvidia  to switch to nvidia
    3. sudo prime-switch intel  to switch to nvidia
Enjoy! I'll update this page as I find new tips and tricsk.


Source:
https://linuxconfig.org/how-to-install-the-latest-nvidia-drivers-on-ubuntu-16-04-xenial-xerus

Friday, May 5, 2017

Downgrading Mysql 5.7 to Mysql 5.6

I just got a new system where I installed mysql through apt-get. It installed 
mysql version 5.7, which unfortunately didn't serve my purpose well. That 
version added a new constraint such that when there's a GROUP BY keyword in a
SELECT clause, the only columns that can be selected are those that are part of
GROUP BY. 

I could possibly disable the constraint, but I just felt like sticking with
version 5.6 which had been working fine for me. Because of this, I decided to
downgrade to 5.6.
Step 1. Remove all 5.7 components. The second line is important, because
it seems that there are some settings that if not deleted, version 5.6 wouldn't
run.
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-5.7 mysql-client-core-5.7
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get autoremove
sudo apt-get autoclean
Step 2. Install version 5.6
 sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty universe'
 sudo apt-get update
 sudo apt install mysql-server-5.6 * see note below if you get an error
 sudo apt install mysql-client-5.6
Step 3. Restart the service
sudo service mysql stop
sudo service mysql start

Thursday, May 4, 2017

XKB Keyboard Mapping - Remapping a Key

I just bought myself a S3 Yoga 14. After installing Ubuntu 16.04, I found out that the key that was suppose to spew out 'pipe' and 'backward slash' (when shifted) actually spewed 'greater than' and 'less than'. This little write up explained how I fixed it.


As a reference, please read this first to get some relevant information:
http://www.antoniusdharijanto.com/2015/10/simple-key-re-mapping-on-ubuntu-1404.html


Steps
1. Figure out the keycode of the offending key
There's a little program 'xev' that when runs from terminal, it would give information about whatever key is pressed, including the keycode.

2. Figure out what the key from (1) is supposed to map into.
Since I have another laptop running Ubuntu, I just run xev there and figure out the keycode of the key 'pipe' and get the action from /usr/share/X11/xkb/keycodes/evdev

2. Re-map that keycode to pip
Open up /usr/share/X11/xkb/keycodes/evdev and remap that keycode to the proper functionality.


Update:
The key to be updated was:
<BKSL> = 94; // Note that other occurence of BKSL has to be commented out for this to work

Thursday, December 29, 2016

Fingerprint Authentication on Ubuntu 16.04

Just for fun, I googled around about how to enable fingerprint login in my X201 with Ubuntu 16.04. And then I came across this super cool tool that let you not only login, but to 'sudo' using fingerprint! How cool is that? Goodbye typing password while thinkering around with system-privilege :)

Here's how you install it:
https://launchpad.net/~fingerprint/+archive/ubuntu/fingerprint-gui


Friday, December 2, 2016

Some Daemons are Not Automatically Started on Ubuntu 16.04

I had a crucial daemon to prevent my laptop from restarting, which is thinkfan (explained here):
http://www.antoniusdharijanto.com/2014/09/corner-cases-of-ubuntu-1404-on-lenovo.html

After upgrading to 16.04, the daemon is no longer started automatically. I noticed this because my laptop restarted itself due to overheating. And the reason is because Ubuntu 16.04 uses systemctl daemon manager as oppose to upstart that 14.04 earlier used.

Here's the solution:
1. Make sure thinkfan is upgraded to the latest (e.g. sudo apt-get update && sudo apt-get install thinkfan). Latest version has systemctl enabled for it.
2. Check if thinkfan can run: sudo systemctl start thinkfan.service
3. Enable the daemon if (2) succeeded: sudo systemctl enable thinkfan.service
Optional:
4. To get it to restart automatically upon crash:
Edit /etc/systemd/system/multi-user.target.wants/thinkfan.service and add 'Restart=always' under [Service] section.

P.S. I notice the same think with mysql daemon. Using the same command, systemctl is smart enough to redirect the command onto sysv that mysql is using.

Enjoy!


Source:
https://www.digitalocean.com/community/tutorials/how-to-configure-a-linux-service-to-start-automatically-after-a-crash-or-reboot-part-1-practical-examples

Thursday, December 1, 2016

Ubuntu 16.04 stucked on boot logo after an upgrade from 14.04

Yesterday I finally decided to let Ubuntu autoupgrade system update my 14.04 into 16.04. After some time, my laptop got really hot, which seems to be caused by some CPU-intensive operations of the upgrade. It got too hot until a point that the firmware decided to shut my laptop down forcefully. Crap! I'm in the middle of an update!

Yes, as you can already guess, my laptop now stucked on boot logo! What's even worse, the boot logo didn't even animate, which means it hung and I can't use emergency mode or tty2!

I almost thought I had to re-install the entire OS from scratch, which would have been much painful considering all the programming tools and libraries I've painstakingly installed throughout the past year! Fortunately, many people out there shared how they recovered their systems!

[SOLUTION]
There really are two things that need to be done:
1. Complete the unfinished upgrade
2. After (1), turned out my system still wouldn't boot, so need to diagnose and debug this.


1. Complete the unfinished upgrade
This can be done via "chroot"-ing onto the broken system via Live CD. For those unfamiliar, "chroot" is a mechanism to "get into" another Linux installation from a currently running one. In this case, the currently running is one from Live CD and the other one is mine that wouldn't boot. It's done as follow:

a. fdisk -l #Figure out the disk where your other Linux is installed
b. mount /mnt/ /dev/sdX #'/dev/sdX' would be from step (a)
c. for i in /sys /proc /run /dev /dev/pts; do sudo mount --bind "$i" "/mnt$i"; done # This is so the chroot-ed system has access to current Linux's hardware nodes that are necessary, for example for internet connection
d. sudo chroot /mnt/ #After this, you're shell is under the other Linux!

It's time to complete/fix the upgrade that has been halted.
a. sudo apt-get update # Update the list of cached components
b. sudo apt-get upgrade # Upgrade the system


2. After (1), turned out my system still wouldn't boot, so need to diagnose and debug this.
For me, there's still a problem that causes my Linux to get stuck on boot loop. After a while, the system got into emergency mode, where there's an option to go into root shell to do something. 

On the emergency mode:
1. journalctl
The shell immediately prompted me to run this command, so I did and found out the culprit:
"timeout waiting for device dev-disk-by..... " and several line below that, it seems that the failure is due to the system trying to mount /dev/disk/by-uuid/XXX that didn't exist. Turned out this was the path to my Windows partition, which changed after an upgrade to 16.04


2. vim /etc/fstab
I commented out the line that tried to mount the no-longer-existing path. And voilla! It worked like a charm!

Credit: 
http://www.webupd8.org/2014/01/how-to-fix-non-bootable-ubuntu-system.html
http://forums.debian.net/viewtopic.php?f=10&t=118828

Monday, October 3, 2016

Changing Device Permission Permanently through udev

Sooo, I've just bought a Raspberry PI for a project, along with a $5 webcam for a Computer Vision experiment. I immediately tried the quality of the camera using "cheese" Linux program on my Ubuntu laptop, and it worked out fine. Unfortunately, in Raspberry PI, the program simply wouldn't detect the camera.

After hours of debugging, apparently the problem was with permission. The webcam enumerates as /dev/video0, which has 0660. Since "cheese" runs as "other", it doesn't have the permission to read it. Manually modifying it through "chmod o+rw /dev/video0" does the job. However, I want a more permanent and elegant solution.

The solution is to use udev. Here're the steps:
1. Get the webcam's vendorId and productId through lsusb/dmesg.
2. Get its DRIVER and SUBSYSTEM (properties required for udev setting) through "udevadm info -a -n [device_path]" (device_path is sth like /dev/video0)
3. Create new rules as instructed here: https://wiki.archlinux.org/index.php/Udev#Video_devices
4. As a reference, in my case the rule file is created here: /etc/udev/rules.d/83-webcam.rules, with the content being: KERNEL=="video[0-9]*", SUBSYSTEM=="video4linux", SUBSYSTEMS=="usb", ATTRS{idVendor}=="05e3", ATTRS{idProduct}=="0510", SYMLINK+="video-cam1", MODE="0666"

What's bold is the part that specifies the permission.


Hope this helps!