18

After upgrading to 20.04 on WSL sleep doesn't work with an error:

sleep: cannot read realtime clock: Invalid argument
9

This is because of a bug in WSL1. Look here: https://discourse.ubuntu.com/t/ubuntu-20-04-and-wsl-1/15291

The upcoming Ubuntu 20.04 implements glibc 2.31. Unless you are on Insider you have not gotten the fix for issue 4989 yet and likely will not for a couple months. Without the fix things tend to break on Ubuntu 20.04 on WSL 1, sometimes even in the upgrade process 9 to Ubuntu 20.04. For example htop doesn’t work on Ubuntu 20.04 on unpatched WSL 1.

| improve this answer | |
22
wget https://launchpad.net/~rafaeldtinoco/+archive/ubuntu/lp1871129/+files/libc6_2.31-0ubuntu8+lp1871129~1_amd64.deb

sudo dpkg --install libc6_2.31-0ubuntu8+lp1871129~1_amd64.deb

sudo apt-mark hold libc6

sudo apt --fix-broken install

sudo apt full-upgrade

How to upgrade Ubuntu 18.04 to 20.04 on WSL Windows 10

| improve this answer | |
  • 3
    It seems that many of your answers consists the link how2shout.com. If you're the owner of that domain, please disclose your affiliation. See How to not be a spammer. – Kulfy May 7 at 15:38
  • 3
    Isn't a good idea to run sudo apt-mark unhold libc6 at the end? – Flimm Jul 22 at 11:02
  • I'd prefer if this answer explained what that random .deb package is and what the risks are of installing it and whether (and how) it would be easy to revert back later. – Ryan Sep 13 at 13:27
15

Just had this problem and I replaced the /usr/bin/sleep binary with a python script that roughly replaces the functionality.

Backup /usr/bin/sleep and replace with the file with the following contents

#!/usr/bin/env python3

import sys
import time

time.sleep(int(sys.argv[1]))

Remember to chmod +x /usr/bin/sleep after replacing.

| improve this answer | |
  • sudo cp -p /usr/bin/sleep /usr/bin/sleep.orig and sudo vim /usr/bin/sleep were helpful commands for me. I think your hack might be working for me, although in my Windows Task Manager, I see a php7.4 background process with "Very high" for "Power usage", and I don't know why. – Ryan Sep 13 at 13:32
  • I needed to replace /bin/sleep instead, on my ubuntu installation. – domenukk Sep 18 at 16:10
  • github.com/u-root/u-root/blob/master/cmds/core/sleep/sleep.go I used this instead as I needed support for seconds/minutes etc. – Lh Lee 2 days ago
2

This command worked for me. use with root user privilege.

apt-mark hold libc6
apt --fix-broken install
apt full-upgrade
| improve this answer | |
  • Those 3 commands didn't work for me until I prepended sudo to each, and only after running sudo apt-get update. Then they seemed to solve this problem. So I guess I'll +1. – Ryan Sep 12 at 18:56
  • Actually, I don't think it worked for me, but I can't remove my upvote. Currently I'm hoping askubuntu.com/questions/1230252/… works. – Ryan Sep 13 at 13:33
1

It's far from ideal but another workaround is to edit /var/lib/dpkg/info/libc6:amd64.postinst and comment out the set -e at the top of the script (insert a # as the first character in the line).

You will still receive the sleep: cannot read realtime clock: Invalid argument error but it will not cause the upgrade of the package to abort.

It's not ideal because:

  1. A standard post-install script is modified.
  2. The script change must be applied every time libc6 is upgraded.
| improve this answer | |
0

Using read as alternative workaround

sudo cp -p /usr/bin/sleep /usr/bin/sleep.orig
echo 'read -n1 -s -t$1 || true' | sudo tee /usr/bin/sleep
| improve this answer | |
  • This looked interesting, but I got an error: sudo service supervisor start Starting supervisor: /bin/sleep: 1: read: Illegal option -n – Ryan Sep 13 at 13:30
-1

Installing this via dpkg on the Surface Pro X solved it for me, https://ubuntu.pkgs.org/19.10/ubuntu-updates-main-arm64/libc6_2.30-0ubuntu2.2_arm64.deb.html

After install I ran wsl -t Ubuntu in PowerShell then sudo apt-mark hold libc6.

| improve this answer | |
-2

I just installed Ubuntu 20.04 using WSL 1 (my windows 10 version is 1903, OS Build 18362.778) and got this error trying to run a redis server.

Thanks to Raj's link to https://www.how2shout.com/how-to/how-to-upgrade-ubuntu-18-04-lts-to-20-04-lts-on-wsl-windows-10.html I got it fixed using what it suggested there.

sudo -i
sudo mv /bin/sleep /bin/sleep~ ; touch /bin/sleep ; chmod +x /bin/sleep

After that the redis server ran ok.

| improve this answer | |
  • 3
    ... Doesn't that just replace /bin/sleep with an empty file? This is a terrible hack and is bound to break things in unexpected ways. – Michael Dorst May 28 at 23:40
  • Yeah, it may get you past some sticky situations, but sleep is a standard UNIX command and no doubt just replacing it with an empty file that does nothing is going to screw up a lot of things. – Asfand Qazi Jul 10 at 9:57

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.