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 X.org 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_horz=1920
res_vert=1080
res_diag=$(echo "scale=5;sqrt($res_horz^2+$res_vert^2)" | bc)
siz_diag=21.5
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"
475.48800x267.46200

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//')
em_ds="$em_ds_h"x"$em_ds_v"
echo $em_ds
477x268

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
EndSection

Arch Linux and most distros use /etc/X11/xorg.conf.d/. 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
EndSection

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

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

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

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

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 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 ‘DisrtoX’ 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.

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. Partition now . 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:

root_part=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):

blkid | grep /dev/STORAGE-DEVICE-ROOT-PARTITION

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:

update-grub

Also the initial ram filesystem (basically a device/software loader for items that need initialized during kernel boot) may need this information as well. 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:

exit
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.

Configure 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.

References

MPD locally

Recently I cleaned the Arch wiki of the MPD name some. MPD on the Arch wiki is a good source of information but it needed help: organization, some tech things, grammatically… but its holding together for now. It is wiser for me to use MPD locally (clean installs are still recommended over updates (just engineered that way)) and having a home partition simplifies things greatly. Anyways, I’ve added .desktop file information and a fix for PulseAudio too.

REO Speedwagon to Ario MPD-wagon

For my tastes I like my MP3 player to be responsive and light (MP3s aren’t incredibly resource intensive files to play) and that’s why I like MPD.

I just found this:

This is Ario, a MPD client I hadn’t heard of before. The flow is beautiful, very logical to me. Works great, gonna be using it for a Bit.

Missed Touchpad Button Clicks

I had gotten this laptop as a gift/hand-me-down from someone else. Since the first thing I did was install Linux, I hadn’t thought otherwise that the buttons hadn’t been treated to well: left-click was very stubborn, often missing on some very obvious pushes. The action/response of the button resembled a sticky button. Because right-click was better, I created a script that would switch/toggle left and right click. I toggled it twice to test it (so that it reverted back to the original) when and found that left-click was working normally. Not sure why this fixed the problem and have yet to see another problem like this but I’m glad it’s good again. I created a script to quickly do this then added .desktop file to have it load on Login. The script:

Then I created a desktop file touchpad-button-fix.desktop in ~/.config/autostart to start it on Login:

Additional, the touchpad button may revert to it’s original behavior after resuming from sleep. To run the script upon resume it will need to be defined to pm-utils. Put this in /etc/pm/sleep.d/90_touchpad-button-fix:

Then make them executable:

sudo chmod +x ~/.config/autostart/touchpad-button-fix.desktop
sudo chmod +x /etc/pm/sleep.d/90_touchpad-button-fix

A more desirable rm

Update: Added mv option -t and --backup=t (thanks to Matt) to prevent file collisions from same-named files. Thanks Matt! A bashrc version and a bash script are both available.
Warning: Currently I am not using this script. This script works good for most instances but I discovered it does have problems when compiling. During compiling some files get force removed (the rm -f, -fr, or -rf options) that it looks like mv will not do. When this happens files don’t get removed and compiling errors can occur. I am still trying to figure out how to do this.

I’ve deleted files before that I wish I could have back and resorted to file saving utilities to try and save them but I have never done this before:

rm -rf ~/ .Arachnophilia

I was doing a bit of spring (fall?) cleaning and as you may have guessed: the space between ~/ and .Arachnophilia was not intended. An accidental slip of the thumb caused this and yes, this had caused my computer to delete my whole home directory! I remembered a post I had read and quickly I did sudo init 1 to drop into single user mode. The post was for recovering a text file though and single user mode didn’t accept any input anyhow so I rebooted into my beloved install disk.

R! and R? (Request!! and Recover?)

Luckily I had back up several days ago. I wrote down the files I had been working on since then to try and recover. The Arch Wiki has a good page on this. I tried extundelete first and while its probably the best and most through way to recover all files, it recovers the files like this:

ls . | head -n 2
010392
010394

Since the files I’ve been working on were just text files and scripts, Photorec was a better application for this. Photorec is able to analyze and determine certain file types including text files and script files.

Afterward, I was left with directories and files that looked like recup_dir/f1029394.txt. 14000 and some text files if I remember right. To be able to find which one were the correct ones using grep is awesome. So quick too. I just had to be able to remember some text within the file and search for it like this:

grep -rn --include=*.txt "the text here" .

Using grep alone instead of combined it with some program like find is much quicker. The -r does a recursive search, the -n will print the line number, and --include specifies the file type in this case. Piping grep works good for more refined searches like searching for two patterns on a string or removing a string:

grep -rn --include=*.txt "the text here" . | grep -n "this too"
grep -rn --include=*.txt "the text here" . | grep -v "string not with this"

I found the files I needed, thankfully, and was able to get them back.

~/Never\ Again\?/

First thing I did after restoring from my backup was to see if I could prevent this again. The answer was pretty simple: move the files to the trash instead. By adding:

alias rm="mv -t ~/.local/share/Trash/files --backup=t --verbose"

to the ~/.bashrc files will get moved to the trash instead of deleted. The ~/.local/share/Trash/file is defined by the freedesktop.org organization so it has interoperability with and Gnome and other desktops. With the -t and --backup=t options mv will rename files with duplicate file names to ones with appended numbers (e.g. abc.~2~).

Here’s is a more detailed version in a bash script that includes feedback: