Using a laptop as alarm clock

My alarm clock died long ago. Since then, I use my cellphone to wake me up. Works ok, except that my current cellphone is total crap and, among numerous issues, its alarm software some morning just stays idle while, the others days when it actually works, a simple movement shuts it off. Believe me, I checked everything, made plenty of test, it’s just bad design and poorly coded software.

Not to mention that I usually wake up with no alarm; so when I use one, it means that I must wake up early, probably with not enough sleep at all. I need the real deal, high sound level and no shortcut to kill it, to actually get up.

Whenever I needed an alarm, I ended up running, on my laptop not to far from my bed, some `sleep XXh XXm && mplayer /path/to/a/song`, check sound volume, followed by CTRL-C in the morning.

Two days ago, I was über-tired, I needed to wake up early next morning and calculating tomorrow waking up time  – current time just pissed me off, not to mention checking the volume level, mute setting and such. It pissed me enough to decide me to write a script to fix the problem. Here comes

  • it takes as argument the time you’d like to wake up in the form HH:MM or HHh MMm ;
  • it can run as timer (as sleep), useful if you want to take 20min nap, with -t or –timer ;
  • it wakes you up playing a random song picked in ~/.wakey ;
  • it uses mplayer to play the song, so it can be in any format your mplayer supports ;
  • it raises progressively the sound volume when trying to wake you up (you can set –volume-max, in case 100% on Master mixer is too loud) and reset properly mixer settings when finished ;
  • it won’t stop playing the music until you type a 3 to 5 characters word randomly taken from the defaut dictionary installed on your system (/usr/share/dict/words).

I wanted it to deal with any powersave setup to make sure to forbid the laptop to sleep or hibernate, but I found not portable and clean way to do it (my laptop uses KDE with PowerDevil). I’d be happy to hear about any clue/lead in the regard.

# (this assume is executable and in $PATH)
# wakes you up next time its 6 in the morning: 06:00

# the same 6h

# wakes you up exactly in 15 minutes -t  :15

# the same
wakey.l 15m --timer

# the same but make sure the sound volume wont exceed 70%
wakey.l 15m -t -v 70

To run it, make sure you have debian packages libfile-homedir-perl and libterm-readkey-perl installed. You’ll also need mplayer and amixer properly set up.

Moving a live system from one hard disk to another

Ever found yourself in the situation where you want to move your GNU/Linux from an old hard disk to a new one? Well, it can be done quite easily 🙂

First, set up new partitions with parted then mkswap, mkfs (using proper labels). Yes, I assume you’re familiar with these (RTFM).

Mount the new root partition somewhere, like /mnt/tmp in this article.

Create in this new partition all the directories that it would not make sense to copy from the original system (in my case: home being on another partition, stockage containing only NFS mounts):

cd /mnt/tmp
mkdir dev  home  proc  stockage  sys  tmp mnt

Shut down any daemon/service that is up (cron, etc), to avoid copying stuff in an incoherent state.

Then, actually copy the system:

