11

Is there a way to instruct the (Linux) kernel not to wake up a secondary hdd after a system sleep/wake-up cycle? I'm asking because in my laptop I have an SSD as a primary drive containing the system root and a secondary HDD where I keep a backup system and files I access sporadically. Since the laptop usually goes through many daily sleep/wake-up cycles (I mean Suspend to RAM, not hibernation) for many days, I would like to put the secondary HDD to sleep manually and instruct the kernel to keep it asleep across system sleep/wake-up cycles.

1
  • 1
    If you want to send your harddisk manually to sleep you can use hdparm -Y /dev/sdb. If you system accesses your disk it will automatically spin up again. You can also define this in /etc/hdparm.conf with /dev/disk/by-label/DATA4 { spindown_time = 180 } I recommend using labels for your disks as you can never rely on which disk is detected first by your system. be aware that you need a newer version of hdparm (mine is 9.43) to send disks with label to sleep.
    – syss
    Mar 4 '15 at 12:47
1

since you only use the secondary hdd for backup, I would suggest telling fstab not to mount the drive automatically and to make a backup script that mounts the drive, makes the backup and unmounts the drive again.

example of the fstab line with the noauto option:

/dev/sdb1 /media/backup ext4 user,noauto 0 0

bash script for the backup would than begin with mount /media/backup and end with umount /media/backup

2
  • This does not prevent the kernel from probing the disk upon boot.
    – Marc.2377
    Aug 4 '19 at 6:38
  • @Marc.2377 that's true, the bios will still brobe the disk.
    – switch87
    Oct 21 at 8:11
0

I don't think that is possible. The drive is probed by the BIOS / UEFI upon boot, not just the kernel.

What I do, though, is instruct the system to put the drive in sleep mode right after the system boots. Check https://wiki.archlinux.org/index.php/Hdparm#Putting_a_drive_to_sleep_directly_after_boot.

In my case I have:

/usr/local/lib/systemd/system/rsleephdd.service

[Unit]
Description="Ranolfi's script to sleep hard drives on boot"

[Service]
Type=oneshot
ExecStart=/usr/bin/hdparm -q -S 120 -Y /dev/sdc

[Install]
WantedBy=multi-user.target

It makes no difference whether the drive or its partitions are mounted by fstab (or crypttab, for that matter) or not.

(Edit): Strictly speaking, it appears to be possible to get the kernel to ignore a disk by patching it. That won't prevent the drive from waking up, though - quite the opposite, the patch I linked to will prevent you from accessing the drive, you'll be unable to access your files even sporadically, and also unable to put the drive to sleep.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.