Fatal: create key in repository at

Been doing some testing on win10-WSL Ubuntu (default) came across this error: Fatal: create key in repository at … any ideas on a fix …thanks Jim

Installed restic (apt-get install restic) created a repository ran some good sized backups, all good until I upgraded and decided to create a new repository. Gave up and blew everything away and removed restic (apt remove restic).

Second test in this order:

  1. apt-get install restic result : restic 0.12.1 compiled with go1.18.1 on linux/amd64
  2. restic init --repo /mnt/Z/WSL/restic-repo-Jul-09-00 created repository no problems
  3. restic self-update successful: restic 0.16.5 compiled with go1.22.4 on linux/amd64
  4. restic init --repo /mnt/Z/WSL/restic-repo-Jul-09-01 failed this error -

Fatal: create key in repository at /mnt/Z/WSL/restic-repo-Jul-09-01 failed: sync /mnt/Z/WSL/restic-repo-Jul-09-01/keys: input/output error

#4 Created all the directories of restic-repo-Jul-09-01 with permissions 777 root:root. Not a permissions problem

win10 Restic 0.16.5 on the same laptop drive all good, only in the WSL/Ubuntu.virtual machine it fails to create a 0.16.5 repositories.

You can try to post here the output of the debug log (see how to create one) to anticipate what others may ask you to do.

As a side note: I don’t use WSL - I tried once and it messed up the virtualization with Virtualbox, so I gave up and uninstalled it.

Can you please try the second test but replace step #1 with just getting the official restic binary from GitHub releases instead? Using apt to install restic is rather pointless when you self-update it afterwards anyway.

2 Likes

Logs done - I’ve numbered the lines.

1 2024/07/10 10:38:45 restic/main.go:106 main.main 1 main string{“restic”, “init”, “–repo”, “/mnt/Z/WSL/restic-repo-Jul-09-01”}
2 2024/07/10 10:38:45 restic/main.go:107 main.main 1 restic 0.16.5 compiled with go1.22.4 on linux/amd64
3 2024/07/10 10:38:55 restic/global.go:633 main.create 1 parsing location /mnt/Z/WSL/restic-repo-Jul-09-01
4 2024/07/10 10:38:55 restic/global.go:569 main.parseConfig 1 opening local repository at &local.Config{Path:“/mnt/Z/WSL/restic-repo-Jul-09-01”, Layout:“”, Conn ections:0x2}
5 2024/07/10 10:38:55 local/local.go:65 local.Create 1 create local backend at /mnt/Z/WSL/restic-repo-Jul-09-01 (layout “”)
6 2024/07/10 10:38:55 layout/layout.go:139 layout.ParseLayout 1 parse layout string “” for backend at /mnt/Z/WSL/restic-repo-Jul-09-01
7 2024/07/10 10:38:55 layout/layout.go:99 layout.DetectLayout 1 detect layout at /mnt/Z/WSL/restic-repo-Jul-09-01
8 2024/07/10 10:38:55 layout/layout.go:132 layout.DetectLayout 1 layout detection failed
9 2024/07/10 10:38:55 layout/layout.go:156 layout.ParseLayout 1 error: auto-detecting the filesystem layout failed, use default layout default
10 2024/07/10 10:38:55 layout/layout.go:139 layout.ParseLayout 1 parse layout string “default” for backend at /mnt/Z/WSL/restic-repo-Jul-09-01
11 2024/07/10 10:38:55 local/local.go:47 local.open 1 using (0o600 file, 0o700 dir) permissions
12 2024/07/10 10:39:04 index/index.go:382 index.(*Index).Finalize 1 finalizing index
13 2024/07/10 10:39:04 logger/log.go:52 logger.(*Backend).Stat 1 Stat()
14 2024/07/10 10:39:04 sema/semaphore.go:27 sema.semaphore.GetToken 1 acquired token
15 2024/07/10 10:39:04 logger/log.go:54 logger.(*Backend).Stat 1 stat err stat /mnt/Z/WSL/restic-repo-Jul-09-01/config: no such file or directory
16 2024/07/10 10:39:04 logger/log.go:24 logger.(*Backend).IsNotExist 1 IsNotExist(*errors.withStack, stat /mnt/Z/WSL/restic-repo-Jul-09-01/config: no such file or direct ory, true)
17 2024/07/10 10:39:04 restic/config.go:49 restic.CreateConfig 1 New config: restic.Config{Version:0x2, ID:“e1f8a8c42f9cc5cfadfc110a651575c40cc9637063e84c48ee08894ac0935dc 3”, ChunkerPolynomial:0x3500dadde715e3}
18 2024/07/10 10:39:06 repository/key.go:206 repository.AddKey 1 calibrated KDF parameters are {32768 8 5}
19 2024/07/10 10:39:06 logger/log.go:30 logger.(*Backend).Save 1 Save(<key/66c1d6cfe1>, 445)
20 2024/07/10 10:39:06 sema/semaphore.go:27 sema.semaphore.GetToken 1 acquired token
21 2024/07/10 10:39:06 local/local.go:160 local.(*Local).Save 1 Failed to preallocate /mnt/Z/WSL/restic-repo-Jul-09-01/keys/66c1d6cfe185741142036a6f1ba099ce1953bb8635083f 7dd89ba66cb0720f79 with size 445: operation not supported
22 2024/07/10 10:39:06 logger/log.go:32 logger.(*Backend).Save 1 save err sync /mnt/Z/WSL/restic-repo-Jul-09-01/keys: input/output error
23 2024/07/10 10:39:06 restic/cleanup.go:87 main.Exit 1 exiting with status code 1

