Howto update-safe change Grub2 default to windows

On debian (ubuntu / linux mint should work too) this is quite simple. Grub2 takes menu entry names as default options. This can be done here:

# filename: /etc/default/grub
# search for or add if it not exists:
GRUB_DEFAULT='Windows 7 (loader) (on /dev/sda1)'

Your install might differ. GRUB_DEFAULT takes the menu entries from your grub.cfg usually placed in /boot/grub/

grep -o "menuentry '.*'" /boot/grub/grub.cfg

And here it is:

[...]
menuentry 'Windows 7 (loader) (on /dev/sda1)' --class windows --class os $menuentry_id_option 'osprober-chain-XXXXXXXXXXXXXXXXX'

All what is left to do is update grub as super user:

update-grub

Howto speed up your apt-get like never before

… is quite simple. You get your hands on eatmydata. Yes it’s not a convincing name but hey it’s in the standard repositories of debian and ubuntu so it should do you no harm 🙂

sudo apt-get -y install eatmydata

How to use it

sudo eatmydata apt-get <your regular stuff / install / update /...>

Try it on installs. It is SO MUCH FASTER.

Why the speed? Are there risks?

Normally programs like apt-get are very much power-loss persistent. If there is a sudden power loss you can pretty much resume where you got interrupted. This is possible because apt-get checks often if the data that should be on the disk is really written to it. Old school nerds may know the tool “sync” which is basically what apt-get does a lot.

This is very time consuming because file systems like ext4 and btrfs are not used to being forced to write all the time. They want to keep stuff in buffers and write when they decide it’s time. The is part of the magic speed they can achieve. Eatmydata redirects calls from following programs to sync-like functions programs into the void. Eatmydata makes other programs think they work pretty safe but actually they are not (and hell of a lot faster).

So it’s really fast but you really shouldn’t loose power (or sth. similar) when using eatmydata. But hey my last power failure is years from now and how are the chances you’re using eatmydata in this very moment? I wouldn’t recommend it for cronjobs though.

Update: Problems with Xbian on the Raspberry PI (rpi)

Looks like eatmydata causes problems on the raspberry pi with xbian installed. apt-get / dpkg exits with an error from time to time. But one can always proceed with

sudo dpkg --configure -a

But nevertheless eatmydata is not recommended for the rpi.

Wake on lan remote control

I’ve written a small script to remote control a computer via wake on lan (WOL) packages. This could come in quite handy if my raspberry pi finally arrives but any HTPC owner could make use of this too. (You don’t want to run xbmc along with your torrent client (and vice versa) all day long, do you?)

It’s available here: https://sourceforge.net/projects/wolrc/

How it works:

It basically executes predefined commands on the amount of WOL packages received without a timeout. Just arm your android smartphone with a WOL app, send e.g. two WOL pkgs and your box will execute whatever you told it to do. It needs root (because it depends on pcapy ) so you’re strongly advised to use sudo wherever you can.

Note (Update):

AFAIK the raspberry pi is not capable of booting up due to a WOL package. Of course it can receive and handle them nonetheless.

 

Automated shutdown paranoid edition

One time I relied heavily on the ntfs-3g driver and it killed my ntfs-partition. Since then I always check if any mounted ntfs partition is umounted properly. For automation here is a code snippet for debian (ubuntu?). If a mount point in /media cannot be unmounted there will be no shutdown.

for f in `mount | grep /media/ | awk '{ print $1; }'`;
do 

! umount $f && exit

done

shutdown -h 1

HOWTO: Tell Grub to load windows 7 as default (debian)

… is quite easy if you know what to do (and it’s update safe!):

Will be / Is DEPRECATED. Please refer to: http://www.triggers-world.de/?p=249

Only precondition: win7 or any other OS you want to boot as default is the next OS after the standard debian entries in the grub list / win7 is the only other OS installed

1. Edit /etc/default/grub

#find&edit or add if it doesn't exist
GRUB_DEFAULT=`/bin/bash "/somedir/getlastboot.sh"`