for dir in /*; do if [ ! -e /mnt/tmp/$dir ]; then cp -ax $dir /mnt/tmp/; fi ; done

Edit /mnt/tmp/etc/fstab to use the newly created partitions.

Chroot in the new system to make it bootable with grub:

mount --bind /dev /mnt/tmp/dev
mount --bind /sys /mnt/tmp/sys
mount proc -t proc /mnt/tmp/proc
chroot /mnt/tmp
# (you can run blkid to check the root's unique id of this
# new system shows up in the new system /boot/grub/grub.cfg)
grub-install /dev/XX  # where XX is the new disk, like /dev/sdc or whatever

Reboot on the new system (stating the obvious: change boot drive order in the BIOS). If everything is fine, then copy /home from the old disk to the new partition, without login in with any system (CTRL-ALT-F2 to quite X server and log in as root, for example).

After removing the old device, re-run update-grub so it’ll no longer show up. The end.

Update: Please take a look also at the following backup script that clone a live system to a secondary hard drive.

Getting accurate temperature reading for the CPU

On my main workstation, lm-sensors provides apparently contradictory temperature reading for the CPU, depending on the sensor:

Adapter: PCI adapter
GPU Temperature:  +62.0°C  

Adapter: PCI adapter
CPU Temperature:  +17.0°C  (high = +70.0°C)
                           (crit = +70.0°C, hyst = +68.0°C)

Adapter: ACPI interface
CPU FAN Speed:          1890 RPM  (min =    0 RPM)
CPU Temperature:         +32.0°C  (high = +90.0°C, crit = +125.0°C)
MB Temperature:          +42.0°C  (high = +45.0°C, crit = +90.0°C)

17°C, as reported by the CPU sensor, seems very low especially as the temperature of the room the computer is running inside is at least 17°C already. Clearly, the Motherboard sensor (atk0110 / IT8716F chip) readings, same as what the BIOS reports, are more sensible.

There’s actually lot of misinformation on the web. For instance, CoreTemp author, a proprietary software for MS Windows to provide CPU temperature readings, states on his front page that “all major processor manufacturers have implemented a DTS (Digital Thermal Sensor) in their products. The DTS provides more accurate and higher resolution temperature readings than conventional onboard thermal sensors”. Possibly, probably, right: k10temp may be more accurate than atk0110. However, when the same author reply, on his forum, to a user asking about inconsistencies in CPU temperature readings, clearly interested in real and not relative temperature (he wrote :”I’m running water cooling and the temps aren’t high during load but just wondering about the accuracy”, high temperature is meaningless on an undefined relative scale), that “I’d say that Core Temp is more accurate, especially at higher temperatures. The ASUS programs sensors are based on the motherboard and depend on an external chip. The sensors Core Temp reads are located in the CPU itself and the values are read directly from the CPU registers.”, he clearly shows misunderstanding of what superior accuracy CPU sensors really mean.

As documented by AMD mentioned in the k10temp linux module doc, “[k10temp] is the processor temperature control value, used by the platform to  control cooling systems, […] is a non-physical temperature on an  arbitrary scale measured in degrees, […] does not represent an actual  physical temperature like die or case temperature. Instead, it specifies  the processor temperature relative to the point at which the system must  supply the maximum cooling for the processor’s specified maximum case  temperature and maximum thermal power dissipation”.

I was about to publish this article without paying attention to Intel sensors, but a quick search lead to me even worse: a comment about Core Temp in a doc titled CPU Monitoring with DTS/PECI stating : “These tools provide a convenient way to see the temperature variation reported by the sensor […] There are several issues with these tools. First the assumed value for Tj may not be correct and thus impact the accuracy of actual temperature reporting. Secondly the DTS is only accurate when in the adjacency of Tj. Not knowing the intention and effective range of DTS, the tools try to compensate with the inaccuracy of low temperature reading, which may not be a correct interpretation.”

However accurate they may be, relative readings provided by CoreTemp for AMD K10 are almost meaningless to an end user (while great for the system for fancontrol and such), likely expecting to be able to compare them to other (motherboard|hard disk|etc) readings. In my case, surely k10temp mean something (17°C is low) but it makes no sense to compare it to the room (20°C), GPU (62°C), PATA Hard Disk (39°C), Motherboard (42°) or any other else temperature. In short, except if you know exactly what you’re doing, use Motherboard sensors and if you’re looking for an alternative to CoreTemp, try Open Hardware Monitor.

RSS feeds: new layout for rawdog

Almost two years ago, I posted an article describing how I use rawdog, a minimalist RSS aggregator to get, on my webserver, an HTML output of my Akregator aggregated feeds. Since then, I changed the layout:

  • articles are no longer shown in four columns,
  • articles descriptions are provided directly on the page and no longer on mouse over the title,
  • there are now several indexes pages, one per day (as many necessary to reach the article limit, set to 950) using plugin dated-output.

I won’t re-describe the whole setup, the relevant files to set up this new rawdog layout are here. On my webserver, it goes in /home/rawdog, using the user rawdog (group www-data). Obviously crontab is actually /etc/cron.d/rawdog and should be edited to refer to proper local users.

I won’t harm, by the way, even if by default unnecessary (could prove useful if, by any chance, your server is configured to interpret perl .pl ou python .py files), to restrict access to rawdogs subdirectories that contains scripts, for instance by adding, for nginx, such statements in the server config:

    location /rss/scripts { deny  all; }
    location /rss/plugins { deny  all; }