Override DSDT to fix Toshiba Battery Status

When I installed Debian on my new laptop earlier this year, I was impressed by how easy it was to set everything up. However, I had to cope with a nagging bug: My system couldn’t recognize the battery, so I had no idea how much time I had before running out of power. It turns out that sloppy Windows programmers at Toshiba shipped my Satellite L640 laptop with broken firmware that had to be fixed before the Linux kernel would recognize my battery.

It is necessary to recompile Linux to override the DSDT file. A succession of clumsy mistakes made this a miserably drawn-out process for me, but when it’s done correctly it’s reasonably simple. Following are the steps I took to override the DSDT on my 64-bit system running Debian GNU/Linux 6.0.2 (squeeze).

Step 1: Fix the DSDT File

See this helpful article for more details: http://techinterplay.com/fix-toshiba-battery-issue-linux.html.

Get the original DSDT from the machine:

$ sudo cat /sys/firmware/acpi/tables/DSDT > dsdt.dat

Disassemble it, installing the package iasl if necessary:

$ iasl -d dsdt.dat

Using your favorite editor (mine’s Vim), open up the newly-created dsdt.dsl and replace the line

OperationRegion (EMEM, SystemMemory, 0xFF808001, 0xFF)

with

OperationRegion (EMEM, EmbeddedControl, 0×00, 0xFF)

Save as dsdt-fixed.dsl and exit. Now reassemble:

$ iasl -tc dsdt-fixed.dsl

This creates the file dsdt-fixed.hex which we will compile into the kernel. You can ignore the errors and put the file somewhere in your /home directory for safe keeping (e.g., /home/user/src/dsdt/).

I made the mistake of saving it under /root even though I was running make as me. Wasting hours compiling only to find it didn’t work is no fun, so don’t do that. Don’t put it in the kernel include/ directory either because, on my system anyways, it won’t compile at all.

Step 2: Compile Linux with Custom DSDT

I had never compiled Linux before, so I followed the steps at the Debian wiki: http://wiki.debian.org/OverridingDSDT.

You may need to install build dependencies:

$ sudo aptitude install fakeroot build-essential devscripts
$ sudo aptitude build-dep linux-2.6

Find out what kernel you’re running and download its source to a convenient folder (e.g., /home/user/src/):

$ uname -r
2.6.32.5-amd64
$ cd src/
$ apt-get source linux-image-2.6.32-5-amd64
$ cd linux-2.6-2.6.32/

Note: If you have additional repositories such as squeeze-backports, make sure that you’re not downloading a different kernel source by temporarily commenting the relevant deb-src line out of /etc/apt/sources.list and updating apt. The squeeze-backports kernel, 2.6.39, will build, but I had some networking problems with it.

Add a comment to the changelog (e.g., “Custom dsdt”):

$ dch --local +dsdt

Edit debian/config/defines and append an identifier (e.g., “dsdt”) to the value of abi.abiname. This will be added to the name of the new kernel package. Then do this:

$ make -f debian/rules source-all
$ fakeroot make -f debian/rules.gen setup_amd64_none_amd64

Edit the file debian/build/build_amd64_none_amd64/.config so that it contains the lines:

CONFIG_STANDALONE=n
CONFIG_ACPI_CUSTOM_DSDT=y
CONFIG_ACPI_CUSTOM_DSDT_FILE="/home/user/src/dsdt/dsdt-fixed.hex"

Finally, it is time to compile the kernel. Set the “DEBIAN_KERNEL_JOBS” option to the number of CPUs on your machine to help speed things up; it will still take forever, so be patient:

$ time fakeroot make -f debian/rules.gen binary-arch_amd64 binary-indep DEBIAN_KERNEL_JOBS=4

This took almost three hours on my 2.67GHz processor:

real	164m18.577s
user	408m31.336s
sys	45m18.594s

Note: Running this command directly from the console saves a little time—about 15 minutes on my machine—when compiling. Log out of your desktop, go to tty1 (Ctrl+Alt+F1), log in, and kill your display manager (e.g., $ sudo killall gdm3). After you’ve run the command above in your source directory and generated the kernel image, start X up again (e.g., $ sudo gdm3 start) and log back in.

Note: Actually, it’s probably easier just to run it in a SCREEN session that you can attach or detach from as desired.

If you know what you’re doing (I don’t), you can considerably cut compile time by customizing the kernel yourself and removing extraneous drivers and such.

If all goes well, src/ should be filled with .deb files, including our new kernel image. Install it with dpkg (as root):

$ sudo dpkg -i linux-image-2.6.32-5-dsdt-amd64_2.6.32-35+dsdt1_amd64.deb

Reboot, and Linux will (hopefully) recognize your battery!

$ acpi -V
Battery 0: Discharging, 32%, 01:11:16 remaining
Battery 0: design capacity 5600 mAh, last full capacity 5188 mAh = 92%
Adapter 0: off-line

