Running rsync as a daemon

Adapted from http://www.jveweb.net/en/archives/2011/01/running-rsync-as-a-daemon.html

Environment: Lubuntu 14.04, QNAP TS-431

The first step in order to create a powerful backup facility with Time Machine like functionality requires that you run an rsync daemon on the machine to be backed up.

Create /etc/rsyncd.conf

In this case the foobarHome and foobarMusic sections are known as modules and foobarHome and foobarMusic are the module names. The module names are important and used when remotely connecting to the rsync daemon.

Create /etc/rsyncd.secrets

Secure /etc/rsyncd.secrets

Enable the rsync daemon

Edit

and enable by changing RSYNC_ENABLE to true. Optionally change the NICE values

Start the rsync daemon

Connect to the rsync daemon

To connect to the rsync daemon, specify a module name as set up in the rsyncd.conf file. You may append file paths to the module name

Samba, linux and QNAP

OS: Lubuntu 14.04
NAS: QNAP TS-431

Here is the procedure that worked for me to access Samba shares published from your QNAP NAS.

Enable SAMBA on the NAS

From the web UI to the NAS, go to

and select the Microsoft Networking tab. Make sure that the “Enable file service for Microsoft networking” is checked. Set the workgroup to match the workgroup setting on all of your Windows boxes. For me, that is WORKGROUP. Click the Advanced Options button and set the “Highest SMB version” to the highest value, which for me was SMB 3.0. Note that this may not be necessary, as the default is SMB 2.1, which may work fine. I have not tested with that. Click Apply

Install cifs-utils on your Linux box

Create an SMB credentials file on your Linux box

In your home directory create and edit .smbcredentials and add the following

you can use the NAS default admin user account as the user

Add mounts to /etc/fstab on your Linux box

Edit /etc/fstab as sudo and add the following lines to the bottom

You can create as many mounts as you want. For example, I created a directory under /homes on the NAS and then mount that as /mnt/backup and backup my laptop to that share.

Mount the new mounts

Graphical notification from scripts

Environment: Linux

My laptop is getting long in the tooth and some programs load very slowly. Since some of these programs are exposed on the desktop as shortcuts to scripts, you need to double click on them to launch them. Unfortunatly, because they load slow and there is no feedback, I can never tell if my double click was recognized. After looking around a bit, I found a tool, notify-send, that allows you to inject messages into the desktop’s notification system.

First, install the package

I wanted to modify the launch script for Android Studio, which is the studio.sh file in Android Studio’s bin directory. I added the following at the top of the script:

notification

This puts up a notification message for 6000ms with the idea.png icon with a summary of Starting and the body of Android Studio in bold below it. The notification pops up immediately, giving sufficient feedback so that I don’t keep mashing the mouse button to launch it.

Note that the body allows some simple HTML to be used and the icon argument can either contain the location of an image file or the name of a system standard icon such as these listed here http://askubuntu.com/questions/189231/where-are-the-stock-icon-names-defined-for-the-unity-panel-service-indicators-an

Oracle Java and update-alternatives

Environment: Ubuntu 14.04

The Linux alternatives system is an excellent way to install and use different program equivalents. If you update Oracle Java quite often (or even once), it can be a tedious task installing new links and removing any old ones.

Since I always install the JDKs in the /usr/lib/jvm directory with the pattern jdk* (eg /usr/lib/jvm/jdk1.8.0_20), this can make it easy for a script to find all of the JDKs. The script shown below will search for all of the JDKs in /usr/lib/jvm and allow you to install or remove all of the programs in the JDK’s bin directory into the alternatives system.

The syntax is:

to install a JDK and

to remove a JDK.

The script will show the list of JDKs and prompt as to which JDK it should perform the install or delete. Selecting the number corresponding to the JDK and hitting Enter will start the operation.

Fix speakers and headphones playing simultaneously after upgrading to Ubuntu 12.04

After upgrading to Ubuntu 12.04 (Precise Pangolin) on a Dell Inspiron 1720, the speakers continued playing even after plugging in a set of headphones. This problem has been reported and fixed in multiple forums. However, the fix requires a model number, which can not be easily guessed. Therefore, this post is meant to help those who have a machine similar to the Dell Inspiron 1720.

References:

This note applies to:

  • Ubuntu 12.04
  • Dell Inspiron 1720

The fix is applied by using the following steps:

  • Edit /etc/modprobe.d/alsa-base.conf and modify the appropriate line
  • Reboot computer

Edit alsa-base.conf

Initially, the file contained the following line:

This line must be commented out (in case you want it back) and replaced as follows:

After saving the file, rebooting the computer is all that is required.

Tethering iPhone 5.1 on Ubuntu 11.10

