Package: systemd
Version: 261.1-2
Severity: important
X-Debbugs-Cc: [email protected]

= Steps to reproduce =

0. Let's assume we have a block device with some partitions on it:
```
$ lsblk /dev/nbd0
NAME     MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
nbd0      43:0    0   20G  0 disk
├─nbd0p1  43:1    0  100M  0 part
└─nbd0p2  43:2    0 19.9G  0 part
```

1. Create a filesystem on one of the partitions:
```
$ sudo mkfs.ext4 /dev/nbd0p2
mke2fs 1.47.2 (1-Jan-2025)
Discarding device blocks: done
Creating filesystem with 5216768 4k blocks and 1305600 inodes
Filesystem UUID: a052641a-2c21-4ce2-aaff-8d37145822d8
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
```

2. mount the newly created filesystem somewhere and create a folder inside it:
```
$ mkdir mnt
$ sudo mount -o relatime /dev/nbd0p2 mnt/
$ sudo mkdir mnt/dev
```

3. bind /dev hierarchy to the newly created folder:
```
$ sudo mount --rbind --make-rslave /dev mnt/dev/
```

4. recursively umount the partition:
```
$ sudo umount -R mnt
```

= Expected result =

The partition's underlying device should not be in use.

= Actual result =

systemd latches onto the device:
```
$ sudo mkfs.ext4 /dev/nbd0p2
mke2fs 1.47.2 (1-Jan-2025)
/dev/nbd0p2 is apparently in use by the system; will not make a filesystem
here!
```

Additionally in case of nbd devices, an attempt to disconnect causes I/O
errors:
```
$ sudo qemu-nbd --disconnect /dev/nbd0
/dev/nbd0 disconnected
morgwai@vm-trixie:~/systemd-sux$ journalctl --since=2026-07-03T22:15
--until=2026-07-03T22:16
Jul 03 22:15:20 vm-trixie sudo[3642]:  morgwai : TTY=pts/0 ;
PWD=/home/morgwai/systemd-sux ; USER=root ; COMMAND=/usr/bin/qemu-nbd
--disconnect /dev/nbd0
Jul 03 22:15:20 vm-trixie sudo[3642]: pam_unix(sudo:session): session opened
for user root(uid=0) by morgwai(uid=1000)
Jul 03 22:15:20 vm-trixie kernel: block nbd0: NBD_DISCONNECT
Jul 03 22:15:20 vm-trixie kernel: block nbd0: Disconnected due to user request.
Jul 03 22:15:20 vm-trixie kernel: block nbd0: shutting down sockets
Jul 03 22:15:20 vm-trixie sudo[3642]: pam_unix(sudo:session): session closed
for user root
Jul 03 22:15:20 vm-trixie kernel: I/O error, dev nbd0, sector 0 op 0x0:(READ)
flags 0x80700 phys_seg 16 prio class 2
Jul 03 22:15:20 vm-trixie kernel: I/O error, dev nbd0, sector 0 op 0x0:(READ)
flags 0x800000 phys_seg 1 prio class 2
Jul 03 22:15:20 vm-trixie kernel: Buffer I/O error on dev nbd0, logical block
0, async page read
Jul 03 22:15:20 vm-trixie kernel: I/O error, dev nbd0, sector 2048 op
0x0:(READ) flags 0x80700 phys_seg 16 prio class 2
Jul 03 22:15:20 vm-trixie kernel: I/O error, dev nbd0, sector 2048 op
0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
Jul 03 22:15:20 vm-trixie kernel: Buffer I/O error on dev nbd0p1, logical block
0, async page read
Jul 03 22:15:20 vm-trixie kernel: I/O error, dev nbd0, sector 0 op 0x0:(READ)
flags 0x800000 phys_seg 1 prio class 2
Jul 03 22:15:20 vm-trixie kernel: Buffer I/O error on dev nbd0, logical block
0, async page read
Jul 03 22:15:20 vm-trixie kernel: I/O error, dev nbd0, sector 0 op 0x0:(READ)
flags 0x800000 phys_seg 1 prio class 2
Jul 03 22:15:20 vm-trixie kernel: Buffer I/O error on dev nbd0, logical block
0, async page read
Jul 03 22:15:20 vm-trixie udisksd[961]: Partitions found on device '/dev/nbd0'
but couldn't read partition table signature: Failed to assign the new context
to disk '/dev/nbd0': Input/output error
Jul 03 22:15:20 vm-trixie udisksd[961]: Partitions found on device '/dev/nbd0'
but couldn't read partition table signature: Failed to assign the new context
to disk '/dev/nbd0': Input/output error
Jul 03 22:15:20 vm-trixie kernel: I/O error, dev nbd0, sector 206880 op
0x0:(READ) flags 0x80700 phys_seg 8 prio class 2
Jul 03 22:15:20 vm-trixie kernel: I/O error, dev nbd0, sector 206880 op
0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
Jul 03 22:15:20 vm-trixie kernel: Buffer I/O error on dev nbd0p2, logical block
4, async page read
Jul 03 22:15:20 vm-trixie kernel: I/O error, dev nbd0, sector 41940864 op
0x0:(READ) flags 0x80700 phys_seg 11 prio class 2
Jul 03 22:15:20 vm-trixie kernel: I/O error, dev nbd0, sector 41940864 op
0x0:(READ) flags 0x800000 phys_seg 1 prio class 2
Jul 03 22:15:20 vm-trixie kernel: Buffer I/O error on dev nbd0p2, logical block
5216752, async page read
Jul 03 22:15:20 vm-trixie kernel: Buffer I/O error on dev nbd0, logical block
0, async page read
Jul 03 22:15:20 vm-trixie kernel: Buffer I/O error on dev nbd0, logical block
0, async page read
Jul 03 22:15:20 vm-trixie kernel: Buffer I/O error on dev nbd0, logical block
0, async page read
Jul 03 22:15:20 vm-trixie kernel: Buffer I/O error on dev nbd0p1, logical block
0, async page read
```

