Quick fstab reference

The /etc/fstab file is used to set permissions on disk drives when mounted at boot. Based on this, one is able to read/ write/ execute files on the disk. The /etc/fstab is general permissions file for disk partitions, so it works on any Linux distribution.

Below is the typical contents of /etc/fstab for a 2-disk setup (OS installed on primary, applications/ media on secondary, both internal), which enables the user to run executable files. [Note that UUID values have been removed; actual fstab entries should have these values].

# /etc/fstab: static file system information.
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
# / was on /dev/sda5 during installation
UUID= / ext4 errors=remount-ro 0 1
# /home was on /dev/sda6 during installation
UUID= /home ext4 defaults 0 2
# swap was on /dev/sda8 during installation
UUID= none swap sw 0 0
# s33 on /dev/sdb5 (Secondary Drive)
UUID= /media/user/s33 ntfs-3g defaults 0 0
# s34 on /dev/sdb6 (Secondary Drive)
UUID= /media/user/s34 ntfs-3g defaults 0 0

The last 2 entries (lines starting with ‘#’ are comments) are for 2 NTFS partitions (/dev/sdb5, /dev/sdb6) on a secondary internal hard drive. These were added manually after the OS install on primary, which automatically added the first 3 entries (root, home, swap).

The options column above decides which permissions to be set for the drive. The value defaults contains the options rw, suid, dev, exec, auto, nouser, and async. This is a typical usage of a file system, where the user will be able to read, write, execute files. The contents specified by defaults can be checked in the manual for mount, towards the end:

$ man mount

For more restrictive permissions, we can individually set permissions via fmask (for files), dmask (for directories), and umask (for both) by providing the bitwise inverse of the actual chmod permission number we want to set, since these are bit masks. More details can be found in the community guide for fstab in Ubuntu here.

One thing to note is the UUID for these drives, which for a partition can be obtained by running

$ sudo blkid

as suggested in the fstab header above.

fix linux mint audio stuttering

With certain Intel HD audio cards, Linux Mint is found to stutter when sound volume is high. The exact threshold of the volume varies with the application/ media being played, but the stuttering is definite and bad enough to the point of being unusable. The issue is similar to what we often get in a sound system when we try to insert a audio jack to a socket, with the speaker volume set high. It may also occur in other Linux systems.

The problem is that in case the motherboard has a front headphone socket, the Linux audio driver tries to send output to that channel also (even though that socket is not connected to any audio jack, and the only output is the speakers connected to the back). If we disable this socket, then the issue is resolved. This is an issue with Linux only, since the same motherboard/ audio setup works fine with Windows.

To resolve the issue, we need to install hda-jack-retask, and override the front audio socket to disable it.

1. Install alsa-tools-gui package, which contains hda-jack-retask:
sudo apt-get install alsa-tools-gui

2. Open hda-jack-retask (Menu > Sound & Video > HdaJackRetask) and scroll down to ‘Green Headphone – front side’. Select ‘Override’ and from the choice list, select ‘Not Connected’. This means we override the front audio socket using a front end of the audio driver.

3. Apply the settings and test whether the audio issues are resolved – e.g. play a Youtube video at very high volume. The stuttering should be gone now.

4. Install boot override (in the same UI) to persist the setting across reboots.

setup mysql on linux

To use MySQL DB on a linux system, we need the MySQL server, client, and optionally, a UI client. For the UI Client, we will use DBeaver, which is a free universal DB client supporting MySQL, SQLite, Postgres, Oracle, and many more. We will create the DB using command line MySQL client, then connect to it using the UI client.

To setup MySQL GA (General Availability version) on Linux (Ubuntu and derivatives), below are the simple steps. Currently, the GA version is 5.6.

1. Download and install the .deb that adds MySQL repository to APT sources:
Download the .deb that corresponds to the version of Ubuntu. While installing the .deb, select the latest versions for all MySQL components (like Server, Workbench, Utilities), then select Apply from the same component list to end the selection.

2. Update the repository
$ sudo apt-get update

3. Install MySQL server and client
$ sudo apt-get install mysql-server mysql-client-core-5.6

Add root password when prompted during the installation. Also, MySQL server is automatically started at the end of installation. To stop it,
$ sudo service mysql stop

To start/ restart,
$ sudo service mysql start

To check whether started,
$ sudo service mysql status

4. Open MySQL client to create a database. We’ll later connect to this DB from DBeaver.
$ mysql -u root -p

Enter root password when prompted (the same one specified in the previous step).

5. Create the DB. In this example, we create the admissions DB that is used in Stanford’s Databases course.
mysql> create database admissions

Note that the database name is case sensitive in Unix.

6. Quits the MySQL prompt
mysql> \q

7. Install DBeaver as MySQL UI-based client
Download the 64-bit archive (assuming 64-bit OS), not the .deb file, because the .deb requires JRE 7 in PATH, whereas there may be a more recent version of Java in the system (say Java 8). Extract the archive, then add to PATH the base directory (which contains the dbeaver executable).

8. Open DBeaver
$ dbeaver

9. In DBeaver UI, create new MySQL connection with all defaults, user = root, and pwd = root pwd (for MySQL given in step 3). Put database name as the one created in step 5.

10. Connect to the DB, then run any scripts to create schema and data using the SQL Editor inside DBeaver (right-click on connection -> SQL Editor)

Now we are ready to run any queries against this database.

Install rJava in Ubuntu with Oracle Java

Ubuntu does not come with any Java installed, unlike Linux Mint which comes at least with openJDK. The rJava package in R requires a JDK to exist in the system. If one uses Oracle Java, then at this point, he may want to install Oracle Java instead of openJDK. This process is very simple:
1. Download Oracle JDK archive
2. Extract to a location with user access, say $HOME/apps/jdk1.7
3. Add/ modify 2 environment variables: Create/ open $HOME/.bashrc and add to the end:

export PATH

export JDK_HOME

4. Since this is the only java, we dont need the update-alternatives. That would be required in Mint, since the default /usr/bin/java would be provided by the pre-installed openJDK.

Now, we want to configure Java for R, using

$ sudo R CMD javareconf

This searches for java in the PATH, then configures R to use that Java (does not modify any system environment variable). The problem with this command is that by default, it picks JAVA_HOME as $JDK_HOME/jre, instead of $JDK_HOME. Because of this, R thinks that only JRE exists in the system, and not JDK (which it requires). Hence, instead of above command, we give

$ sudo R CMD javareconf JAVA_HOME=/home/user/apps/jdk1.7

where ‘user’ is the username. This is the JAVA_HOME that we want R to have in its javaconf, because this is the JDK_HOME and not JRE_HOME.

Also, the JAVA_HOME system environment variable takes precedence over the one in R javaconf, hence we must remove it. If

$ echo $JAVA_HOME

returns something, it means at some point we had set the variable, so we must remove it. The command for R javareconf earlier would not set it, because as mentioned it does not create/ modify any system environment variables. To remove it,

$ unset JAVA_HOME

At this point, we have configured R javaconf, and ensured that JAVA_HOME is not set in the system. It therefore exists only in R javaconf. Open R (or RStudio), and install rJava:

> install.packages("rJava")

If behind a proxy, we can set R env var http_proxy. Open $HOME/.Renviron (create if does not exist) and add the line having format:


install linux as a virtual machine

This post is a one stop reference for all steps that need to be followed to install Linux as a Virtual Machine (guest) on another Operating System (host), using a hypervisor program (VM player). There is no need to download a precompiled Virtual Disk Image; we can create our own through the hypervisor program itself.

In this example, the guest OS is Ubuntu 14.04 LTS 64bit, and host OS is Windows 7 64bit. The hypervisor program used is Oracle VirtualBox.

1. Install VirtualBox
Install VirtualBox (latest) after downloading from here. Since our host is Windows 7 64bit, the one of interest is for Windows host and 64bit. This is approximately 100MB.

2. Download Linux ISO
Download the standard ISO image of Ubuntu Linux 14.04 LTS 64bit from here. This is approximately 1GB.

3. Create VM
a. Open VirtualBox and click on ‘New’ to create a VM. Give a name like ‘Ubuntu1404’. The other choices automatically select Linux and assume 64bit, which is what we want. For other architecture, change it.

b. Next, select 1GB of RAM to be used by this VM. With all the fuss about new GNOME and Unity desktops, 1GB is a good balance. Since our host is Windows 64bit, we can safely assume we have at least 4GB RAM. Otherwise, it is more prudent to install the OS as a dual boot rather than running as VM in the first place. For 32bit guest, 512MB RAM should suffice.

c. Next, select ‘Create a virtual hard drive’. The recommended size is 8GB; spare a couple more if possible to make it 10. This is not required, but just gives us some extra space in case of a large download or installing lots of packages.

d. In the next two screens, select VDI (default), and ‘dynamically allocated’ so that 10GB is consumed only when required, until then it is available for host to use. ‘Fixed size’ will also do, in which case entire 10GB will be unavailable at once to the host system.

e. Next steps will ask for the ISO image to install the OS on that virtual hard drive. Point the location of ISO image to where downloaded in step 2, then the install steps are as straightforward as if we are doing everything on a single isolated hard drive of another computer. So in most cases, the first option in the installer of ‘erase everything’ will do just fine. For more assurance, select ‘custom’, confirm that the only hard drive visible is the virtual one, and set the root mount point (‘/’) to it. The bootloader will have automatically selected the virtual drive. All these, because the host drive is not visible to the installer, thus there is no way to mess it up.

f. After installation, the VM is created for use. Restart the VM if prompted, and it will boot into Ubuntu Desktop. The VM will be displayed on a separate window of its own, and VBOX will run on another ‘main’ window. Now we can perform some necessary adjustments.

4. Install Guest Additions
Start the VM by clicking on ‘Show’ (if not running). It will prompt about some shortcuts that can be used to shift focus out of the guest into the host. Make a note of them. Once the deskotop has come up, go to the VBOX menu (on the window displaying the VM, not the main VBOX application) by using the appropriate shortcut. In Devices menu, click on ‘Install Guest Additions CD Image’. This will mount the VBOXGuestAdditions.iso as a media and open a terminal, on which, the extra packages will be installed automatically. This comes with VirtualBox, and contains extra features like:
a. Mouse pointer integration
b. Shared folders
c. Support for desktop resolutions higher than 640×480
d. Seamless windows
e. Generic host/guest communication channels
f. Time synchronization
g. Shared clipboard
h. Automated logons (credentials passing)

Most of them are very useful, so no point in holding from installing the extra packages for them. Once the guest additions are installed, restart the VM, and immediately we can see a change in screen resolution towards better. Also, mouse integration is now seamless, i.e. we no longer need to provide any shortcut to shift focus, simply moving the mouse will do.

Other benefits can be availed by changing some ‘Settings’ (Gear icon on the VBOX main window, or Machine > Settings menu on the VM window) like
In General > Advanced, select ‘Bidirectional’ for clipboard sharing.
In Display > Video, set the VRAM to 128MB (max allowed).
In Network > Adapter 1 > Attached to, check that ‘NAT’ is selected.
For more information, refer the documentation.

Note: The guest additions that come with VirtualBox may not be the right one for the guest OS version being installed. This may affect some features. In my case, the ‘Switch to Seamless Mode (Host + L)’ and ‘Auto-resize Guest Display (Host + G)’ were found to be not working after I installed the guest additions as mentioned above (i.e. from Devices menu). In order to bypass this problem, pull the right guest additions from the Ubuntu repository:

sudo apt-get install virtualbox-guest-x11

This will download the guest additions specific to the guest OS version. This is only about 2 MB of additional download over the one installed through VirtualBox.

5. [Optional] Proxy settings for VM
If behind a proxy, set the proxy settings to be used to connect from the VM (shut it down first):
a. In VBOX main application, select File > Preferences > Proxy. Set the proxy server (ex. http : // myproxyserver . com) and port (say 80), in the fields provided.
b. In VM, programs like apt-get, Node npm, Python pypi etc. require separate proxy settings. Else, with the previous step, only the browser will be able to connect from VM and these will not work. Each of these programs have their own proxy configuration setting; lets set for the one to be most frequently used, apt:

$ sudo gedit /etc/apt/apt.conf.d/01proxy

The ’01proxy’ file will not exist at first, so we create it thus. Then add the below line to it:

Acquire::http::Proxy "";

Save the file, and test apt-get:

$ sudo apt-get update

For other programs, set proxy in their individual config locations, like global/ local config list for npm, etc.

Now the VM will be fully usable as a virtual computer inside Windows, that has 10GB HDD and 1GB RAM.