Subject: Re: bug#43366: "error: rmdir: Device or resource busy" when using btrfs

From: Maxim Cournoyer <[email-masked]>
Date: Tue, 15 Sep 2020 00:15:46 -0400

Hi Fredrik,

I just sent a patch now, but here's a bit more background on what led to
it.

Fredrik Salomonsson <[email-masked]> writes:

> When you have separate btrfs subvolumes for /gnu and /var/guix, you'll
> encounter this error running `guix system init /mnt/etc/config.scm /mnt`
> when it tries to copy things to /mnt. My guess is that guix is trying to
> remove one of them but fails as they're mounted.

The issue seems to be with:

--8<---------------cut here---------------start------------->8---
  ;; If a previous installation was attempted, make sure we start anew; in
  ;; particular, we don't want to keep a store database that might not
  ;; correspond to what we're actually putting in the store.
  (let ((state (string-append target "/var/guix")))
    (when (file-exists? state)
      (delete-file-recursively state)))
--8<---------------cut here---------------end--------------->8---

Which is part of the install procedure (which gets called when using
'guix system init /some/target').  So your guess was correct :-).

To confirm this was the case, I did:

sudo btrfs subvolume create /tmp/toto
mkdir /tmp/tata
sudo mount -o subvol=/tmp/toto /dev/mapper/cryptroot /tmp/tata

sudo -E guix repl
> ,import (guix build utils)
> (delete-file-recursively "/tmp/tata/")
ice-9/boot-9.scm:1669:16: In procedure raise-exception:
In procedure rmdir: Device or resource busy

Bingo!

Reading the docstring of delete-file-recursively, it says it should
"report but ignore errors", so that's a bug.

Maxim