This blog site already features an note on tethering the iPhone to Ubuntu (http://www.bitsbythepound.com/tethering-iphone-on-ubuntu-11-04-397.html). However, since upgrading to iOS 5.1, when the iPhone is connected to the Ubuntu platform, an error is reported stating that “Unhandled Error Lockdown”.

This note applies to:

  • Ubuntu 11.10 (Oneiric)
  • iPhone 5.1

References:

The solution offered by this note is to:

  • Install the package repository offered by Paul McEnery
  • Adjust the package repository to be picked up in oneiric
  • Install the necessary packages from the repository
  • Configure

Install Package Repository from Paul McEnery

Adjust Package Repository for use in Oneiric

I applaud the work done by Paul McEnery in providing us the tools to use the iPhone. Unfortunately, the package repository is not available for Ubuntu 11.10. On the other hand, the package repository for Natty (11.04) seems to work just fine for Oneiric. In this step, the package list is modified to point to the Natty version.

While editing the file, replace “oneiric” to “natty” and save again. The resulting file should look something like:

Install Necessary Packages

Configure

The first step of configuration is to tether the iPhone to the platform using the USB connector. Then, run the following command:

Finally, unplug and re-connect the iPhone. The error should not be reported. Instead, all services from the iPhone should be available.

Fix jumpy mouse with PlayOnLinux (wine) in Ubuntu

Since upgrading to Ubuntu 11.10, some games that used to run perfectly using PlayOnLinux started to display unwanted behaviour. In particular, the mouse jumps from the expected position in Starcraft: Broodwar. This behaviour prevents efficient playing. Researching the Internet shows that many other games are plagued by the same problem.

This note applies to:

  • Ubuntu 11.10
  • PlayOnLinux 4.0.16
  • Wine 1.3.18
References:

Many solutions are offered on the Internet which did not work on my system. However, the problem appears fixed in a newer version of Wine. The approach offered in this note is to install Wine 1.4. The latest version of Wine is not yet available via the packages offered by Ubuntu. However, the latest version (beta) is available via the WineHQ’s PPA. The following steps adds a new package repository and updates Wine to the latest version available from this repository. As an interesting note, Wine 1.4 is available via the package named wine-1.3.

After those changes, you can verify the version of the currently installed version of Wine with the following command.

Conclusion

Wine and PlayOnLinux are great tools. The complexity of the task performed by those tools is such that one must expected some unstable versions. This note demonstrated how a user can jump into experimental versions of Wine to access solutions earlier than pushed by the standard packages.

Using a Solid State Drive (SSD) with Ubuntu 11.04

I have been using a Solid State Drive (SDD) for some time and I have decided to share my notes on how to do it and references I have followed. The configuration I use is to have two disks attached to my platform: the first is the SSD and holds the Operating System; the second is a magnetic drive which holds my home partition.

This note applies to:

  • Ubuntu 11.04
  • ATA INTEL SSDSA2M080G2GC
  • ext4

From research, the important aspects that need to be dealt with when using a SSD are:

  1. Enable TRIM
  2. Disable access timestamp on files
  3. Adjust disk scheduler
  4. Moving log files to RAM drive

Each of these topics are discussed separately below.

Enable TRIM

TRIM is the process under which an operating system tells a drive that a sector is no longer in use. This is not necessary for magnetic drives and, historically, operating systems did not provide this information to the drives as it increased the amount of information traversing between a host and its drives. However, this information is crucial for SSDs as it is needed to perform proper wear leveling.

Information on TRIM can be found via these links:

In Ubuntu, TRIM is enabled via the file “fstab” located in “/etc”. One needs to find the drive associated with the SSD and add the option “discard”. To edit the “fstab”:

Then add the “discard” option to the drive concerned. In my example, the root drive is the SSD. Therefore, the resulting file looks like:

After the “fstab” file is modified, one must reboot the system for the change to take effect.

After reboot, one should ascertain that TRIM was in fact enabled. To do so, a trick provided by Nicolay Doytchev is used (link above). However, it is claimed that this trick works with ext4. One might not get expected results from other disk format.

1. Become root and move to a directory managed by the SSD:

2. Create a file with random bytes in it:

3. Get and record the disk sector address for the beginning of the file:

Note the number under begin_LBA and use it for <ADDRESS> below:

4. Access file data from disk (replace /dev/sdX for the drive you are enabling in fstab):

The result of this should be random bytes and look like this:

5. Delete the file and synchronize the file system so that changes are pushed to the SSD:

6. Finally, repeat the command from step 4. Reading the same disk sector should yield an empty sector. For example:

Disable access time stamps on files and directories

Every time a file is accessed, a time stamp for last access is recorded with the file. It is believed that this information is generally unnecessary and that it is the source of a lot of wear on a SSD. Turning off access time stamps does not disable last modified time stamps, which are crucial to a lot of computer tools.

However, it is possible that some tools you are using rely on last access time stamps. Therefore, I suggest that you disable access time stamps separately than all other changes you make to your system. Turn it off and then leave your system unchanged for a while to see how it performs under this mode. In that period, try out all your tools. Tools that rely on file caching might not do as well as others.

Interesting links about last access time:

Disabling last access time is done by adding the options “noatime” and “nodiratime” for the SSD to the file “fstab” under the directory “/etc”. First, edit the “fstab” file:

Then, locate your drive and add the options “noatime” and “nodiratime” at the appropriate line. For example, my file looks like:

After the file is saved, one must reboot the operating system for the changes to take effect.

After reboot, you can verify that the recording of access time is not longer in effect with the following tests:

1. Move to a directory managed by the SSD and writable to your user. If your home directory is on the SSD, then the following would work:

2. Create a file for testing purposes:

3. Record the last access time:

4. Wait for a minute or two to elapse (you can use ‘date’) and then read the file:

5. Repeat command from step 3 and compare the results. If the same time is returned, then “noatime” is in effect. If a newer time is returned the second time, then the operating system is still recording access time for the file.

6. Clean up after yourself and delete the test file:

Adjust Disk Scheduler

By default, the CFQ scheduler is used to access a drive. This scheduler is designed for magnetic drives and take into account variables such as seek times. In SSDs, access time is fairly constant. Therefore, there is no need for a complex scheduler and addressing requests on a first-come-first-served basis is adequate. I have used the “noop” scheduler and this is what I demonstrate. However, there is an interesting post at this blog that might convince otherwise.

The trick offered here changes the scheduler after the boot is performed and as the operating system is starting it services. Therefore, the boot process does not benefit of these changes. The post above provides links to enable scheduler at the boot loader.

Myself, I like keeping my boot loader as clean as possible, so I have adopted this trick.

1. Edit the file “/etc/rc.local”:

2. Add the following line by taking care to replace sdX for the proper drive:

This change will take effect at the next reboot. However, to save a reboot, one can apply the change right away with (again, replacing sdX for proper drive):

Moving log files to RAM

Log files are a source of constant writing to disk. Personally, I have not yet made the change to my drive for two reasons:

  1. I am ambivalent about throwing away the logs since I sometimes rely on them to find causes of crashes. Given I keep up with the latest version of Ubuntu and that I have a set of problematic video drivers, I feel I must keep my logs around.
  2. Of all the solutions offered, I have not been able to make one work to my liking. I find a lot of solutions presented on the web are finicky and prone to errors.

However, my research indicates that this will yield to an earlier retirement of my drive. Therefore, I offer here a link that I found useful on this topic:

Other readings

Here are a couple of interesting links that might guide you in your decisions. I do not personally endorse the views presented there. However, I believe they provide good food for thoughts:

Conclusion

With a SSD drive, the time to boot up has greatly decreased and performance associated with my development tools as increased. Surprisingly, the general temperature reported by my laptop sensors has also gone down. However, as most activities performed on computers are “web based”, the network-bound activities have remained pretty much the same.

All in all, I have been quite satisfied with my purchase of a SSD drive.

Tethering iPhone on Ubuntu 11.04

Reference:

  • Ubuntu 11.04
  • iPhone 3GS with iOS 4.3

The following steps can be used to enable tethering between a platform running Ubuntu 11.04 and an iPhone. At a high level:

  1. Enable tethering on iPhone
  2. Install repository from Paul McEnery
  3. Install necessary packages
  4. Connect

Enable Tethering on iPhone

The use of iPhone tethering might be governed by your wireless plan. If data tethering is allowed, one should be able to turn it on using the “Settings” application.
In the “Settings” application, choose “Personal Hotspot” from the menu, and enable it by pushing the switch to “on”.

If one can not accomplish this step, the remainder steps from this article will be in vain.

Install repository from Paul McEnery

Adding package “python-software-properties” provides the command “add-apt-repository”. This command is then used to make it really easy to add a repository from PPA.

Install necessary packages

Once the repository is installed, installing the packages is straight forward:

During the configuration of those packages, a kernel module must be built. In the case that the kernel headers are not installed, the following error message is printed on the screen:

Module build for the currently running kernel was skipped since the kernel source for this kernel does not seem to be installed.

In this case, the proper headers must be installed. To find out which headers are required:

Then, install the headers using the following command. Ensure that you replace the proper version according to what was returned previously.

When this command completes, the iPhone module should be built. If not, then the system can be prompted to rebuild the kernel module:

Connect

Connect the iPhone to the platform using a USB cable. When the USB device is detected, an Ethernet should be established automatically.

Login package updates messages are incorrect

We have a couple of machines running 10.04 LTS and they have been showing messages similar to the following when you ssh to them.

11 packages can be updated.
7 updates are security updates.

And yet, when you do an update, there is nothing to update. There was a bug that caused the package update information to be incorrectly dumped into /etc/motd.tail and never updated. The bug was fixed, but the incorrect /etc/motd.tail was never cleaned up. This can be fixed by removing /etc/motd.tail. The correct information will be generated when available in /var/run/motd.

Reference: http://old.nabble.com/Where-does-the-%22n-packages-can-be-upgraded%22-message-come-from-td31632514.html