GNU bug report logs - #43366
"error: rmdir: Device or resource busy" when using btrfs

Previous Next

Package: guix;

Reported by: Fredrik Salomonsson <plattfot <at> posteo.net>

Date: Sun, 13 Sep 2020 04:00:02 UTC

Severity: normal

Tags: patch

Done: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 43366 in the body.
You can then email your comments to 43366 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guix <at> gnu.org:
bug#43366; Package guix. (Sun, 13 Sep 2020 04:00:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Fredrik Salomonsson <plattfot <at> posteo.net>:
New bug report received and forwarded. Copy sent to bug-guix <at> gnu.org. (Sun, 13 Sep 2020 04:00:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Fredrik Salomonsson <plattfot <at> posteo.net>
To: bug-guix <at> gnu.org
Subject: "error: rmdir: Device or resource busy" when using btrfs
Date: Sat, 12 Sep 2020 20:37:35 -0700
[Message part 1 (text/plain, inline)]
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.

I encountered this issue while I tried installing guix system on my main
laptop. But I have encountered this before [1]. When I installed guix
system on my secondary laptop. I worked around it back then by using
guix-0.15.0.

For my secondary laptop I have this layout
| subvol                | Mountpoint | Comment         |
|-----------------------+------------+-----------------|
| __current/guixsd-root | /          | root for GuixSD |
| __current/grub        | /boot/grub | grub config     |
| __current/guix        | /var/guix  | guix stuff      |
| __current/gnu         | /gnu       | Store etc       |
| __current/home        | /home      | home partition  |

For my main laptop I tried:
| subvol | Mountpoint | Comment        |
|--------+------------+----------------|
| @      | /          | root for Guix  |
| @grub  | /boot/grub | grub config    |
| @guix  | /var/guix  | guix stuff     |
| @gnu   | /gnu       | Store etc      |
| @home  | /home      | home partition |

Found another thread that also had this issue [2], and the same
workaround worked for me. I.e. simplified the layout:
| subvol    | Mountpoint | Comment        |
|-----------+------------+----------------|
| @         | /          | root for Guix  |
| @home     | /home      | home partition |

This seems to just be an issue when running guix system init, as I've
been using my secondary laptop with separate subvolumes for /gnu and
/var/guix without any issues since 0.15.

The guix version I used to install my main laptop with was
1.1.0-25.44c6e6f. I generated it with

  guix system disk-image --file-system-type=iso9660 \
       gnu/system/install.scm

As described in the manual.

Thanks

[1] https://lists.gnu.org/archive/html/help-guix/2018-12/msg00055.html
[2] https://lists.gnu.org/archive/html/help-guix/2019-06/msg00259.html

[heimdal-sway.scm (text/plain, attachment)]
[Message part 3 (text/plain, inline)]

-- 
s/Fred[re]+i[ck]+/Fredrik/g

Information forwarded to bug-guix <at> gnu.org:
bug#43366; Package guix. (Tue, 15 Sep 2020 04:09:01 GMT) Full text and rfc822 format available.

Message #8 received at 43366 <at> debbugs.gnu.org (full text, mbox):

From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
To: 43366 <at> debbugs.gnu.org
Cc: Fredrik Salomonsson <plattfot <at> gmail.com>,
 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
Subject: [PATCH core-updates] utils: Do not raise exceptions in
 delete-file-recursively.
Date: Tue, 15 Sep 2020 00:08:37 -0400
This makes it so that delete-file-recursively honors its docstring, which says
it should "report but ignore errors".

Fixes <https://issues.guix.gnu.org/43366>.

* guix/build/utils.scm (warn-on-error): New syntax.
(delete-file-recursively): Use it to catch exceptions and print warning
messages.

Reported-by: Fredrik Salomonsson <plattfot <at> gmail.com>
---
 guix/build/utils.scm | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 0a04032834..fbf4f2d61a 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -6,6 +6,7 @@
 ;;; Copyright © 2018 Arun Isaac <arunisaac <at> systemreboot.net>
 ;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado <at> elephly.net>
 ;;; Copyright © 2020 Efraim Flashner <efraim <at> flashner.co.il>
+;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -366,6 +367,16 @@ verbose output to the LOG port."
                         stat
                         lstat)))
 
