Amazon Kindle

From Gentoo Wiki
Jump to: navigation, search
Resources

A quick document explaining how to use the Amazon Kindle with Gentoo.

Kernel

To be able to mount your Kindle as an external storage device, you require the VFAT file system as well as support for DOS partition tables in your kernel.

KERNEL Enabling File System Options
File Systems  --->
   DOS/FAT/NT Filesystems  --->
       [*] VFAT (Windows-95) fs support
Enable the block layer  --->
   Partition Types  --->
       [*] PC BIOS (MSDOS partition tables) support

Kindle DX / DX Graphite

Mounting the Removable Storage Media

Mounting using AutoFS

Execute blkid (sys-apps/util-linux) with the Kindle device attached.

root #blkid

Find the UUID from the blkid output and insert the following line into your /etc/autofs/auto.misc file, substituting UUID with your UUID:

FILE /etc/autofs/auto.misc
kindle    -fstype=vfat,gid=100,noatime,rw,umask=002,user,utf8    UUID="Your_UUID_from_blkid_Output"

Edit the /etc/conf.d/autofs file to your liking. Make sure you uncomment the MASTER_MAP_NAME="auto.master" line if you use the /etc/autofs/auto.master file!

The following addition to the auto.master file can be used. The --ghost option auto-unmounts after five seconds:

FILE 1/etc/autofs/auto.master
/mnt/auto   /etc/autofs/auto.misc   --timeout=5 --ghost

Mounting using udev

The following udev rule will mount your Kindle using the Volume Name (ie. "Kindle") to (/media/Kindle). You then will need to execute the user scripts add.sh and remove.sh to tell the udev to add (mount) and remove (unmount) the device. In turn, the /media/Kindle folder is automagically created and destroyed on mount and unmount.

FILE /etc/udev/rules.d/11-media-by-label-auto-mount.rules
SUBSYSTEM!="usb", KERNEL!="sd[c-z][0-9]", GOTO="media_by_label_auto_mount_end"

# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"

# Get a label if present, otherwise specify one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"

# Global mount options
#ACTION=="add", ENV{mount_options}="relatime"
ACTION=="add", ENV{mount_options}="noatime"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"

# Mount the device
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"

# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"

# Exit
LABEL="media_by_label_auto_mount_end"
FILE /home/user/bin/udev-add-all.sh
#!/bin/bash - 
#===============================================================================
#
#          FILE:  udev-add.sh
# 
#         USAGE:  ./udev-add.sh 
# 
#   DESCRIPTION: udev add removable media device 
# 
#        AUTHOR: Roger Zauner (rdz), rogerx (dot) oss (at) gmail (dot) com
#       CREATED: 04/10/2010 12:18:57 AM AKDT
#===============================================================================

set -o nounset                              # Treat unset variables as an error
#set -o xtrace                              # Enable trace debugging

# sd[b-z][0-9]
#udevadm trigger --action="add" --sysname-match="sdb1" --verbose

if [ $HOSTNAME = "localhost1.local" ]; then
    sudo /sbin/udevadm trigger --action="add" \
      --sysname-match="sd[c-z][0-9]" --verbose
#    sudo /sbin/udevadm trigger --action="add" \
#      --sysname-match="sr[0-9]" --verbose
  
  elif [ $HOSTNAME = "localhost2.local" ]; then
    sudo /sbin/udevadm trigger --action="add" \
      --sysname-match="sd[c-z][0-9]" --verbose
#    sudo /sbin/udevadm trigger --action="add" \
#      --sysname-match="sr[0-9]" --verbose
  
  elif [ $HOSTNAME = "localhost3.local" ]; then
    sudo /sbin/udevadm trigger --action="add" \
      --sysname-match="sd[b-z][0-9]" --verbose
