Put HDD into standby after wake from suspend

I use suspend on my laptop all the time as it works perfectly on Ubuntu with integrated intel graphics. After I bought second classical (spinning) HDD in addition to SSD I was thinking about reducing power consumption and noise as this second HDD gets started on each system start / resume from suspend. Because it will serve only as media storage, it should run only a couple of minutes per day and the rest time should be powered down.

So my requirements were clear:

  • after start/resume, second HDD should be put into standby mode immediately (HDD is not spinning)
  • when second HDD is not active within 10 minutes it should be put into standby mode as well

Spinning and other HDD settings are controlled using hdparm utility. This is how my current hdparm config file looks like:

$ cat /etc/hdparm.conf

/dev/sdb {
    apm = 255
    apm_battery = 255
    # 120 * 5 = 600 seconds = 10 minutes
    spindown_time = 120
    poweron_standby = off

Note: If you want to get your HDD into standby mode, APM level should be in general lower than 128. Failing to do so is a common mistake and reason why people are wondering that HDD won’t stop spinning after spindown_time elapse. However for my Samsung SpinPoint M9T, APM values lower than 128 cause standby only after a few seconds of idleness so the spindown_time is ignored. For that reason I disabled APM completely (value 255) and now HDD is brought into standby properly after configured spindown_time. If you are experience the same issue, try to disable APM, it might help you too.

This hdparm configuration works fine except HDD is not brought automatically into standby mode after wake from suspend. I found out that only apm, apm_battery and spindown_time settings are re-applied after resume, not the standby. This is done using script


which gets called from

/lib/systemd/system-sleep/hdparm (systemd hook)

once laptop is suspended or resumed. No other hdaparm settings are re-applied after resume. So in order to spin down HDD after resume, there are 2 options:

  1. create systemd service in /etc/systemd/system/suspend.target.wants
  2. modify /lib/systemd/system-sleep/hdparm script or create new one in the same directory and suspend disk manually when post event occurs

Until Ubuntu 15.04 there was also a third option, place standby invoking script into /etc/pm/sleep.d directory. As from 15.10, systemd has replaced upstart and pm utils scripts are no longer invoked automatically!.

I took the first approach and created following systemd service, which spins down HDD immediately after resume:

$ cat /etc/systemd/system/suspend.target.wants/standby-hdd.service

Description=Turn off power of the media hdd after resume

ExecStart=/sbin/hdparm -y /dev/sdb


This works for me well.

Ubuntu 14.04 – broken bracketed paste mode in Gnome Terminal

After upgrade to Ubuntu 14.04 LTS (Trusty Tahr) from 13.10 I found out very annoying issue while copy-pasting commands into gnome terminal. Each command pasted from clipboard has characters 0~ in the beginning and 1~ at the end of the text, so it looks like:

$ 0~ls -la1~

This happens only after I go to subshell from Midnight Commander and back a few times using Ctrl+o key.

First time I thought it’s a MC bug but after a bit of googling I discovered that the problem is caused by a bug in bracketed paste mode implementation in VTE library. VTE library is used in most GTK based terminal emulators such as Gnome terminal, XFCE terminal etc. so this problem affects all of them. There is already a patch for development version of libvte (v0.36) but it’s not clear whether this fix will be backported to libvte v0.34 used in Trusty or Ubuntu team will upgrade libvte to at least v0.36 in LTS. Until resolved, you can disable bracketed paste mode manually once this issue appears like Conrad Irwin suggested in his great blog post. Just enter following command in terminal:

$ printf "\e[?2004l"

and issue should go away. I have tried to add this command into ~/.bashrc in order to disable bracketed paste mode when terminal is opened but this seems to not work. You can re-enable bracketed paste mode anytime using similar command:

printf "\e[?2004h"

Bracketed paste mode is generally a good idea. Its main purpose is to inform shell or applications running in shell that text has been pasted from clipboard and not typed manually. This could improve security since when you paste command with newline character (\n) at the end, bash (and most shells too) executes that command immediately. You can find some examples of malicious commands here.

Edit 10/2015: Seems like this issue is finally resolved in Ubuntu. VTE patch has been backported to libvte v0.34 used in Trusty. After upgrade I am no longer able to reproduce this issue.

Motorola Atrix 4G – unlock and install custom ROM

Motorola Atrix 4G is a great phone. I owned it more than a year and a half and I am very satisfied with overall performance, battery life and Android stability. Although Atrix has been released officially in early 2011, there are still not many devices on the market that are substantially more powerful. Unfortunately, Motorola decided to not provide any further updates of Android OS for this device so it’s basically stuck on Gingerbread (2.3.x). On the other side, Android is a OSS and community luckily came up with several custom ROMs you may use to bring some new life to this excellent device.

In this post I will show you how to:

All steps listed above except ROM backup are necessary in order to install custom ROM and can’t be skipped.


Be aware that using this approach you will most likely void the warranty! Although procedure has been tested multiple times by many users on XDA, there is always a slight chance that some step won’t work for you and you will brick your device. You do it on your own and I can’t be responsible for any damages to your device!

Consider making applications backup

Please consider rooting your original Gingerbread ROM and backup all installed applications with their data using Titanium Backup for instance. The thing is all Android phones have implemented security mechanism which completely erases /data partition when you try to unlock bootloader, so it basically performs factory reset. This is a generally good idea and prevents unknown persons to access your private data when device is stolen or lost. Data partition contains apps+data, sms, contacts etc. and you can’t backup them normally since /data partition is not accessible without root permission.

If you don’t care about data of your installed applications and all stuff like contacts you have already synchronized on Google’s servers than rooting your original ROM is not needed. You can unlock bootloader and flash custom recovery completely without rooting! Any procedure mentioned in this post won’t touch your files stored on /mnt/sdcard partition (internal 16GB memory) or /mnt/sdcard-ext (SD card).


Before proceed please make sure fastboot tool is available on your computer. The easiest way how to get it is to install Android SDK although there are also alternative methods without having to install entire SDK. This guide presumes you are running operating system based on Linux.

1. Unlock bootloader

Atrix comes with locked bootloader just as most others Android phones do. What does it mean? Bootloader is a program responsible for starting either Android OS or recovery software. Atrix bootloader only starts original ROMs, which are signed by digital signature from Motorola so it’s locked only to software provided by manufacturer. Unlocked bootloader allows you to install and boot custom Android Recovery that enables you to install (flash) custom ROM and boot into it.

Before the bootloader can be unlocked, we have to flash so-called pudding image. It’s a system binary file (SBF) that contains some tweaks for the bootloader and makes the unlock possible. There are two version of it:

so make sure you have picked up the right version for your device. You also need to download utility (linux-only) for flashing SBF files. Do not attempt to flash wrong image. Very likely you will brick your device. You should be able to find out what kind of version you have from About page accessible through System settings in your device. Since I bought my Atrix in Germany from original distribution, I have used the international version which worked fine.

1.1 Flash pudding image:

Start your phone while holding Volume up key and the Power button. You will boot into RSD Protocol mode. Once you see the Starting RSD protocol support on the screen, you can release the keys. Plug-in phone using USB cable into your computer and perform flash:

root@thinkpad:/home/marlly/Android/Moto4G# ./sbf_flash intl-fix-try1.sbf
SBF FLASH 1.23 (mbm)
=== intl-fix-try1.sbf ===
Index[5]: Unexpected chip 16
Index[6]: Unexpected chip 16
00: RDL03 0x00000000-0x002FFFFF 7F75 AP
01: RDL01 0x00800000-0x008407FF 3556 BP
02: CG02 0x00000010-0x0000580F 4615 AP
03: CG03 0x000000A0-0x0008009F 2135 AP
04: CG42 0x00000020-0x0030001F F03C AP
05: CG44 0x00000050-0x0030004F 0C66 AP
06: CG47 0x00000070-0x0008006F E7CB AP
>> waiting for phone: Connected.
>> uploading RDL03: 100.0%
-- OK
>> verifying ramloader
-- OK
>> executing ramloader
-- OK
>> waiting for phone: Connected.
>> sending erase
-- OK
>> uploading CG02: 100.0%
-- OK
>> uploading CG03: 100.0%
-- OKu
>> uploading CG42: 100.0%
-- OK
>> uploading CG44: 100.0%
-- OK
>> uploading CG47: 100.0%
-- OK
>> rebooting

After restart, you need to shutdown your device and take the battery off. Now when the pudding is in place, you can proceed to actual unlock.

1.2 Boot into fastboot and issue unlock

Turn the phone on again while holding Volume down key until text Fastboot appears. You are now in bootloader menu, where you can navigate through menu items using Volume down key and enter to selected item using Volume up key. In our case just press Volume up to select Fastboot mode. Now run command fastboot devices on your computer while device is still connected through USB cable to assure phone is recognized.

root@thinkpad:/home/marlly/Android/SDK/platform-tools# ./fastboot devices
TA744097OL fastboot

Device is connected so now we can proceed to actual unlock.

root@thinkpad:/home/marlly/Android/SDK/platform-tools# ./fastboot oem unlock
(bootloader) Unlocking your device can permanently VOID your warranty.
(bootloader) This process cannot be reversed. If you wish to proceed,
(bootloader) reissue the unlock OEM command containing the unique ID
(bootloader) of your device: 02804088433FD3D7
OKAY [ 0.001s]
finished. total time: 0.001s

Bootloader raised a warning about warranty and asked for confirmation. Just copy the device ID run unlock again:

root@thinkpad:/home/marlly/Android/SDK/platform-tools# ./fastboot oem unlock 02804088433FD3D7
(bootloader) Device is now unlocked
OKAY [ 6.160s]
finished. total time: 6.160s

Congrats, bootloader on your device is now unlocked. You can perform reboot using fastboot command to avoid taking battery out in order to issue restart:

root@thinkpad:/home/marlly/Android/SDK/platform-tools# ./fastboot reboot
finished. total time: 0.000s

After restart you should see the Unlocked label in the top left corner on the screen while device is booting.

2. Flash Clockworkmod recovery

ClockworkMod is a custom Android recovery that allows you to take a full backup of ROM with all data (nandroid backup), restore it, install new ROM or kernel, mount a partition etc. Those things can’t be done using stock recovery.

To flash ClockworkMod you need to download version for Atrix first and boot again into fastboot. Just follow steps above from section 1.2 and make sure you device is recognized in fastboot. After that run this command:

root@thinkpad:/home/marlly/Android/SDK/platform-tools# ./fastboot flash recovery /home/marlly/Android/Moto4G/recovery-clockwork-
sending 'recovery' (4824 KB)...
OKAY [ 0.261s]
writing 'recovery'...
OKAY [ 0.760s]
finished. total time: 1.021s

Now when you restart the phone (by taking battery out or fasboot reboot) and hold Volume up while booting, you should be able to access ClockworkMod from Android Recovery menu item.

3. Backup of original Gingerbread ROM

As we are going to flash a new ROM is very good idea to backup the stock ROM and create so-called Nandroid backup. When things go wrong you have the safety net. With no backup of original software, you have to find and download the same version of stock ROM from the internet and risking you can possibly brick your device. So take a backup now!

In previous step we ended up with freshly installed and booted ClockworkMod recovery. Navigate to backup and restore and select backup. CWM will automatically create folder clockworkmod on the sdcard and put a backup marked with timestamp into it. Restore is very similar. Just select restore instead of backup, pick up the right backup and confirm restore.

4. Install CyanogenMod ROM

There are several custom ROMs for Atrix 4g available at this time. CyanogenMod ROM’s:

MIUI v5 ROM and few others. I have tried all of them and the only one stable enough to do the full day job was CM7. Unfortunately, it’s only Gingerbread so quite old today. Others had a deep sleep bug probably due to 3.1.x kernel. I have also experienced several restarts per day on my device. However, there are also plenty of users on XDA satisfied with mentioned ROMs with no such problems so I suggest you to try if you have enough time to play and you will see.

Save downloaded ROM on sdcard and boot device into CWM recovery. From main menu navigate to wipe data and perform factory reset. After that pick up install zip from sdcard, select the ZIP file with ROM and confirm. ROM will be installed onto /system partition. Once installation has finished you can reboot device again from main menu. That’s it, done. Your Atrix will now boot with custom ROM. Enjoy 🙂

EDIT 09/2015: since most download links seem to be dead now, I put all files I downloaded back in 2013 to dropbox.