As for WSL & V’Box cohabiting, haven’t had any problems on my win10 laptop for the last two years but my win10 PC yes. Both identical setup, the PC just can’t handle Solaris as a guest in V’box had to disable WSL.

restic_0.16.5_linux_amd64.bz2 has the same problem.

apt install & update - two commands from the machine - versus…
Go to the URL download it ->Copy it to some where relevant → create a director for the binary → unpack the *.bz2 file → rename restic_0.16.5_linux_amd64 to “restic”

Update after more testing…
This problem only occurs for network shares. The share for backup storage can either be a

  • Windows mapped drive that’s mounted in WSL/Ubuntu by mount -t drvfs Z: /mnt/Z where Z: is the Windows mapped drive of the storage target.
  • OR mounted directly mount -t drvfs ‘\<target IP>\BKUP-RESTIC’ /mnt/Z

The mount point was given permissions 777, so no issues there.

There is something magical about the old restic 12.2 version installed by apt-get. because works.
Restic installed from restic_0.13.0_linux_amd64.bz2, restic_0.14.0_linux_amd64.bz2, restic_0.15.0_linux_amd64.bz2 and restic_0.16.0_linux_amd64.bz2 all fail.

This is a problem of the filesystem mounted into WSL. The “input/output error” occurs when restic tries to ensure that the folder is actually written to disk. I assume that WSL wants to signal that it cannot give that guarantee when the folder is on a network share. However, it returns the wrong error code.

It’s not possible to ignore this error in restic, as IO errors usually indicate that data could not be written and therefore would threaten the integrity of the backup.

Are you using WSL1 or WSL2?

Wouldn’t that apply to any Linux virtual machine running in Hyper-V that has a storage target which mounted by a UNC path? Under the hood WSL2 is Hyper-V.

16.5 will create a functional repository on a USB external HDD (NTFS) connected to the Win10 host and mounted in WSL/Ubuntu as type drvfs, same as a UNC-pathed network share.

If Restic was unsure of the file system it shouldn’t have created the repository director structure and key. It seems to failing to create the config file.

CORRECTION
mount -t drvfs ‘\<target IP>\BKUP-RESTIC’ /mnt/Z should have been
mount -t drvfs ‘\\<target IP>\BKUP-RESTIC’ /mnt/Z

WSL2

$ uname -a
Linux ub1 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux.

Usually CIFS (SMB) shares are directly mounted in the Linux VMs instead of using an indirection through Windows. Directly mounting the CIFS shares is supported.

Well, that’s order in which the repository initialization works. The sync operation (the one resulting in IO errors) is only used when storing files. So it’s not relevant when creating the directory structure.

The solution was simple:
Install cifs-utils and do everything in the fstab file like this:
//<target IP>/L-BKUP-RESTIC /mnt/bkup cifs credentials=/home/jim/.bkupshare,iocharset=utf8 0 0
This successfully created the repository…now to test the rest.

Previously directly mounting cifs shares like…
mount -t drvfs '//<target IP>/L-BKUP-RESTIC' /mnt/Z
also failed with create key problem
mount -t cifs '//<target IP>/L-BKUP-RESTIC' /mnt/Z
completely failed