unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
* bug#43366: "error: rmdir: Device or resource busy" when using btrfs
@ 2020-09-13  3:37 Fredrik Salomonsson
  2020-09-15  4:08 ` bug#43366: [PATCH core-updates] utils: Do not raise exceptions in delete-file-recursively Maxim Cournoyer
  2020-09-15  4:15 ` bug#43366: "error: rmdir: Device or resource busy" when using btrfs Maxim Cournoyer
  0 siblings, 2 replies; 5+ messages in thread
From: Fredrik Salomonsson @ 2020-09-13  3:37 UTC (permalink / raw)
  To: 43366

[-- Attachment #1: Type: text/plain, Size: 2092 bytes --]


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


[-- Attachment #2: Guix system config file --]
[-- Type: text/plain, Size: 4344 bytes --]

;; 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))

[-- Attachment #3: Type: text/plain, Size: 34 bytes --]



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#43366: [PATCH core-updates] utils: Do not raise exceptions in delete-file-recursively.
  2020-09-13  3:37 bug#43366: "error: rmdir: Device or resource busy" when using btrfs Fredrik Salomonsson
@ 2020-09-15  4:08 ` Maxim Cournoyer
  2020-09-15  4:15 ` bug#43366: "error: rmdir: Device or resource busy" when using btrfs Maxim Cournoyer
  1 sibling, 0 replies; 5+ messages in thread
From: Maxim Cournoyer @ 2020-09-15  4:08 UTC (permalink / raw)
  To: 43366; +Cc: Fredrik Salomonsson, Maxim Cournoyer

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=yes, Size: 2196 bytes --]

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





^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#43366: "error: rmdir: Device or resource busy" when using btrfs
  2020-09-13  3:37 bug#43366: "error: rmdir: Device or resource busy" when using btrfs Fredrik Salomonsson
  2020-09-15  4:08 ` bug#43366: [PATCH core-updates] utils: Do not raise exceptions in delete-file-recursively Maxim Cournoyer
@ 2020-09-15  4:15 ` Maxim Cournoyer
  2020-09-15 18:15   ` Fredrik Salomonsson
  2020-10-08 15:44   ` Maxim Cournoyer
  1 sibling, 2 replies; 5+ messages in thread
From: Maxim Cournoyer @ 2020-09-15  4:15 UTC (permalink / raw)
  To: Fredrik Salomonsson; +Cc: 43366

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:

> 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




^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#43366: "error: rmdir: Device or resource busy" when using btrfs
  2020-09-15  4:15 ` bug#43366: "error: rmdir: Device or resource busy" when using btrfs Maxim Cournoyer
@ 2020-09-15 18:15   ` Fredrik Salomonsson
  2020-10-08 15:44   ` Maxim Cournoyer
  1 sibling, 0 replies; 5+ messages in thread
From: Fredrik Salomonsson @ 2020-09-15 18:15 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: 43366

Hi Maxim,

Maxim Cournoyer <maxim.cournoyer@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




^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#43366: "error: rmdir: Device or resource busy" when using btrfs
  2020-09-15  4:15 ` bug#43366: "error: rmdir: Device or resource busy" when using btrfs Maxim Cournoyer
  2020-09-15 18:15   ` Fredrik Salomonsson
@ 2020-10-08 15:44   ` Maxim Cournoyer
  1 sibling, 0 replies; 5+ messages in thread
From: Maxim Cournoyer @ 2020-10-08 15:44 UTC (permalink / raw)
  To: Fredrik Salomonsson; +Cc: 43366-done

Hello,

Pushed to core-updates with commit
7102c18678dc02d5ee6c77a9a70ae344482af841.

Closing.

Thanks,
Maxim




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-08 15:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-13  3:37 bug#43366: "error: rmdir: Device or resource busy" when using btrfs Fredrik Salomonsson
2020-09-15  4:08 ` bug#43366: [PATCH core-updates] utils: Do not raise exceptions in delete-file-recursively Maxim Cournoyer
2020-09-15  4:15 ` bug#43366: "error: rmdir: Device or resource busy" when using btrfs Maxim Cournoyer
2020-09-15 18:15   ` Fredrik Salomonsson
2020-10-08 15:44   ` Maxim Cournoyer

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).