Category Archives: Linux

Bash Script Templates

The basic and expanded templates I use to begin most of my bash scripts:



Syntax Highlighting in Blog Posts with Vim

Update: Reader Elder Marco has pointed out that does have support for syntax highlighting of source code built-in (which I had never heard of before) that might be a preferred alternative for some. An example of both is below.

Vim is a great all-around editor, it also does very good at syntax highlighting. With the plugin “TOhtml” included with Vim it’s easy to put that highlighting into a blog post. I created a blogscrpt bash script that when run on another script will produce a file defining the syntax highlighting in HTML code. From there it can be pasted into the blog post.

blogscrpt syntax highlighting:

# Create HTML code from Vim syntax highlighting (for use in coloring scripts)

scrpt=${0##*/}  # filename of script

# Display usage if no parameters given
if [[ -z "$@" ]]; then
  echo " $scrpt <filename> - create HTML code from Vim syntax highlighting"

# Syntax highlighting to HTML export
vim -f  +"syntax on"                  \
        +"set background=$background" \
        +"colorscheme $colorscheme"   \
        +"let html_use_css = 0"       \
        +"let html_no_pre = 1"        \
        +"let html_number_lines = 0"  \
        +"TOhtml"                     \
        +"x"                          \
        +"q" $filename

# Clean up HTML code
tidy -utf8 -f /dev/null --wrap -m $filename.html

# Delete the HTML meta page information.
sed -i '1,/body bgcolor=/d' $filename.html

# Remove line breaks (needed for some things like blog posts)
sed -i 's|<br>||g' $filename.html

# Remove the closing HTML tags
sed -i 's~</body[^>]*>~~g' $filename.html
sed -i 's~</html[^>]*>~~g' $filename.html

# Add preformatting tabs <pre> and </pre>
#sed -i '1 i <pre>' $filename.html
#sed -i '$ a </pre>' $filename.html

# Remove trailing blank lines
while [ "$(tail -n 1 $filename.html)" == "\n" ]; do
  sed -i '$d' $filename.html

# Delete newline of last <font> line for better formatting
sed -i ':a;N;$!ba;s/\(.*\)\n/\1/' $filename.html
sed -i ':a;N;$!ba;s/\(.*\)\n/\1/' $filename.html

# Delete final newline
perl -i -e 'local $/; $_ = <>; s/\n$//; print' $filename.html

WordPress built-in syntax highlight support example:

# Create HTML code from Vim syntax highlighting (for use in coloring scripts)

scrpt=${0##*/}  # filename of script

# Display usage if no parameters given
if [[ -z "$@" ]]; then
  echo " $scrpt <filename> - create HTML code from Vim syntax highlighting"

# Syntax highlighting to HTML export
vim -f  +"syntax on"                  \
        +"set background=$background" \
        +"colorscheme $colorscheme"   \
        +"let html_use_css = 0"       \
        +"let html_no_pre = 1"        \
        +"let html_number_lines = 0"  \
        +"TOhtml"                     \
        +"x"                          \
        +"q" $filename

# Clean up HTML code
tidy -utf8 -f /dev/null --wrap -m $filename.html

# Delete the HTML meta page information.
sed -i '1,/body bgcolor=/d' $filename.html

# Remove line breaks (needed for some things like blog posts)
sed -i 's|<br>||g' $filename.html

# Remove the closing HTML tags
sed -i 's~</body[^>]*>~~g' $filename.html
sed -i 's~</html[^>]*>~~g' $filename.html

# Add preformatting tabs <pre> and </pre>
#sed -i '1 i <pre>' $filename.html
#sed -i '$ a </pre>' $filename.html

# Remove trailing blank lines
while [ "$(tail -n 1 $filename.html)" == "\n" ]; do
  sed -i '$d' $filename.html

# Delete newline of last <font> line for better formatting
sed -i ':a;N;$!ba;s/\(.*\)\n/\1/' $filename.html
sed -i ':a;N;$!ba;s/\(.*\)\n/\1/' $filename.html

# Delete final newline
perl -i -e 'local $/; $_ = <>; s/\n$//; print' $filename.html

Ubuntu Oneiric: Final Touches

Note: A month ago I meant to write this article but experienced hardware issues. I wrote that in places that Oneiric was slow… I was wrong. Apologize for any inconvenience.

Here are some edits, additions, and subtractions that help complete the feel of the of Ubuntu’s 11.10 Oneiric desktop. Note that a couple modifications are made only for performance reasons for use with an older computer.


When installing Ubuntu, it is still recommended to do a clean (fresh) install of Ubuntu. Ubuntu/Debian engineers primarily focus resources on the install route therefore making it the recommended method.

Home folder on a dedicated partition

“How we work can be almost as important as what we do.”

Putting application preferences back together can be a lengthy process. A good work flow can dramatically improve productivity. Putting settings and documents on a dedicated partition will allow them to be easily built on from install to install. In Linux, configurations rarely ever cause problems. The Parted Magic Maintenance CD is a good tool to start with that can help with the process. More on how to do this can be found here.

When doing a clean install with a dedicated home partition, the partition needs to be defined during installation being sure to have it remain unformatted:


For future reference here is a package management helper script. It makes common package management related tasks easier to execute (and remember).

If planning to stick around with Linux, learn Vim. Vim is an excellent command line editor. Learning Vim can save time and be pleasurable to use (here to edit configuration files). More about Vim can be found here.

Hardware Setup

The first detail to focus on after installing Ubuntu is to get all hardware up and running. Ubuntu does good at discovering/setting up hardware but it isn’t able to do everything. First, the Additional Drivers control panel in System Settings may have hardware needed to be installed (some hardware setup requires user confirmation and is done here). After this, testing all devices and peripherals is recommended. It may in the end be necessary to visit the manufacturers website and download drivers. In most cases though to get the hardware working, information is usually available on the wiki.

Desktop Preferences

A number of options can be made to make a more efficient desktop; these programs will be needed to make the edits:

sudo apt-get install dconf-tools gconf-editor

Remove Unnecessary Startup Applications

To restore the ability to edit the Startup Applications do:

mkdir -p ~/.config/autostart
cd ~/.config/autostart
cp /etc/xdg/autostart/*.desktop .
sed -i "s/NoDisplay=true/NoDisplay=false/g" *.desktop

To save resources, select what is needed in Startup Applications. If not needed, Ubuntu One, Desktop Sharing, and Check Hardware Drivers can be removed. Removing Update Notifier too can save a good bit or resources if willing to update manually. To complete Update Notifier disabling:

dconf write /com/ubuntu/update-notifier/auto-launch false
sudo apt-get remove apt-xapian-index  # actually an old Synaptic plugin remnant


The Launcher with a couple edits can become more able to streamline the workspace.

Disable Auto-hide:

To have the Launcher always visible (usually recommended) do:

dconf write /com/canonical/unity-2d/launcher/use-strut true

Remove Multiple Desktops/Workspaces:

Save space on the Launcher if not using the multiple desktops feature:

gconftool-2 -s /apps/metacity/general/num_workspaces --type int 1
sudo cp /usr/share/unity-2d/launcher/Launcher.qml{,.bck}
sudo sed -i '/items.appendModel(workspaces)/d' /usr/share/unity-2d/launcher/Launcher.qml

This edit is temporary and will need to be run again when the unity-2d-launcher package is updated.

Add Show Desktop:

The ability to show the desktop can be done with the Super + D keypress (thats usually the Windows key) but to have the icon available on the Launcher an Xorg server interface tool will be needed:

sudo apt-get install xdotool

Create the .desktop so it can be pinned to the launcher:

echo "[Desktop Entry]
Name=Show Desktop
Exec=xdotool key --delay 300 super+d
StartupNotify=false" >>   ~/.local/share/applications/show-desktop.desktop

Open the file manager and drag the .desktop to the Launcher:

nautilus ~/.local/share/applications/

Numlock Enabled on Login

Because the numberpad exists on most keyboards and since it’s primary use is for doing calculations having the Numlock on by default is usually is the preferred option:

sudo apt-get install numlockx
sudo sed -i 's|^exit 0.*$|# Numlock enable\n[ -x /usr/bin/numlockx ] \&\& numlockx on\n\nexit 0|' /etc/rc.local

Turn Off Resume from Sleep Lock

More obstruction than protection for some the resume from sleep lock can be disabled:

gsettings set org.gnome.desktop.lockdown disable-lock-screen 'true'

File Manager Possibilities

Once the behavior is adapted to this feature can save time; however this behavior can be persistent: to streamline workflow consider using a single-click for files in the file manager/desktop. Set this in the File Manager under > Edit > Preferences > Behavior > Single click. For a slight speedup in the file manager, lower the preview values (Nautilus > Edit > Pref > Preview > No text icons, Thumbs for smaller file sizes, and Count number).

Application Indicators

Application indicators are the feedback icons in the menu bar on the top right. Here are some edits/considerations (changes to application indicators area don’t take effect until Logout/Login).

Switch Users Unneeded:

For single-user computer or if the feature is never used, save space by disabling the Switch Users indicator:

dconf write /apps/indicator-session/user-show-menu false

Google Web Mail:

Because of its’ efficient use of space and it’s connectivity possibilities the web interface of Google mail is preferred over email programs by a good number of people. There is an application indicator to notify of new Gmail email called gm-notify:

sudo apt-get install gm-notify

gm-notify can be configured additionally to play a sound when new mail arrives, check /usr/lib/libreoffice/basis3.4/share/gallery/sounds/curve.wav ia a possibility.

Other Indicators:

Additional application indicators can be found at Ask Ubuntu.

Laptop Touches

For regular laptop users the thought of limiting the touchpad from accidental scrolling and mouse click tapping is kept in the front of the mind. Consider using two-finger scrolling and disabling touchpad tapping instead.

Firefox Security

If on the Internet a lot, it’s a good idea to protect the application that primarily accesses it. There is a nice script written by Ignorant Guru that puts Firefox in a sandbox. To learn more read here. First install the PPA then install the script through the package manager:

sudo apt-get update
sudo apt-get install sandfox

The script is most productive in protecting from Adobe Flash security holes. A perk of the script is that it allows Flash preferences to be saved; a disadvantage is this allows a security hole. To plug the hole change the preference directories to read-only only by root:

cd ~
rm -rf .adobe .macromedia
sudo mkdir .adobe .macromedia
sudo chmod ugo-wx .adobe .macromedia

Then bind the folders read-only in the script:

sed -i 's_^hide=/home/\\$user/.adobe.*$_bindro=/home/\\$user/.adobe      # bind folder read-only_g' /usr/bin/sandfox
sed -i 's_^hide=/home/\\$user/.macromedia.*$_bindro=/home/\\$user/.macromedia # bind folder read-only_g' /usr/bin/sandfox

After this, the Sandfox package could be put on hold to prevent it from updating (thereby preserving changes made to the script):

echo sandfox hold | sudo dpkg --set-selections

Under the Hood

A few options on the system-level can help improve performance and help unexpected delays.

No Timestamping on File Access

Since Linuxs’ early days the kernel behavior has been to re-date a files’ timestamp every time a file is accessed. This reasoning goes back to its’ server days when users were more interested in knowing when a file was accessed rather then when it was edited (written to). For desktop users however the expected behavior is for the timestamp of a file to be when it was last edited. Tagging the option noatime to the filesystem will give the expected behavior, also this option additionally improves system performance by saving a number of writes to the disk. See more on this here.

Swap Value

For computers with plenty of memory available (1 Gigabyte will be enough for most uses), lowering swap priority can help improve performance. To change immediately do:

sudo sysctl -w vm.swappiness=20
sudo sysctl -w vm.vfs_cache_pressure=50

And to have it as this value used regularly add the values to /etc/sysctl.conf:


Match Filesystem Check Times

If more than one partition is used, having filesystem check times run at the same time will cause less number of unexpected boot delays. This can be done with tune2fs (Ubuntus’ default value is 33 mounts and six months):

sudo tune2fs -c 33 -C 0 -i 6m -T now /dev/partition1
sudo tune2fs -c 33 -C 0 -i 6m -T now /dev/partition2

Other Programs

Other useful programs are these (most are additional command line utilities that come in useful down the road):

sudo apt-get install cd-discid curl dos2unix dnsmasq epiphany-browser gdebi gimp gparted imagemagick inkscape iotop irssi lame librsvg2-bin links mp3gain msmtp openjdk-6-jre p7zip pdftk ppa-purge pwgen realpath ripit ruby tree unrar vim xclip

Vims is set up well as is, but to make it even better use a more-optioned configuration:

sudo mv /etc/vim/vimrc{,.bak}
sudo cp /usr/share/vim/vim73/vimrc_example.vim /etc/vim/vimrc

Being on the Internet a good deal a Domain Name Server address cache/query daemon can help a lot with improving web browser load times, particularly during busy hours (the NetworkManager connection will need to be re-established afterward for changes to take effect):

sudo sed -i 's:^#listen-address=:listen-address=' /etc/dnsmasq.conf
sudo sed -i 's:^#prepend domain:prepend domain:' /etc/dhcp/dhclient.conf
sudo service dnsmasq restart


  • Missed Touchpad Button Clicks – fix for a touchpad button that missed clicks regularly.
  • Hosts File Help – Only really a good idea for aging computers that can’t process complex ad-laden webpages.
  • Root Required – If around Linux for a bit eventually the root account will have to be used. To work in a familiar environment when it root link common home settings: sudo ln -s ~/.{bashrc,profile,vimrc,vim} /root

Editors’ Opinion

I’m happy with my setup. Originally I had thought I’d go straight to Gnome 3 Fallback but I’ve stuck with Unity and I like the simplicity of it; plus it runs well. With a desktop setup like this, I’m beginning to feel productive. Thanks to Linux and Ubuntu engineers that made this possible.


Western Digital My Book Essential External Hard Drive on Linux

I decided to sell my desktop computer and use my laptop exclusively, I had no need to keep another computer and since I was only using it for doing backups I decided it would be better to save some space.

I choose to get a Western Digital because they have been so reliable to me in the past. Of the external hard drives available at Wal-Mart it initially appeared not the be the best value. A Seagate right next to it was also a terabtye in storage capacity but also had USB 3.0 capability for only $15 dollars more. The WD Essentials has only USB 2.0 and I know that 3.0 is supposed to be considerable faster than 2.0. However, for me, my laptop is only USB 1.0 so this didn’t factor into it; also, because I am only using this for backups, time isn’t much of a factor and I prefer to have the reliability of the Western Digital name.

The My Book Essential HD has a capacity meter on the front to display how full the disk is. I learned though, unfortunately, that this only works through the Windows driver and using the NTFS file system. Because I’m going to be using this for backups on Linux with ext4 this feature isn’t available.

Since I have a Windows system installed I retrospectively learned that it is a good idea to install the driver/software for the drive there to setup the drive for only the reason so that I could disable the VCD. The Virtual CD Drive is a built-in memory chip that registers to the operating system as a regular CD drive. On it it contains the driver/software installer and manual. As far as the driver/software goes its nicer than I’ve seen of other hardware’s software, it was lightweight, easy to use, and with no frills. For Linux though the driver/software is unecessary as it is automatically recognized and working out of the box. I disabled the VCD drive with the Windows software though to keep the VCD from popping up when I loaded my Linux desktop.

I ran a S.M.A.R.T. conveyance test and extended test on it then did a thorough badblocks write test that took about 24 hours… all tests passed.

Formatting to ext4, the drive works perfectly in Linux without any additional configuration (besides noatime. I’ve been using the hard drive the last couple of months and I’m real happy with it: it’s small, quiet, and has done it’s job without a hitch.

DisplaySize in xorg.conf… uhgg!

Update: This turns out to be done by xrandr which the server hands off to now for dynamic use of monitors. man xrandr even reports that it is trying to keepaconstant DPI. Not sure just why it is doing it, but found a good way to get it done.

I just got a new monitor to be able to use as an external monitor for my laptop. While I was setting it up I noticed that the monitors display size wasn’t correctly detected. The Xorg server does a good job auto-configuring however this caught my eye:

xdpyinfo | grep -B2 resolution
dimensions:    1920x1080 pixels (508x286 millimeters)
resolution:    96x96 dots per inch

The monitor I got is a 21.5″ monitor so I figured the DPI was off. I decided to calculate it myself (this is a square pixel monitor):

res_diag=$(echo "scale=5;sqrt($res_horz^2+$res_vert^2)" | bc)
siz_horz=$(echo "scale=5;($siz_diag/$res_diag)*$res_horz*25.4" | bc)
siz_vert=$(echo "scale=5;($siz_diag/$res_diag)*$res_vert*25.4" | bc)
echo "$siz_horz"x"$siz_vert"

Also there are online DPI Calculators conferred by doubt (1, 2,) and xrandr:

em_ds_h=$(xrandr | grep VGA-0 | rev | cut -d " " -f 3 | rev | sed 's/mm//')
em_ds_v=$(xrandr | grep VGA-0 | rev | cut -d " " -f 1 | rev | sed 's/mm//')
echo $em_ds

My discovered value and theirs are a couple millimeters off overall so I just used theirs. I created a configuration to define the display size to the the Xorg server. A basic configuration to define display size can be done like this:

cat /usr/share/X11/xorg.conf.d/90-monitor-disp-size.conf
Section "Monitor"
  Identifier "<default monitor>"
  DisplaySize 477 268

Ubuntu uses /usr/share/X11/xorg.conf.d/ Arch Linux and some other use /etc/X11/xorg.conf.d/ (better choice I think). However this won’t work on the external monitor. So I expanded on it (more than it probably needed to be) by defining both monitors and related sections:

Section "Monitor"
  Identifier    "Internal - Pavilion Laptop"
  DisplaySize    304.5 228.6

Section "Monitor"
  Identifier    "External - Samsung Syncmaster SA350"
  VendorName    "Samsung"
  ModelName     "SA300/SA350"
  DisplaySize    476 267.7

Section "Device"
  Identifier    "ATI Radeon Mobility IGP 330M"
  Option        "Monitor-VGA-0"  "External - Samsung Syncmaster SA350"
  Option        "Monitor-LVDS"   "Internal - Pavilion Laptop"

Section "Screen"
  Identifier    "Default Screen"
  Monitor       "Internal - Pavilion Laptop"

Section "ServerLayout"
  Identifier    "Default Layout"
  Screen        "Default Screen"

I added VendorName and ModelName but I’m not sure they uniquely define the monitor so that the Xorg server acknowledges them. The VendorName I believe is just for reference, ModelName can usually be discovered by doing:

grep "Monitor name" /var/log/Xorg.0.log

Monitor-VGA-0 and Monitor-LVDS define the ports and hence by reference should uniquely define the monitor (xrandr -q shows them and both are found in the Xorg log).

After a bit of research I discovered that there is a good amount of history concerning the Xorg server having a bit of trouble in not being able to correctly discover the display size. I believe this may be related to some drivers. I’ve been told the open-source ATI driver have had problems and read in some other places of other people who have had similar issues. Defining the display size in the configuration and telling the Xorg server not to use the auto-detected value can be done by adding this to the Devices section (for Nvidia drivers use: Option "UseEDID" "FALSE"):

 Option        "NoDDC"

Unfortunately, this didn’t work either and left me completely at a loss. Unsure how to go further to define display size in the the Xorg server configuration I decided to define it through xrandr.

xrandr has an option to define the display size with the --fbmm option:

xrandr --output VGA-0 --auto -fbmm 476x267.7

--auto uses the default/preferred mode of the monitor.

A Journey of Fidelity (As Luck Has It)

A few weeks ago, my monitor kept blanking out on me. I’d been having a couple troubles with X crashes so I attributed them to that. I had been wanting to change my partitioning scheme so I decided to just re-install and use the older version for awhile (thinking the problem came after an update). So I installed Windows, then started Parted Magic’s Gparted to resize the NTFS partition only to get 22 Unaccounted Clusters errors. ‘ntfsresize‘ (which GParted uses) does a filesystem integrity check before resizing I found out. Thinking that Windows must not have unmounted the disk cleanly on shutdown, I rebooted and forced a filesystem check… no errors. When I went back and tried again, I got the same problem. I learned that there are different versions of the NTFS filesystem so I reinstalled Windows again and let the Windows installer format the partition instead of Gparted which I had done previously. When I went to resize again, I got the same problem. Here I eventually came to the conclusion that very possibly my hard drive was failing on me. This threw me off because my drive was only a year and a half old and because it was a Western Digital. Nonetheless, I had to check. So I ran a S.M.A.R.T conveyance test and then an extended test. Both tests passed. I knew (…Ughh!) that I’d have to run a ‘badblocks‘ test. I ran a non-destructive test (… long wait here) and discovered I had 44 bad sectors on my hard drive. I checked the Western Digital website (who had a very nice warranty check/RMA program) and thankfully my drive was still under warranty. I got a replacement drive (in only two days!!), did tests this time, and installed Windows again. When I went to resize… uggggh, I got the same problem again. At this point, I got out an older version of Parted Magic (6.3) and everything worked… perfectly.

Through all this the fun part was my monitor which kept blanking out on me (its just getting old) and was only able to read the screen for about a minute at a time.

I got a new monitor now too and am doing good again. It turns out that ‘ntfsresize‘ had a bug in it. I’m not sure what version of ‘ntfsresize‘ had the bug but it’s also on the Ubuntu 11.10 install disk. I upgraded to Parted Magic 11-11-11 and was able to resize my NTFS partition.

On this journey I learned is to never buy a a new drive and not test it, que sera sera. Because of this, I wrote badblocks page on the Arch Wiki for reference.

A Beautiful fstab

I know what partitions I have and like to know what is mounted and where. To do this, I keep a tidy static filesystem file (/etc/fstab).

I use labels instead of UUID’s just because they look nicer, but also because this allows me to resize them if need be. It’s hard to go wrong with UUID’s but since I know I likely won’t be putting a USB drive named ‘Windows’ or ‘Ubuntu’ in the USB port, I’m likely pretty safe. You may have noticed too that I choose not let HAL/DBUS (is it dbus that does mounting now?) handle my Windows and Storage partitions. I choose to do this for several reasons. One is because when I copy files I almost always find it much quicker from the command line (i.e. cp file1 file2 ... /mnt/Storage/backups/) rather than navigate through multiple directories in the file browser. The second reason is for security because sensitive data I don’t always want available. The third is to protect the Windows partition. If a crash were to happen, I find it a good inconvenience to have to boot Windows to be able to fix the NTFS volume.

Here it is:

# /etc/fstab: static file system information
# <file system>          <dir>        <type>  <options>           <dump/pass>
# Temporary file systems:
tmpfs                    /tmp         tmpfs   nodev,nosuid                0 0

# Internal hard disk (sda[2,3,5,6,7]): 
LABEL=SYSTEM\040RESERVED /mnt/SR      ntfs-3g noatime,noauto,user         0 0
LABEL=ACER               /mnt/Windows ntfs-3g noatime,noauto,user         0 0
LABEL=Arch               /            ext4    errors=remount-ro,noatime   0 1
LABEL=Home               /home        ext4    noatime                     0 2
LABEL=Swap               swap         none    defaults                    0 0

# External hard disk (sdb1)
LABEL=Backup             /mnt/Backup  ext4    noatime,noauto,user         0 3

noatime has been applied to save disk writes and unnecessary timestamps everytime the file is accessed, and the user option allows me to mount without superuser privileges. For the Windows partition to be able mounted as a regular user, the NTFS-3G driver will need to be compiled with internal FUSE support.

Mounting a Windows NTFS Partition as a Regular User (Ubuntu)

To be able to mount a Windows NTFS partition in Linux as a regular user (e.g. mount /dev/sda1 /mnt/Windows), rebuilding the driver with internal FUSE (Filesystem in USErspace) support is required, and then setting correct permissions is needed.

Download and Compile

First setting a couple variables eases the process:

blddir=~/Downloads/build      # A good place to do compiling
pkgname=ntfs-3g               # The package/driver name

Here the package version variables defined to match the actual extracted package source namings (why 1: gets prepended and 2ubuntu3 gets appended I’m unsure of):

pkgname_ver=$(dpkg -l | grep ^[i,h]i | awk '{print $2"_"$3}' | grep $pkgname | sed 's/1://')
PKGNAME_VER=$(echo $pkgname_ver | sed 's/\(.*\)-.*/\1/')

Note: Theoretically this should not be needed if you use udisks2. Unfortunately it looks like no one has found out how to use udiskctl yet.

Install the compiling (building) programs and then packages need to build ntfs-3g:

sudo apt-get install build-essential fakeroot dpkg-dev lynx devscripts
sudo apt-get build-dep $pkgname

Create the building directories and change to it’s directory:

[ ! -d "$blddir" ] && mkdir -p "$blddir"
cd "$blddir"
[ ! -d "$pkgname" ] && mkdir "$pkgname"
cd "$pkgname"

Download the source code (which gets extracted after downloading):

apt-get source "$pkgname"

The source code is oddly owned by root, to make it editable change it’s permissions:

sudo chown -R username:username .

Entering the source code directory (required to build):


Change the FUSE option to internal, comment the change, then compile:

sed -i 's/--with-fuse=external/--with-fuse=internal/g' debian/rules
dch -i "Changed fuse option to internal in configuration rules"
dpkg-buildpackage -rfakeroot -b

Replace the current NTFS-3G driver with the one just compiled with internal FUSE support:

sudo gdebi ntfs-3g_2011.4.12AR.4-2ubuntu3_i386.deb

And hold (freeze) the package so it doesn’t get updated with a new version on a system update:

echo ntfs-3g hold | sudo dpkg --set-selections

The driver will need to be set to setuid-root (there are risks doing this, read this for more information):

sudo chown root $(which ntfs-3g)
sudo chmod 4755 $(which ntfs-3g)

Finally, give the user the ability to be able to mount volumes:

sudo gpasswd -a username disk

Reboot to have the new driver loaded and the user to be put in the disk group.


The fstab will need to have the right options to be able to mount as a regular user. In my next post, I’ll show what my fstab looks like.

Bug Fix

I had a problem with gcc-4.6_4.6.1 on my install. It would error out at the beginning of a compile. The workaround for me was to use an earlier version of GCC and then define it when compiling:

sudo apt-get install gcc-4.4
CC=gcc-4.4 dpkg-buildpackage -rfakeroot -b


Storing login/password Websites in a File

I find that it is a good idea to update my Internet passwords from time to time. Previously to do so, I opened Firefox’s Preferences window and then went to the Saved Passwords window. From here, I’d toggle between Firefox and the Saved Passwords window, goto the sites that were listed, and change the password.

After doing this, I decided it would be quicker if I just had them in a text file. In the text file once I had updated the password on the website, I’d comment the line so I’d know I had done so.

For text editing, I commonly use Vim and it works great for this.

The nice thing about working in the terminal too is that once the text file is opened the webpages can be opened by Ctrl clicking on them.

I created a three of scripts to help the process: one to edit the list, one to generate the password, and one to copy the password to the clipboard.

 sitepass-ls   - list of programs/sites using common pw
  a | add   - add entry to list
  e | edit  - edit list
  s | sort  - sort list alphabetically
  u | uncom - uncomment list for new password
 sitepass-gn  - generate password for common use and other use.
  c | common - generate common password
  o | other  - generate other  password
 sitepass-cb  - copy common, other, and previous passwords to clipb.
  c  | common  - copy common
  o  | other   - copy other
  cp | comprv  - copy previous common
  op | othprv  - copy previous other
  x  | clear   - clear contents of clipboard

Here are the scripts:




Swap File for Suspend

Warning: I have not found this method to be unreliable; therefore, I have reverted back to using a swap partition.

I decided not to clutter my partitioning scheme anymore with a swap partition so from now on I’m using a swap file instead. This shows how to do use a create and use swap file during installation.

Create the Swap File

Boot the install disk and load Linux (for Ubuntu use the ‘Try Ubuntu’ to get to a functioning environment). Partition now (if required, GParted recommended) as it is generally easier than using the installer partitioner. When partitioning is done open the terminal so the swap file can be created.

You’ll need the kernel-defined root partition name (if you don’t already know it):

sudo fdisk -l | grep ^/dev

To simplify tasks define the root partition as a variable. For example, if your root partition is sda2:


Create the mount point and mount the partition:

sudo mkdir /mnt/$root_part && sudo mount /dev/$root_part /mnt/$root_part

Create the swap file (this is created before doing the install so it’s at the beginning of the partition) by doing:

fallocate -l 1G /mnt/$root_part/swapfile  # G = Gigabyte, M = Megabyte
chmod 600 /mnt/$root_part/swapfile
mkswap /mnt/$root_part/swapfile

Unmount, then install your system:

umount /mnt/$root_part

Install your System

Install as normal. With the installer, define the partition(s) to the desired mount point (for example, sda2 to be / (root), sda3 to be /home?,…).

List the Swap File

After the install has completed, the swap file information will need to be listed in the static filesystem configuration file (fstab).

To do this, the partition will likely need to be mounted again:

sudo mount /dev/$root_part /mnt/$root_part

Add the swap file to root partition fstab file using the editor of choice (for example: gksudo gedit /mnt/$root_part/etc/fstab) and adding:

/swapfile none swap defaults 0 0

Define the Kernel Options

After the install has completed, the swap file location will need to be defined as a kernel option to the bootloader.

Change apparent root (to be able to update the bootloader later):

for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$root_part$i; done
chroot /bin/bash /mnt/$root_part

Get root parition UUID (partition Unique IDentifier):


Get the swap file first block physical location on the partition by running the command (the value needed is given on the first row of the ‘physical’ column):

filefrag -v /swapfile

The bootloader will need the kernel options defining the swap file partition UUID and first block physical location of the swap file (resume_offset) in this form:

resume=UUID=the-root-partition-UUID resume_offset=the-swap-file-physical-address

These will need to be added to the configuration file. For the original GRUB (GRUB Legacy), edit /boot/grub/menu.lst and add to the kernel line the above kernel options. For GRUB2, edit /etc/default/grub and add the kernel options to the GRUB_CMDLINE_LINUX_DEFAULT="..." line, then:


Also the initial ram filesystem (basically a device/software loader for items that need initialized during kernel boot) may need this information as well. For Ubuntu, define the kernel options by doing:

echo "resume=UUID=the-root-partition-UUID resume_offset=the-swap-file-physical-address" | sudo tee /etc/initramfs-tools/conf.d/resume
sudo update-initramfs -u

Exit chroot, unmount, and reboot to new system:

for i in /sys /proc /dev/pts /dev; do sudo umount /mnt$root_part$i; done
umount /mnt/$root_part

Test now if hibernation works. If it doesn’t you can try to add and switch to the ‘userspace’ suspend framework instead.

Userspace Suspend/Hibernation

uswsusp is a rewrite of the kernel suspend framework for use as a ‘userspace’ tool. It generally has better support for suspending to a swap file so using it here is generally necessary.

Reboot into the new operating system and install uswsusp.

Ubuntu pre-configures uswsusp (defines the root partition, gets the swap file size, runs sudo swap-offset /swapfile, places these values in the configuration file /etc/uswsusp.conf, then creates a new initramfs) so all that needed to do is install it. Other distributions may need to configure it. Once installed and configured, reboot again and test.


Converting Ext4 to JFS

Because I have an older laptop and disk I/O can really bottleneck on the motherboard, I decided to move from the ext4 filesystem to JFS. Recently, I’ve used ext4 because it was fairly fast and definitely reliable; however, with the kernel moving to 2.6.30 new data integrity features have been added that slow it fairly noticeable on an eight year old computer. Moving to JFS has made a fair difference in improving the speed of the system, it’s caveat being that it that journals only metadata (not metadata and data like ext3/4)).

Backup, Convert, Restore

The JFS filesystem utilities will be needed (for Debian/Ubuntu):

sudo apt-get install jfsutils

Reboot to a rescue CD, and backup partition(s)/disks onto another drive. For this example two partitions are used: one for root, one for home. Mount root, home, and then the backup drive:

mkdir /mnt/{,,}
mount /dev/ /mnt/
mount /dev/ /mnt/
mount /dev/ /mnt/

Create the backup directories:

mkdir -p /mnt//backup-rsync/{root,home}

Backup both partitions:

rsync -axS /mnt// /mnt//backup-rsync/root
rsync -axS /mnt// /mnt//backup-rsync/home

Check integrity of backup, then create a JFS filesystem on both partitions:

mkfs.jfs /dev/
mkfs.jfs /dev/

Restore the backup contents back to the root and home partitions; first method:

rsync -axS /mnt//backup-rsync/root/ /mnt/
rsync -axS /mnt//backup-rsync/home/ /mnt/

Or this method to be sure files are defragmented (JFS is somewhat prone to fragmentation, heavy use may require occasional defragmenting):

(cd /mnt//backup-rsync/root/ && tar -cS -b8 --one -f - .) | (cd /mnt/ && tar -xS -b8 -p -f -)
(cd /mnt//backup-rsync/home/ && tar -cS -b8 --one -f - .) | (cd /mnt/ && tar -xS -b8 -p -f -)

Updating the System

The system needs to know of the filesystem changes. Changing apparent root from the rescue CD to the current Linux install is done by:

cd /mnt/
mount -t proc proc proc/
mount -t sysfs sys sys/
mount -o bind /dev dev/
chroot . /bin/bash

Update the chrooted system current mounts file:

grep -v rootfs /proc/mounts > /etc/mtab

The fstab file (the static filesystem configuration) needs to be updated. The information that will need adjusting is: the UUID (possibly), the filesystem type, and options. The UUID’s (unique disk identifiers) may have changed, they can be appended onto the fstab file (so that they can be easily moved) like this:

blkid /dev/ | cut -d "\"" -f 4 >> /etc/fstab
blkid /dev/ | cut -d "\"" -f 4 >> /etc/fstab

Edited /etc/fstab with set UUID, type, and options:

# /dev/sda2
UUID=5d9753dd-f45f-425a-85e2-25746897fdfa / jfs   noatime,errors=remount-ro 0 1
# /dev/sda4
UUID=d3f9eafd-1117-4c75-a309-b21dece655d1 /home jfs noatime                 0 2

noatime lessens disk writes by not creating a timestamp every time a file is accessed (it isn’t seen as very useful anymore since it was developed primarily for servers with statistics in mind).

JFS supposedly works very well with the Deadline Scheduler; the Grub configuration need to specify to use it. This example is for Grub2 though it is similar with original Grub; edit /etc/default/grub and append:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash elevator=deadline"

The other Grub configurations need to be updated with the new information:


Then the Grub bootloader will have to be re-installed to the MBR (I think this is because the version of Grub put on the MBR has directions on how to be able to find its configurations for a specific filesystem).

grub-install /dev/  # Disk here is more likely and not partition

Exit the chroot and unmount temporary filesystems:

umount {proc,sys,dev}



Get every new post delivered to your Inbox.

Join 58 other followers