logo

Home page
Articles for Windows, Linux, OS X
Mac tips and articles
Mac tips
Windows 8 tips and articles
Windows 7 tips and articles
Vista Tips
XP Tips
Linux tips and articles
Read the blog
Online store
Windows, Linux, OS X programs
Links
About

Send the disk to sleep with hdparm

There are lots of obscure commands in Linux and there are so many you could fill a whole book with them. Come to think of it, there are whole books full of them. One command that you might find useful is hdparm, which is used to access various functions of the hard disk drive. It is a multi-function tool that does a lot of different things, but here we are just going to look at a few simple ones. It's a brief introduction to hdparm.

You need to open a Terminal command prompt window in order to use it. Type hdparm and you will see a long list of command line parameters that can be used with it. Notice that some are labelled dangerous, some are very dangerous and a few are extremely dangerous. We're not going to be using any labelled dangerous. However, you do need to be careful with your typing because sometimes a function is safe with an uppercase parameter, like -S, but dangerous with a lowercase parameter like -s.

Let's start off with something very simple. We'll display information about the disk drive:

sudo hdparm -i /dev/sda

You can run this with a -i or a -I, so try both and you'll see lots of information about the hard disk drive. Probably more than you need to know and a bit technical in placed, but it could be useful. I'm using sudo to run this as root (administrator) and some distros use su instead. The /dev/sda simply means the first hard disk drive in the PC, but you may need to use /dev/hda - the former is for SATA drives and the latter is for old IDE disk drives.

How fast is the hard disk drive? If you upgrade the computer and put a faster hard disk drive in, how much faster is it? Was it worth the upgrade price? You can measure the performance of the disk with:

sudo hdparm -t /dev/sda

As before you can use a lowercase -t or an uppercase -T. Both measure the disk performance, but in different ways. A -T benchmarks the cache and -t benchmarks the device. If you run these before and after upgrading a disk drive you can see the improvement in performance.

Measure disk performance with hdparm

Many components in the computer can be put into a low power sleep mode and this reduces energy consumption, which is more environmentally friendly, but more usefully it extends the life of a laptop battery. A disk drive can automatically stop spinning and go into sleep mode after a certain period of inactivity and you can set this with hdparm:

sudo hdparm -S 60 /dev/sda

The S stands for sleep, the /dev/sda is the disk drive and the 60 is the time to wait before going to sleep. In typical Linux fashion, everything is much more complicated than it needs to be and the time is expressed as the number of blocks of five seconds. So 60 is 60 x 5 seconds or five minutes.


copyright