Tuesday, November 14, 2017

Upgrading Ubuntu Linux Kernel

Sometimes there are problems with the kernel that a Ubuntu distro ships with. For example, on 16.04 LTS release image, my ThinkPad Yoga 14 S3 often fails to resume from sleep. And the latest version of this writing, 4.13.12, caused intermittent WiFi issue which required me to re-connect to the AP periodically.

In short, sometimes there are needs to switch to different kernel versions (sometimes older) to find the one that is the most stable for the hardware in subject.

Here's how you upgrade Linux Kernel:
1. Pick the kernel to update to in:
http://kernel.ubuntu.com/~kernel-ppa/mainline/

2. Download the 'generic' version of the right architecture (3 deb files)

3. Install the kernel from terminal
sudo dpkg -i *.deb

4. Reboot your system!

Tips:
You can boot to a different kernel version in Ubuntu. While booting up, once you get into GRUB bootloader, pick "Advanced Option" and select the version of kernel you want to use.

Tuesday, August 1, 2017

Saving Second Monitor Settings Across Reboots in Ubuntu 16.04

I recently used a second monitor with my Ubuntu 16.04 laptop. After a while, I realized that whenever the HDMI is re-plugged or if the computer is rebooted, the setting reset back!

For example, if I set the monitor to be at the left of my monitor through preferences -> display, it got reset back to be at the right of my laptop after a reboot.

The solution is to use xrandr:
First, run:

#This gives out information about ID of display that is currently running on the system.

xrandr


#After that, run command like the following to update the setting
xrandr --output HDMI2 --left-of eDP1


#Finally, the command can be persisted by writing it to ~/.xprofile file
echo "xrandr --output HDMI2 --left-of eDP1" > ~/.xprofile


For more information. look at this documentation:
https://wiki.ubuntu.com/X/Config/Resolution#Setting_xrandr_commands_in_.xprofile

Monday, July 24, 2017

Using Scanner in Ubuntu

After installing Epson scanner drivers from official Epson site, there are a few tools that can be used to scan:
1. scanimage terminal application
2. xsane GUI app
3. Simple Scan GUI app

The GUI apps are straight-forward to use. But I found that sometimes they just don't work. So I use the Terminal method when that happened :)

scanimage --resolution 300 --mode Color --format ppm > output.ppm

Friday, July 21, 2017

Can't create public-facing SSH server because of firewall or ISP policy? No worries, Reverse SSH Tunnel come to the rescue!

In regular situation, creating a public-facing SSH server, or any other server can be done as following:


Usually, the added complexity would simply be that ISP subscription only gives dynamic IP address, which gets randomized whenever the modem/connection is restarted. But this can easily be worked around using Dynamic DNS service.

However, today I encountered annoying issue. The ISP I used blocks their DMZ and Port Forwarding capabilities from their router! I called and they told me they had no solution! They also wouldn't let me tinker around with their router (i.e. installing Open-WRT or other open-source OS). But this turned out to be a great experience, because I learned a new cool SSH trick today!

 Reverse SSH Tunneling allows a relay-server that is publicly accessible to relay connection to private server that we have. So instead of SSH-ing to the private server, we SSH into the relay server, which in turn relay the connection to the private server. Wait, hold on a second! How could the relay-server establish a connection with the private server? Isn't it not publicly accessible? Simple, the connection between relay and private servers are initiated by the private server. So it's just like any computer can SSH into any publicly accessible SSH server out there.



The commands are the following:
# Run on private-server
# Tell nusantara-cloud.com SSH-server to relay any connection made to port 3559 of itself, to the private server.
ssh -R :3559:localhost:22 antonius@nusantara-cloud

# Editted on the relay-server:
# Without this configured, SSH-server would only relay connection made to port 3559 if it comes from loopback adapter. So this made it accessible from external world as well!
sudo echo "GatewayPorts clientspecified" >> /etc/ssh/sshd_config 
Credit: http://xmodulo.com/access-linux-server-behind-nat-reverse-ssh-tunnel.html

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