#    sudo /sbin/udevadm trigger --action="add" \
#      --sysname-match="sr[0-9]" --verbose
fi
FILE /home/user/bin/udev-remove.sh
#!/bin/bash - 
#===============================================================================
#
#          FILE:  udev-remove.sh
# 
#         USAGE:  ./udev-remove.sh 
# 
#   DESCRIPTION: udev remove removable media device 
# 
#        AUTHOR: Roger Zauner (rdz), rogerx (dot) oss (at) gmail (dot) com
#       CREATED: 04/10/2010 12:22:17 AM AKDT
#===============================================================================

set -o nounset                              # Treat unset variables as an error
#set -o xtrace                              # Enable trace debugging

# sd[b-z][0-9]
#udevadm trigger --action="remove" --sysname-match="sdb1" --verbose

if [ $HOSTNAME = "localhost1.local" ]; then
    sudo /sbin/udevadm trigger --action="remove" \
      --sysname-match="sd[c-z][0-9]" --verbose
#    sudo /sbin/udevadm trigger --action="remove" \
#      --sysname-match="sr[0-9]" --verbose
  
  elif [ $HOSTNAME = "localhost2.local" ]; then
    sudo /sbin/udevadm trigger --action="remove" \
      --sysname-match="sd[c-z][0-9]" --verbose
#    sudo /sbin/udevadm trigger --action="remove" \
#      --sysname-match="sr[0-9]" --verbose

  elif [ $HOSTNAME = "localhost3.local" ]; then
    sudo /sbin/udevadm trigger --action="remove" \
      --sysname-match="sd[b-z][0-9]" --verbose
#    sudo /sbin/udevadm trigger --action="remove" \
#      --sysname-match="sr[0-9]" --verbose
fi

The AutoFS method may be preferred, as it's cleaner and doesn't need running the above user scripts. The main problem with the Kindle DX seems to be the DX's display stating the device is plugged in. Even though this is true, you can still unplug the device without using the eject command and the device is not mounted! And, using the eject command at times would confuse the device and the Linux sub-system at times. So, just unplug the device after checking the device is no longer mounted via the mount command. As such, much easier to just use AutoFS, as it can be configured to auto unmount it for you using the --ghost option.

File Format Conversions

Simple utilities for converting documents can be used, as shown below.

PDF File Format

Best format to read technical documents is PDF.

  • You can create PDF's easily from printing them from Seamonkey or Firefox using the print to file method.
  • Use ps2pdf utilities (app-text/ghostscript-gpl)

MOBI File Format

The basis of this file format is HTML, but with the feature of DRM when required by publishers. Keep it simple, avoiding TABLE tag usage. (See Amazon's AmazonKindlePublishingGuidelines.pdf.)

Use Vim to convert a ASCII/UTF8 text file to HTML. Execute Vim's ":ToHtml" command and save, then use Amazon's kindlegen binary on the saved file. (KindleGen is Amazon's version of MobiGen.)

Tips

  • When possible, copy both the MOBI and PDF file formats to the device as both currently have separate pros and cons (e.g. O'Reilly publishes books into a multitude of formats).
  • Because there are so many files freely available, create subfolders within the /mnt/kindle/documents folder even though the Kindle DX Graphite firmware doesn't display the folders, but will see the files within the folders. Then use the Kindle firmware to create a "Collection" with a similar name to the folders (e.g. Filesystem folder name /mnt/kindle/documents/programming-c, Collection Name "Programming - C").

Free Books

  • Gentoo Wiki articles can be printed to either PDF or HTML using the "Printable version" link, located to the bottom left within the "toolbox" of the viewable version of pages.
  • Many C Programming books, specifications and manuals are already freely available in PDF format (e.g. C on Freenode lists many freely available recommended books).
  • Many FSF GNU Manuals are also already available in HTML and PDF formats.
  • Manual Pages (AKA manpages) can be easily converted to HTML, then MOBI using KindleGen (see references below).
  • TLDP hosts many HowTo's and documents in PDF and HTML formats.
  • Python hosts its documentation in PDF, HTML and EPUB formats.

Mobile Linux Websites

See also

  • AutoFS — a program that uses the Linux kernel automounter to automatically mount filesystems on demand.

External resources