"error: rmdir: Device or resource busy" when using btrfs

  • Done
  • quality assurance status badge
Details
2 participants
  • Maxim Cournoyer
  • Fredrik Salomonsson
Owner
unassigned
Submitted by
Fredrik Salomonsson
Severity
normal
F
F
Fredrik Salomonsson wrote on 13 Sep 2020 05:37
(address . bug-guix@gnu.org)
87v9gi5ou8.fsf@posteo.net
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

;; This is an operating system configuration template ;; for a "desktop" setup without full-blown desktop ;; environments. (use-modules (gnu) (gnu packages) (gnu system nss) (gnu system locale) (gnu services nfs) (gnu services sddm) (ice-9 rdelim) (ice-9 format) (srfi srfi-1)) (use-service-modules desktop networking ssh base xorg) (use-package-modules wm certs shells xdisorg display-managers) (define plattfot (user-account (name "plattfot") (group "users") ;; Define a G-Expr to find the path of the zsh binary: ;; https://gitlab.com/rain1/guix-wiki/wikis/FAQ#how-do-i-make-my-login-shell-zsh ;;(shell #~(string-append #$zsh "/bin/zsh")) (supplementary-groups '("wheel" "netdev" "audio" "video")) (home-directory "/home/plattfot"))) ;; Specify a mapped device for the encrypted root partition. ;; The UUID is that returned by 'cryptsetup luksUUID'. (define mapped-swap (mapped-device (source (uuid "3f1a433f-e3d5-46f1-8471-b0cfee72a659")) (target "swap") (type luks-device-mapping))) (define mapped-root (mapped-device (source (uuid "0633603e-019c-4be0-b35e-abb055660909")) (target "root") (type luks-device-mapping))) ;; Partion layout for `root` ;; | subvol | Mountpoint | Comment | Shared | ;; |-----------+------------+--------------------+--------| ;; | @ | / | root for Guix | no | ;; | @home | /home | home partition | yes | (define btrfs-common-options '("discard" "compress=lzo" "space_cache" "autodefrag")) (define (btrfs-mount-options subvol) "Return the btrfs mount options I use. Where SUBVOL is the subvolume to mount" (string-join `(,@btrfs-common-options ,(format #f "subvol=~a" subvol)) ",")) (define fs-root (file-system (mount-point "/") (type "btrfs") (device (file-system-label "root")) (options (btrfs-mount-options "@")) (needed-for-boot? #t) (dependencies `(,mapped-root)))) (define fs-home (file-system (mount-point "/home") (type "btrfs") (device (file-system-label "root")) (options (btrfs-mount-options "@home")) (needed-for-boot? #t) (dependencies `(,fs-root)))) (define nfs-valhalla (file-system (device "fafner:/srv/nfs4/Valhalla") (mount-point "/media/Valhalla") (type "nfs4") (mount? #f) (check? #f))) (operating-system (host-name "heimdal") (timezone "Canada/Pacific") (locale "en_US.utf8") (locale-definitions (list (locale-definition (name "en_US.utf8") (source "en_US") (charset "UTF-8")) (locale-definition (name "sv_SE.utf8") (source "sv_SE") (charset "UTF-8")))) ;; Assuming /dev/sda is the target hard disk, and "root" ;; is the label of the target root file system. (bootloader (grub-configuration (target "/dev/sda"))) ;; Kernel arguments (kernel-arguments '("rootflags=compress=lzo,subvol=@")) (mapped-devices (list mapped-root mapped-swap)) (file-systems (cons* fs-root fs-home nfs-valhalla %base-file-systems)) (swap-devices '("/dev/mapper/swap")) (users (cons plattfot %base-user-accounts)) (keyboard-layout (keyboard-layout "us" #:options '("ctrl:swapcaps"))) (packages (cons* sway waybar rofi guix-simplyblack-sddm-theme ;;zsh nss-certs ;for HTTPS access %base-packages)) ;; Use the "desktop" services, which include the X11 ;; log-in service, networking with Wicd, and more. (services ;;%desktop-services (cons* (service openssh-service-type (openssh-configuration (port-number 6060) (password-authentication? #f))) (extra-special-file "/bin/env" (file-append coreutils "/bin/env")) (service sddm-service-type (sddm-configuration (display-server "wayland") (theme "guix-simplyblack-sddm"))) (remove (lambda (service) (member (service-kind service) (list gdm-service-type ))) %desktop-services))) ;; Allow resolution of '.local' host names with mDNS. (name-service-switch %mdns-host-lookup-nss))
--
s/Fred[re]+i[ck]+/Fredrik/g
M
M
Maxim Cournoyer wrote on 15 Sep 2020 06:08
[PATCH core-updates] utils: Do not raise exceptions in delete-file-recursively.
(address . 43366@debbugs.gnu.org)
20200915040837.26098-1-maxim.cournoyer@gmail.com
This makes it so that delete-file-recursively honors its docstring, which says
it should "report but ignore errors".


* 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@gmail.com>
---
guix/build/utils.scm | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

Toggle diff (44 lines)
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@systemreboot.net>
;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@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
M
M
Maxim Cournoyer wrote on 15 Sep 2020 06:15
Re: bug#43366: "error: rmdir: Device or resource busy" when using btrfs
(name . Fredrik Salomonsson)(address . plattfot@posteo.net)(address . 43366@debbugs.gnu.org)
87wo0v3cb1.fsf@gmail.com
Hi Fredrik,

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

Fredrik Salomonsson <plattfot@posteo.net> writes:

Toggle quote (5 lines)
> 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:

Toggle snippet (8 lines)
;; 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)))

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
Toggle quote (2 lines)
> ,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
F
F
Fredrik Salomonsson wrote on 15 Sep 2020 20:15
(name . Maxim Cournoyer)(address . maxim.cournoyer@gmail.com)(address . 43366@debbugs.gnu.org)
87sgbi9a9f.fsf@posteo.net
Hi Maxim,

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

Toggle quote (3 lines)
> 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.

Toggle quote (14 lines)
> 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!

Toggle quote (17 lines)
> 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
M
M
Maxim Cournoyer wrote on 18 Sep 2020 05:00
control message for bug #43366
(address . control@debbugs.gnu.org)
87k0wrzt4n.fsf@gmail.com
tags 43366 + patch
quit
M
M
Maxim Cournoyer wrote on 8 Oct 2020 17:44
Re: bug#43366: "error: rmdir: Device or resource busy" when using btrfs
(name . Fredrik Salomonsson)(address . plattfot@posteo.net)(address . 43366-done@debbugs.gnu.org)
87sgaou3hx.fsf@gmail.com
Hello,

Pushed to core-updates with commit
7102c18678dc02d5ee6c77a9a70ae344482af841.

Closing.

Thanks,
Maxim
Closed
?