I talk about GNU/Linux, and stuff.
All websites that I control will be displaying a protest about SOPA instead of their usual content from 00:00 UTC+1 tonight until the same time tomorrow. There are a few WordPress plugins available to do the job, but most of my websites don’t use WordPress, so a better way is needed. I’ve put a simple htaccess and php script on my GitHub, which does the job nicely.
A while ago I ordered a PC for my mother from pcspecialist, a company I’ve ordered laptops from a few times and been pleased in each instance. I have tended to have them running Arch, but since this case would require my mother maintaining her own computer with little intervention (and she is not proficient with computers in general, never mind Linux), I decided to go with Debian. The installation was fine, but after entering GDM I noticed a problem — the display mode was completely wrong. Instead of using the intel driver, X would fall back to vesa and output in 1024×768. Trying to use intel resulted in “no devices detected”. This turns out to be because of lacking support for the graphics chipset in the current squeeze kernel provided by the linux-image-2.6-686 metapackage. I do not know at which point the driver for this chipset is included in the kernel, but at the present time an appropriate driver is in backports. Just enable backports in your sources if you haven’t already and issue aptitude -t squeeze-backports install linux-{image,headers}-2.6-686.
Working with a coworker this afternoon, I noticed him attempting to overwrite a USB flash disk with NULs using /dev/zero. After asking him about what he was hoping to achieve with this, he stated that he was attempting to securely erase the disk. It appears to be a common misconception that zero is the erase state for USB flash devices — in fact, one is the erase state. It seems like tr would be a potential candidate to solve this issue:
tr \\000 \\377 < /dev/zero > /dev/sdX
This is fine until you encounter the huge overhead from tr. On my AAO, it almost triples the time it takes to produce the same size of output (the use of cat here is necessary to make it a fair test, that is, that we include the pipeline both times):
$ time tr \\000 \\377 < /dev/zero | head -c 1000000000 > /dev/null real 0m12.396s user 0m10.243s sys 0m5.613s $ time cat /dev/zero | head -c 1000000000 > /dev/null real 0m4.506s user 0m0.777s sys 0m5.200s
Some C is probably the best method:
#include <string.h>
#include <unistd.h>
int main() {
char buf[4096];
memset((void *)&buf, '\377', sizeof(buf));
while(true)
write(1, buf, sizeof(buf));
}
$ time ./ones | head -c 1000000000 > /dev/null real 0m4.103s user 0m0.752s sys 0m5.003s
Here’s one with better error checking, but it is slower as a consequence:
#include <string.h>
#include <unistd.h>
int main() {
char buf[4096];
memset((void *)&buf, '\377', sizeof(buf));
while(write(1, buf, sizeof(buf)) == sizeof(buf));
return 1;
}
In a moment of boredom today, I decided to unify my PGP/SSH keys. You should do this all in a ramdisk or encrypted filesystem to avoid saving the unencrypted key to disk, I prefer to just do it in a completely clean environment — I use Tails. Here are the steps I took:
Firstly, we need to get monkeysphere, a suite of programs dedicated to increasing the reach of PGP. This suite contains a script called openpgp2ssh, which is what we will need to do the conversion. Annoyingly, it doesn’t understand how to decrypt a key and then reencrypt with the same information, so you have to do it manually.
Now, export your secret key.
key=2A7D4D74 gpg --export-secret-key "$key" > id_rsa.bak
This will mean that we can quickly reimport it once we’re done (as we have to remove the encryption and passphrase).
Now issue gpg --edit-key, run passwd, remove the password, and then quit, saving the changes. This will remove the encryption from your key.
Now convert the keys and store them in the standard files in ~/.ssh.
gpg --export "$key" | openpgp2ssh "$key" > ~/.ssh/id_rsa.pub gpg --export-secret-key "$key" | openpgp2ssh "$key" > ~/.ssh/id_rsa
We now change the password to the SSH secret key:
ssh-keygen -f ~/.ssh/id_rsa -p
Now reimport the original key (deletion is required or for some reason it fails to reimport as encrypted):
gpg --delete-secret-key "$key" gpg --import < id_rsa.bak rm id_rsa.bak
For the rare occasions that I need to use Windows for something (namely: to play videogames) I feel pretty lost without a tiled WM. After using dwm all these years, Windows’ native “click at stuff” method feels vastly inferior and imprecise. bug.n fills that gap, as a dwm-like tiling WM for Windows.
I’m mostly just noting this here to avoid the inevitability of forgetting what it’s called when I have to reinstall this terrible operating system.
It’s relatively convienient to have a file container for groups of files that you’d might move about. A few people were asking about this today on ##linux, so I figured I’d write a quick blog post on the concept and execution.
Firstly, let’s create the container. Have no delusions — LUKS does not provide plausible deniability by any means, however, for situations where that isn’t an issue, it is still a good idea to make it difficult for an attacker to determine where your encrypted data begins and ends. We can do this by filling the drive with garbage data from a (P)RNG, in this case, I will use /dev/urandom. You could also use /dev/random, but you will need to keep on giving it entropy to make it output at a decent rate.
dd if=/dev/urandom of=container bs=1M count=20
This will create a 20M container filled with PRNG output. Now, associate a loop device with the container.
losetup /dev/loop0 container
The container is now mounted on /dev/loop0, and can be addressed in a similar manner to any other block device. Now, let’s format the container using luksFormat. This will set up the container in such a way that LUKS can address it.
cryptsetup luksFormat /dev/loop0
Now enter a strong password for the volume. Once done, you can mount the LUKS volume by using luksOpen.
cryptsetup luksOpen /dev/loop0 container
This will decrypt/encrypt the data to and from the loop device by using the map device at /dev/mapper/container. At this point, the encrypted container still has no filesystem, so create one:
mkfs.ext4 /dev/mapper/container
Now you can mount this to any appropriate mountpoint.
mount /dev/mapper/container /mnt/container
To unmount the map device, unmap the map device from the loop device and disassociate the loopdevice from the container, issue the following commands:
umount /mnt/container cryptsetup luksClose /dev/mapper/container losetup -d /dev/loop0
So I just got this new machine thanks to my friend Ward, and it’s a real beauty. Very good quality, like it just came off the production line. So let’s get to it!
Here is lspci:
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 03) 00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 03) 00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 02) 00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01) 00:07.2 USB Controller: Intel Corporation 82371AB/EB/MB PIIX4 USB (rev 01) 00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03) 00:08.0 FireWire (IEEE 1394): Sony Corporation CXD3222 i.LINK Controller (rev 02) 00:09.0 Multimedia audio controller: Yamaha Corporation YMF-744B [DS-1S Audio Controller] (rev 02) 00:0a.0 Communication controller: Conexant Systems, Inc. HSF 56k Data/Fax Modem (Mob WorldW SmartDAA) (rev 01) 00:0c.0 CardBus bridge: Ricoh Co Ltd RL5c478 (rev 80) 00:0c.1 CardBus bridge: Ricoh Co Ltd RL5c478 (rev 80) 01:00.0 VGA compatible controller: ATI Technologies Inc Rage Mobility P/M AGP 2x (rev 64) 02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ (rev 10)
…here is /proc/cpuinfo:
processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 8 model name : Pentium III (Coppermine) stepping : 6 cpu MHz : 645.221 cache size : 256 KB fdiv_bug : no hlt_bug : no f00f_bug : no coma_bug : no fpu : yes fpu_exception : yes cpuid level : 2 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov pse36 mmx fxsr sse up bogomips : 1290.21 clflush size : 32 cache_alignment : 32 address sizes : 36 bits physical, 32 bits virtual power management:
…and finally here is /proc/meminfo:
MemTotal: 187792 kB MemFree: 58544 kB Buffers: 8256 kB Cached: 99548 kB SwapCached: 0 kB Active: 28848 kB Inactive: 82220 kB Active(anon): 3280 kB Inactive(anon): 108 kB Active(file): 25568 kB Inactive(file): 82112 kB Unevictable: 0 kB Mlocked: 0 kB HighTotal: 0 kB HighFree: 0 kB LowTotal: 187792 kB LowFree: 58544 kB SwapTotal: 530140 kB SwapFree: 530140 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 3276 kB Mapped: 3708 kB Shmem: 128 kB Slab: 13620 kB SReclaimable: 10048 kB SUnreclaim: 3572 kB KernelStack: 384 kB PageTables: 344 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 624036 kB Committed_AS: 8428 kB VmallocTotal: 835640 kB VmallocUsed: 6864 kB VmallocChunk: 820320 kB HardwareCorrupted: 0 kB AnonHugePages: 0 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 4096 kB DirectMap4k: 24512 kB DirectMap4M: 172032 kB
Everything works straight out of the box, which is terrific. Better still the PCMCIA device for ethernet I have works out of the box too. My day just keeps getting better!
So since there’s not much to talk about in the area of hardware setup, let’s set up X, and talk about kernel configuration.
Firstly, you’re going to need to get xorg-server and the related video drivers. As we can see from lspci, we have an ATI Rage Mobility. A quick search shows that this card is supported by the mach64 driver, so let’s install that too. I’ll also get xorg-xinit since I don’t want to use a display manager, and xorg-twm/xterm too so that we can test straight away.
pacman -S xorg-{server,xinit,twm} xterm xf86-video-mach64
And that’s it! Hello there beautiful!