+(define-syntax-rule (warn-on-error expr file)
+  (catch 'system-error
+    (lambda ()
+      expr)
+    (lambda args
+      (format (current-error-port)
+              "warning: failed to delete ~a: ~a~%"
+              file (strerror
+                    (system-error-errno args))))))
+
 (define* (delete-file-recursively dir
                                   #:key follow-mounts?)
   "Delete DIR recursively, like `rm -rf', without following symlinks.  Don't
@@ -376,10 +387,10 @@ errors."
                         (or follow-mounts?
                             (= dev (stat:dev stat))))
                       (lambda (file stat result)   ; leaf
-                        (delete-file file))
+                        (warn-on-error (delete-file file) file))
                       (const #t)                   ; down
                       (lambda (dir stat result)    ; up
-                        (rmdir dir))
+                        (warn-on-error (rmdir dir) dir))
                       (const #t)                   ; skip
                       (lambda (file stat errno result)
                         (format (current-error-port)
-- 
2.28.0





Information forwarded to bug-guix <at> gnu.org:
bug#43366; Package guix. (Tue, 15 Sep 2020 04:16:01 GMT) Full text and rfc822 format available.

Message #11 received at 43366 <at> debbugs.gnu.org (full text, mbox):

From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
To: Fredrik Salomonsson <plattfot <at> posteo.net>
Cc: 43366 <at> debbugs.gnu.org
Subject: Re: bug#43366: "error: rmdir: Device or resource busy" when using
 btrfs
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 <plattfot <at> posteo.net> 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




Information forwarded to bug-guix <at> gnu.org:
bug#43366; Package guix. (Tue, 15 Sep 2020 18:24:02 GMT) Full text and rfc822 format available.

Message #14 received at 43366 <at> debbugs.gnu.org (full text, mbox):

From: Fredrik Salomonsson <plattfot <at> posteo.net>
To: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
Cc: 43366 <at> debbugs.gnu.org
Subject: Re: bug#43366: "error: rmdir: Device or resource busy" when using
 btrfs
Date: Tue, 15 Sep 2020 11:15:40 -0700
Hi Maxim,

Maxim Cournoyer <maxim.cournoyer <at> gmail.com> writes:

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

Nice find! I'm unable to test out the patch right now on my original use
case as I soft bricked my laptop fiddling around with coreboot. And I'm
having some issues with my external flasher.

> 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 :-).

Yay!

> 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.

Yeah, that's is the same error I get when running guix init. So this
sounds like it will fix my issue!

Thanks for the speedy fix.

-- 
s/Fred[re]+i[ck]+/Fredrik/g




Added tag(s) patch. Request was from Maxim Cournoyer <maxim.cournoyer <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 18 Sep 2020 03:00:03 GMT) Full text and rfc822 format available.

Reply sent to Maxim Cournoyer <maxim.cournoyer <at> gmail.com>:
You have taken responsibility. (Thu, 08 Oct 2020 15:45:02 GMT) Full text and rfc822 format available.

Notification sent to Fredrik Salomonsson <plattfot <at> posteo.net>:
bug acknowledged by developer. (Thu, 08 Oct 2020 15:45:02 GMT) Full text and rfc822 format available.

Message #21 received at 43366-done <at> debbugs.gnu.org (full text, mbox):

From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
To: Fredrik Salomonsson <plattfot <at> posteo.net>
Cc: 43366-done <at> debbugs.gnu.org
Subject: Re: bug#43366: "error: rmdir: Device or resource busy" when using
 btrfs
Date: Thu, 08 Oct 2020 11:44:10 -0400
Hello,

Pushed to core-updates with commit
7102c18678dc02d5ee6c77a9a70ae344482af841.

Closing.

Thanks,
Maxim




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 06 Nov 2020 12:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 165 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.