From then on, the nbd device becomes unusable: attempts to connect it to a
qcow2 file result in subsequent I/O errors.

This also affects physical removable devices in a similar way, preventing their
clean removal:
```
$ sudo eject /dev/sda
eject: cannot open /dev/sda: Device or resource busy
```

Disconnecting produces the following errors in logs:
```
Jul 05 04:27:21 morgwai-x4tuxedo kernel: usb 3-2: USB disconnect, device number
5
Jul 05 04:27:21 morgwai-x4tuxedo kernel: EXT4-fs (sda5): shut down requested
(2)
Jul 05 04:27:21 morgwai-x4tuxedo kernel: Aborting journal on device sda5-8.
Jul 05 04:27:21 morgwai-x4tuxedo kernel: device offline error, dev sda, sector
126885888 op 0x1:(WRITE) flags 0x9800 phys_seg 1 prio class 2
Jul 05 04:27:21 morgwai-x4tuxedo kernel: Buffer I/O error on dev sda5, logical
block 1081344, lost sync page write
Jul 05 04:27:21 morgwai-x4tuxedo kernel: JBD2: I/O error when updating journal
superblock for sda5-8.
```

On Devuan Excalibur this works perfectly fine, so this seems to be a systemd
issue.


-- Package-specific info:

-- System Information:
Debian Release: 13.5
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 
'stable'), (90, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 7.1.1+tbfive2-amd64 (SMP w/24 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE, 
TAINT_UNSIGNED_MODULE
Locale: LANG=en_IE.UTF-8, LC_CTYPE=en_IE.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_IE:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages systemd depends on:
ii  libacl1            2.3.2-2+b1
ii  libapparmor1       4.1.0-1
ii  libc6              2.41-12+deb13u3
ii  libmount1          2.41-5
ii  libpam0g           1.7.0-5
ii  libseccomp2        2.6.0-2
ii  libselinux1        3.8.1-1
ii  libssl3t64         3.5.6-1~deb13u2
ii  libsystemd-shared  257.13-1~deb13u1
ii  libsystemd0        257.13-1~deb13u1
ii  mount              2.41-5

Versions of packages systemd recommends:
ii  dbus [default-dbus-system-bus]   1.16.2-2
ii  linux-sysctl-defaults            4.12.1
ii  systemd-cryptsetup               257.13-1~deb13u1
ii  systemd-timesyncd [time-daemon]  257.13-1~deb13u1

Versions of packages systemd suggests:
ii  libtss2-tcti-device0t64 [libtss2-tcti-device0]  4.1.3-1.2
ii  polkitd                                         126-2
pn  systemd-boot                                    <none>
ii  systemd-container                               257.13-1~deb13u1
pn  systemd-homed                                   <none>
pn  systemd-repart                                  <none>
pn  systemd-resolved                                <none>
pn  systemd-userdbd                                 <none>

Versions of packages systemd is related to:
ii  dbus-user-session  1.16.2-2
pn  dracut             <none>
ii  initramfs-tools    0.148.4
ii  libnss-systemd     257.13-1~deb13u1
ii  libpam-systemd     257.13-1~deb13u1
ii  udev               257.13-1~deb13u1

-- no debconf information

Reply via email to