Will cover kernel config in another post soon.
A tracker I recently joined requires using an SSL tracker. This is a good step, but rtorrent requires some configuration to get it to work.
Assuming that the SSL port is 443 (it should be), use the following commands append the cert to to /etc/ssl/certs/ca-certificates.crt:
_tracker=[your tracker url]
_tracker="${_tracker#*//}"
openssl s_client -connect "${_tracker%%/*}":443 2>/dev/null < /dev/null | sed -n '/BEGIN CERTIFICATE/,/END CERTIFICATE/p' >> /etc/ssl/certs/ca-certificates.crt
Now rehash the certs as root:
SSL_CERT_DIR=/etc/ssl/certs c_rehash
Now go into your .rtorrent.rc, and add the following if it doesn’t already exist:
http_capath = /etc/ssl/certs
Now start rtorrent however you normally do, and it should successfully authenticate.
Earlier today one of my drives began to exhibit some problems that cause me to expect that it is nearing the end of its days, so I unmounted the drive, fired up ddrescue and copied it over to an image within a file on another drive. I had reason to believe that the one of the filesystems within the image that contains an ext4 filesystem was corrupt, and needed fixing.
Firstly, we need to find the offset of the partition on the raw image. You can use fdisk or its derivatives for this, but I am more comfortable with GNU parted.
# parted seagate-2011-06-02.img GNU Parted 2.4 Using /media/exthd2/seagate-2011-06-02.img Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) unit Unit? [compact]? B (parted) print Model: (file) Disk /media/exthd2/seagate-2011-06-02.img: 500107862016B Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1048576B 500107862015B 500106813440B primary ext2 (parted) q
1048576 bytes (1M) is our offset. Now, let’s set up the loop device that we will fsck.
losetup -o 1048576 /dev/loop0 /media/exthd2/seagate-2011-06-02.img
Now fsck the loopback device.
# fsck [...] /dev/loop0
Riviera on #bash came up with this pretty nice sed conversion from text to octal mode:
sed -e 's/.*/+&=---0--x1-w-2-wx3r--4r-x5rw-6rwx7/' -e :a -e 's/+\(...\)\(.*\)\1\(.\)\([^=]*\)$/\3+\2\1\3\4/' -e ta -e 's/+=[^=]*$//' <<< rwx-w-rwx 727
If you don’t mind having bc as a dependency, it can be even shorter:
sed 'y/rwx-/1110/;s/^/ibase=2;obase=8;/' <<< rwxr-wr-w | bc 755
I just thought this was pretty great, so I figured I’d give it a post.