Score:2

How to set timeout for waiting missing HDD while system boots?

it flag

System: Ubuntu 20.04 with EFI boot.


Clarification why I need this

I configured two swap partitions:

  • One primary swap on the second HDD. It is used for hibernation. (Hibernation function is better to use on HDD in order to prolong life for SSD.)
  • The second swap partition on SSD with the system. This is for case if I use SSD as single disk - when second HDD is removed and missing. In this case I just want the system to work normally - even without hibernation function (or with one using swap on SSD).

What I did:

  • Created swap partition on HDD.
  • Set its UUID as resume for Grub.

/etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=25d5d4af-736a-4232-a4bb-492499bc1038"
  • Set both swap partitions to fstab with priority for the swap on HDD and the nofail and x-systemd.device-timeout=3s options. This options for case when HDD is missing. Without this options and when HDD is missing the system hangs during the boot for 90 seconds.

/etc/fstab config for swap partitions:

#swap on HDD
UUID=25d5d4af-736a-4232-a4bb-492499bc1038 none            swap    nofail,pri=20,x-systemd.device-timeout=3s              0       0
#swap on SDD
UUID=e78a171a-3c52-4cd1-b86a-17709f4b49d9 none            swap    pri=10              0       0

What the problem I have:

When SSD and HDD connected to laptop together everything is fine. When HDD is missing during system boot Grub tries to find partition with swap on HDD and hangs for this on about 33 seconds.

After system booted in logs there were the following messages about timeout for waiting for missing HDD (which I intentionally removed) with swap partition:

/var/log/boot.log:[ESC[0;1;31m TIME ESC[0m] Timed out waiting for device ESC[0;1;39m/dev/disk/by-uuid/46e39f74-e1b3-4705-9bac-84ee2593b4d
4ESC[0m.

/var/log/syslog:Feb 23 14:23:26 Device-2 kernel: [    0.032426] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-5.13.0-28-generic root=UUID=a59635ec-2cef-4396-bdf3-be7e4b23fc73 ro quiet splash resume=UUID=25d5d4af-736a-4232-a4bb-492499bc1038 vt.handoff=7

/var/log/syslog:Feb 23 14:56:14 Device-2 systemd[1]: dev-disk-by\x2duuid-25d5d4af\x2d736a\x2d4232\x2da4bb\x2d492499bc1038.device: Job dev-disk-by\x2duuid-25d5d4af\x2d736a\x2d4232\x2da4bb\x2d492499bc1038.device/start timed out.

What I want:

To set timeout for waiting missing HDD not more than 5 seconds. Now it set by default somewhere in the system for 30-33 seconds.


I tried the following:

  • To find timeout property in the Grub config. In /etc/default/grub can be specified two related options:
  • GRUB_HIDDEN_TIMEOUT
  • GRUB_RECORDFAIL_TIMEOUT

But they are not for this case. Information about this options can be found here:

I tried to analyze code for Grub in /etc/grub.d/ and understood that such timeout probably specified in the system boot config - in systemd. I tried to find corresponding timeout option in systemd config:

sudo grep -iR timeout /etc/systemd/
/etc/systemd/system/rescue.target.wants/grub-initrd-fallback.service:TimeoutSec=0
/etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service:ExecStart=/usr/bin/nm-online -s -q --timeout=30
/etc/systemd/system/emergency.target.wants/grub-initrd-fallback.service:TimeoutSec=0
/etc/systemd/system/multi-user.target.wants/ua-reboot-cmds.service:TimeoutSec=0
/etc/systemd/system/multi-user.target.wants/unattended-upgrades.service:TimeoutStopSec=1800
/etc/systemd/system/multi-user.target.wants/grub-initrd-fallback.service:TimeoutSec=0
/etc/systemd/system/multi-user.target.wants/snapd.recovery-chooser-trigger.service:# blocks the service startup until a trigger is detected or a timeout is hit
/etc/systemd/system/sleep.target.wants/grub-initrd-fallback.service:TimeoutSec=0
/etc/systemd/system.conf:#DefaultTimeoutStartSec=90s
/etc/systemd/system.conf:#DefaultTimeoutStopSec=90s
/etc/systemd/system.conf:#DefaultTimeoutAbortSec=
/etc/systemd/user.conf:#DefaultTimeoutStartSec=90s
/etc/systemd/user.conf:#DefaultTimeoutStopSec=90s
/etc/systemd/user.conf:#DefaultTimeoutAbortSec=
/etc/systemd/logind.conf:#HoldoffTimeoutSec=30s

Tried to change options with 30 seconds value to 5 seconds:

/etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service:ExecStart=/usr/bin/nm-online -s -q --timeout=5
/etc/systemd/logind.conf:#HoldoffTimeoutSec=5s

But this has not given expected result.

Also I tried to set the same labels for swap partitions and to specify resume swap partition by this label (/dev/disk/by-label/...), not by UUID. But in such case there is no determination which swap partition from both will be used to load the system from hibernation state.

I found the similar question: How to set timeout for the systemd start job "dev-md125.device" (mdadm) But in it there is no details how to configure timeout in systemd for HDD.

Here there is example how to set TimeoutStartSec for httpd.service

Is it possible to specify such timeout for HDD mounting during system boot?

Thanks.

cn flag
Don't use partitions use a swapfile and your problem is non-existent: you can put either swap in a directory on each of the disks. "(Hibernation function is better to use on HDD in order to prolong life for SSD.)" Doubt it will make a real dent into the lifetime of an SSD. My SSD outlasts my notebook 10 times over and when I get a new notebook I get a new (far quicker) SSD. All you really need is a backup of personal data on the SSD.
it flag
Did not thought in this direction. That is interesting. Thanks for the idea! I have quite good old Toshiba's SSD - do not want to kill it by 3 time per day hibernation )
cn flag
Oh then it might indeed be an issue. The old ssds had lots of little bugs storing data. Might I also suggest it might be better to not hibernate if you use the SSD to boot. Booting is so quick I always turn my machine off (your boottime will be under 15s i would guess ?).
it flag
@Rinzwind, Yes I also usually are using power off. Boot time is quite fast - is about 20-30 seconds. But hibernate sometimes is also useful - many apps with their state can be saved in hibernation - and to wait 1 minute while hibernate are loaded them from HDD for me is not a problem. Besides if swap resides on HDD the hibernation will be free for SSD - I mean it will not hurt it (but of course it is not so fast as on SSD). And hibernation settings also open `hybrid sleep` and `sleep-then-hibernate` options - this is also sometimes useful. So I thing this set up worth it.
it flag
@Rinzwind I analyzed approach with swapfiles and do not understand how they can help in my situation. In case of swapfiles (also both - on HDD and SDD) I also have to specify UUID partition of swapfiles location in `Grub2` property `GRUB_CMDLINE_LINUX_DEFAULT` in format `resume=UUID=<your UUID> resume_offset=<youroffset>` source: [HOWTO: Use swapfile instead of partition and hibernate](https://ubuntuforums.org/showthread.php?t=1042946) And there must be the same problem during boot with missing UUID on which swapfile is located. Could you please clarify how they can help?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.