If you have custom modules, you need to compile them too—so see the wiki on that. Until the Linux developers add a workaround upstream, this process will be necessary whenever you upgrade to a new kernel.

Note: After installing virtualbox I regretted not keeping all of the .deb files I made. In order to compile custom modules (like vboxdrv), you also need to install the linux headers for your new kernel:

$ sudo dpkg -i linux-headers-2.6.32-5-dsdt-amd64_2.6.32-35+dsdt1_amd64.deb \
linux-headers-2.6.32-5-dsdt-common_2.6.32-35+dsdt1_amd64.deb

Keep backups of these files if you think you might need them, otherwise you’ll have to compile again like I did.

Posted in Unix, Linux, and GNU | Tagged , , , , , , | 8 Comments

Download Audio from .m3u Playlist

If you found an .m3u streaming playlist online that you would like to save for offline use (e.g., a concert from the Grateful Dead collection at Archive.org), you can download all files with a simple shell command:

$ cat playlist.m3u | xargs wget
Posted in Unix, Linux, and GNU | Leave a comment

How to Set Up an Encrypted External Hard Drive

When it comes to protecting digital information, encryption is not optional; likewise, when it comes to preserving digital information, making backups is not optional. Happily, it is a breeze to do both with free software. Here are the steps I followed to set up an external hard drive with full-disk encryption (dm-crypt/LUKS) on my Debian GNU/Linux system.

Before You Begin

Doing this irrecoverably destroys all the data on the chosen drive, so proceed with care. Read the man pages to learn more about each command and how to modify them to suit your needs. Note, although it would be silly to make encrypted backups of unencrypted data, this process will work whether or not the data on the machine is itself encrypted.

0: Overwrite External Drive

Make sure you have backed up everything you want to keep, because after overwriting the drive you won’t be getting it back.

Once your external hdd is plugged in, use fdisk and mount to see what it’s called and whether or not it’s mounted. You should see something like this:

$ sudo fdisk -l

...

Disk /dev/sdc: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5c74ae42

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       30401   244196001    c  W95 FAT32 (LBA)

My 250GB external drive is /dev/sdc, so I will use this path throughout the post. Modify the path in your commands as necessary. Make sure any filesystems on the device are unmounted and we’re ready to nuke it.

Filling the disk with random data accomplishes two things: First, it irrecoverably deletes any data on the drive. Second, it helps hide the fact that encryption is being used and makes it more difficult for an attacker to determine where the encrypted data ends and where the random data begins. There are many tools to choose from, in particular shred, wipe, dd, and badblocks. Consult the Internet and the man pages for specifics on these commands. I chose to use badblocks:

# badblocks -c 10240 -swt random -v /dev/sdc

I’m sure this made the drive reasonably random, but the previous three commands are better suited to higher-security erasure. The trade-off is that they may take a lot more time. badblocks itself took several hours to overwrite my 250GB hdd. Use your best judgment.

1: Partition the Disk

Now that there is nothing but noise on the drive, we can create a new partition. Use fdisk as root to set up the partition table (use gparted if you prefer a GUI).

# fdisk /dev/sdc

The commands you will need in fdisk include:
p – print partition table
n – create new partition
q – quit without saving
w – write new partition table and exit

You should now have a partition called something like /dev/sdc1. Once you have partitioned the disk, it is time to set up encryption.

2. Encrypting the Disk

Initialize the LUKS partition and set its password:

# cryptsetup --verbose --verify-passphrase luksFormat /dev/sdc1

This will ask for a password and set up the encrypted volume.

Now you may use your password to open the device:

# cryptsetup luksOpen /dev/sdc1 sdc

3. Create Filesystem

At this point, the hdd is connected and it will behave like any other disk. You need to create a filesystem before you can use it. I chose ext4, but there are naturally other options:

# mkfs.ext4 -j /dev/mapper/sdc

If all went well, you may mount the new filesystem and use it like any other:

# mount /dev/mapper/sdc /media/mountpoint

To close the disk, unmount the filesystem and disconnect from LUKS:

# umount /media/mountpoint
# cryptsetup luksClose sdc

Using the Encrypted Drive

Disconnect the USB plug and then plug it back in: I was pleasantly surprised by a user-friendly password prompt from GNOME that takes care of the rest:

User-friendly password prompt in GNOME

Now you may backup data to your external drive knowing that your files are secure. I used rsync to backup my /home directory, but the possibilities are endless.

References

I collected most of these steps from the wiki at infectedtech.org.

Posted in Unix, Linux, and GNU | Tagged , , , | Leave a comment

taylor`s website

I’m Taylor and this is my website. There isn’t much here and I can’t promise that there ever will be, but I see myself posting some reflections and computing tips sooner or later.

Until then, peace~

Posted in Uncategorized | Leave a comment