2. in /somedir/ create a getlastboot.sh with the following content

#!/bin/bash

VAR1=`ls -l /boot | grep -v .bak | grep -c initrd.img`
VAR2=`ls -l /boot | grep -v .bak | grep -c vmlinuz`

let DEFAULTX=VAR1+VAR2
echo $DEFAULTX

3. make it executable

chmod 777 getlastboot.sh

4. update-grub

sudo update-grub

(I have not tested it on ubuntu, but it should work there too)

S-ATA cables – more guilty than you might think

If you get sth. like this (and best case your raid 1 goes crazy)

daywalker kernel: [  498.324514] ata5.00: status: { DRDY }
[  498.324516] ata5.00: failed command: WRITE FPDMA QUEUED
[  498.324520] ata5.00: cmd 61/60:e8:e2:7d:0e/01:00:9c:00:00/40 tag 29 ncq 180224 out
[  498.324520]          res 50/00:d8:7a:87:0f/00:00:9c:00:00/40 Emask 0x10 (ATA bus error)
[  498.324522] ata5.00: status: { DRDY }
[  498.324524] ata5.00: failed command: WRITE FPDMA QUEUED
[  498.324527] ata5.00: cmd 61/88:f0:4a:7f:0e/01:00:9c:00:00/40 tag 30 ncq 200704 out
[  498.324528]          res 50/00:d8:7a:87:0f/00:00:9c:00:00/40 Emask 0x10 (ATA bus error)
[  498.324530] ata5.00: status: { DRDY }
[  498.324533] ata5: hard resetting link
[  498.644016] ata5: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[  498.646630] ata5.00: configured for UDMA/133
[  498.660052] ata5: EH complete
[  499.755828] ata5.00: exception Emask 0x10 SAct 0x7ffff9ff SErr 0x400100 action 0x6 frozen
[  499.755831] ata5.00: irq_stat 0x08000000, interface fatal error
[  499.755834] ata5: SError: { UnrecovData Handshk }
[  499.755836] ata5.00: failed command: WRITE FPDMA QUEUED
[  499.755840] ata5.00: cmd 61/00:00:b2:51:ed/04:00:4d:00:00/40 tag 0 ncq 524288 out
[  499.755840]          res 50/00:98:ba:6a:ed/00:01:4d:00:00/40 Emask 0x10 (ATA bus error)
[  499.755842] ata5.00: status: { DRDY }
[  499.755844] ata5.00: failed command: WRITE FPDMA QUEUED
[  499.755848] ata5.00: cmd 61/08:08:b2:55:ed/02:00:4d:00:00/40 tag 1 ncq 266240 out
[  499.755848]          res 50/00:98:ba:6a:ed/00:01:4d:00:00/40 Emask 0x10 (ATA bus error)
[  499.755850] ata5.00: status: { DRDY }

you might want to check a different S-ATA cable first. (Chances for a kernel bug are very bad too…) Would have spared me a lot of time… If you have got the opinion that the cable is innocent because windows is working properly on the same hdd well guess again because windows easily ships around this mess by falling back into not using dma 🙂

(If another cable on another SATA connector does not change anything the hdd is probably broken)

UPDATE:
http://lime-technology.com/wiki/index.php?title=The_Analysis_of_Drive_Issues
is pretty informative though!

UPDATE II:
Had a short conversation with a computer shop owner the other day. He told me that the SATA cables provided (for free) with the mainboard are much more likely to fail than others. Don’t know if he just wanted me to buy more cables (i did not) but my faulty one was indeed provided with the mainboard and he didn’t knew that in advance.

Unzip broken archive (partially)

Many solutions I found included wine and winrar (and this does not worked for me in any case btw). But I found sth different. (apt-)get (install) bsdtar!

bsdtar xf yourbrokenzip.zip

Besides for rar files the non free version does this like a charm

unrar -kb x yourrar.rar

Remember: These cmds do not repair anything. They just extract what they can!