sg3_utils icon indicating copy to clipboard operation
sg3_utils copied to clipboard

rescan-scsi-bus.sh: -r flag unmounts active root disk

Open BenjaminGrayNp1 opened this issue 1 year ago • 3 comments

Passing the -r flag unmounts the active root disk if it's SCSI

[fedora@localhost ~]$ sudo rescan-scsi-bus.sh -r
Syncing file systems
which: no multipath in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/snapd/snap/bin)
Scanning SCSI subsystem for new devices and remove devices that have disappeared
Scanning host 0 for  SCSI target IDs 0 1 2 3 4 5 6 7, all LUNs
 Scanning for device 0 0 2 0 ...           
REM: Host: scsi0 Channel: 00 Id: 02 Lun: 000
      Vendor: IBM      Model: 3303      NVDISK Rev: 0001
      Type:   Direct-Access                    ANSI SCSI revision: 05

Connection to 10.0.0.241 closed by remote host.
Connection to 10.0.0.241 closed.


# system log
[ 6331.532310] EXT4-fs (sda2): shut down requested (2)
[ 6331.532364] Aborting journal on device sda2-8.
[ 6331.532461] device offline error, dev sda, sector 534528 op 0x1:(WRITE) flags 0x800 phys_seg 1 prio class 2
[ 6331.532705] Buffer I/O error on dev sda2, logical block 65536, lost sync page write
[ 6331.532918] JBD2: I/O error when updating journal superblock for sda2-8.
[ 6331.538722] BTRFS error (device sda5): bdev /dev/sda5 errs: wr 1, rd 0, flush 0, corrupt 0, gen 0
[ 6331.538732] BTRFS error (device sda5): bdev /dev/sda5 errs: wr 2, rd 0, flush 0, corrupt 0, gen 0
[ 6331.538847] BTRFS error (device sda5): bdev /dev/sda5 errs: wr 3, rd 0, flush 0, corrupt 0, gen 0
[ 6331.538922] BTRFS error (device sda5): bdev /dev/sda5 errs: wr 4, rd 0, flush 0, corrupt 0, gen 0

This was partially addressed by #10, but there is another location where certain conditions lead to unintended behaviour. The uses of

sg_turs "$sg_turs_opt" /dev/$SGDEV >/dev/null 2>&1

are incorrect if there are no options, as it passes the empty string as the first argument to sg_turs which treats it as the device positional argument. The quotes should be removed (though I don't know if that affects the case where there is an argument).

BenjaminGrayNp1 avatar Dec 20 '23 06:12 BenjaminGrayNp1

I have just mirrored svn revision 1076 here that contains a proposed fix to this case. Place "-t" option rather than "" in $sg_turs_opt . Would appreciate if you could test and send some feedback.

doug-gilbert avatar Dec 21 '23 04:12 doug-gilbert

Sorry for the delay, was on leave.

Taking the rescan-scsi-bus.sh script in commit rescan-scsi-bus.sh: fix for github issue 46 and running it on a Fedora 39 Cloud image works as it should. I can run sudo ./rescan-scsi-bus.sh -a -r and it will add/remove disks as I dynamically mount/unmount them, without removing the root disk anymore.

BenjaminGrayNp1 avatar Jan 08 '24 00:01 BenjaminGrayNp1

My preference would have been to simply remove the double quotes around $sg_turs_opt, which would have been safe, AFAICT. But I'm fine with rev 1076 as-is. Thanks @doug-gilbert for fixing this.

mwilck avatar Jan 08 '24 07:01 mwilck