Fix-usb-sleep icon indicating copy to clipboard operation
Fix-usb-sleep copied to clipboard

Add support for internal SD card reader, a.k.a. "Baseqi Ninja disk"

Open OldManLink opened this issue 6 years ago • 52 comments

I found this project after getting the Disk Not Ejected Properly error for my Baseqi Ninja disk. This is an internal "disk" that uses the SD card reader on my MacBook Pro. Here are the details of the disk when it is mounted:

   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *196.9 GB   disk2
   1:                        EFI EFI                     209.7 MB   disk2s1
   2:                  Apple_HFS Baseqi Ninja            196.5 GB   disk2s2

Would it be possible to extend Fix-usb-sleep to work for this disk also? I have of course tried it, but it did not help with the problem.

OldManLink avatar Aug 21 '18 12:08 OldManLink

@OldManLink Thank you for your information, in short, the answer is yes. But would you mind provide more information about your SD slot? In terminal type in

diskutil info disk2
diskutil info disk2s1
diskutil info disk2s2

Thank you in advance, syscl

syscl avatar Aug 29 '18 17:08 syscl

It will be my pleasure to help fix this in any way I can! Here is the requested info, part 1:

19:20 $ diskutil info disk2
   Device Identifier:        disk2
   Device Node:              /dev/disk2
   Whole:                    Yes
   Part of Whole:            disk2
   Device / Media Name:      SD Card Reader

   Volume Name:              Not applicable (no file system)
   Mounted:                  Not applicable (no file system)
   File System:              None

   Content (IOContent):      GUID_partition_scheme
   OS Can Be Installed:      No
   Media Type:               Generic
   Protocol:                 USB
   SMART Status:             Not Supported

   Disk Size:                196.9 GB (196865949696 Bytes) (exactly 384503808 512-Byte-Units)
   Device Block Size:        512 Bytes

   Read-Only Media:          No
   Read-Only Volume:         Not applicable (no file system)

   Device Location:          Internal
   Removable Media:          Removable
   Media Removal:            Software-Activated

   Virtual:                  No
   OS 9 Drivers:             No
   Low Level Format:         Not supported

part 2:

19:21 $ diskutil info disk2s1
   Device Identifier:        disk2s1
   Device Node:              /dev/disk2s1
   Whole:                    No
   Part of Whole:            disk2

   Volume Name:              EFI
   Mounted:                  No

   Partition Type:           EFI
   File System Personality:  MS-DOS FAT32
   Type (Bundle):            msdos
   Name (User Visible):      MS-DOS (FAT32)

   OS Can Be Installed:      No
   Media Type:               Generic
   Protocol:                 USB
   SMART Status:             Not Supported
   Volume UUID:              0E239BC6-F960-3107-89CF-1C97F78BB46B
   Disk / Partition UUID:    7D4F0DC1-CFA9-4A2B-8C83-C74636C7DA13

   Disk Size:                209.7 MB (209715200 Bytes) (exactly 409600 512-Byte-Units)
   Device Block Size:        512 Bytes

   Volume Total Space:       0 B (0 Bytes) (exactly 0 512-Byte-Units)
   Volume Available Space:   0 B (0 Bytes) (exactly 0 512-Byte-Units)

   Read-Only Media:          No
   Read-Only Volume:         Not applicable (not mounted)

   Device Location:          Internal
   Removable Media:          Removable
   Media Removal:            Software-Activated

and part 3:

19:21 $ diskutil info disk2s2
   Device Identifier:        disk2s2
   Device Node:              /dev/disk2s2
   Whole:                    No
   Part of Whole:            disk2

   Volume Name:              Baseqi Ninja
   Mounted:                  Yes
   Mount Point:              /Volumes/Baseqi Ninja

   Partition Type:           Apple_HFS
   File System Personality:  Journaled HFS+
   Type (Bundle):            hfs
   Name (User Visible):      Mac OS Extended (Journaled)
   Journal:                  Journal size 16384 KB at offset 0x5bb000
   Owners:                   Disabled

   OS Can Be Installed:      Yes
   Media Type:               Generic
   Protocol:                 USB
   SMART Status:             Not Supported
   Volume UUID:              99944A2F-20C2-38BD-863F-DBFD8AA70ADF
   Disk / Partition UUID:    7CF06232-39CE-4D25-A6FE-46A9EE7C3F1F

   Disk Size:                196.5 GB (196521975808 Bytes) (exactly 383831984 512-Byte-Units)
   Device Block Size:        512 Bytes

   Volume Total Space:       196.5 GB (196521975808 Bytes) (exactly 383831984 512-Byte-Units)
   Volume Used Space:        7.8 GB (7755063296 Bytes) (exactly 15146608 512-Byte-Units) (3.9%)
   Volume Available Space:   188.8 GB (188766912512 Bytes) (exactly 368685376 512-Byte-Units) (96.1%)
   Allocation Block Size:    4096 Bytes

   Read-Only Media:          No
   Read-Only Volume:         No

   Device Location:          Internal
   Removable Media:          Removable
   Media Removal:            Software-Activated

If there's anything else you need to know, please do not hesitate to ask!

OldManLink avatar Aug 29 '18 17:08 OldManLink

Thank you, I will add the SD support now.

syscl avatar Aug 29 '18 17:08 syscl

@OldManLink Could you please provide the log by running the script directly by typing

sudo /etc/sysclusbfix.sleep

Note: please insert your SD card as well.

syscl

syscl avatar Aug 29 '18 17:08 syscl

This is what happens:

19:37 $ sudo /etc/sysclusbfix.sleep
Disk disk2 ejected
usage: ioreg [-abfilrtx] [-c class] [-d depth] [-k key] [-n name] [-p plane] [-w width]
where options are:
	-a archive output
	-b show object name in bold
	-c list properties of objects with the given class
	-d limit tree to the given depth
	-f enable smart formatting
	-i show object inheritance
	-k list properties of objects with the given key
	-l list properties of all objects
	-n list properties of objects with the given name
	-p traverse registry over the given plane (IOService is default)
	-r show subtrees rooted by the given criteria
	-t show location of each subtree
	-w clip output to the given line width (0 is unlimited)
	-x show data and numbers as hexadecimal
/etc/sysclusbfix.sleep: line 47: [: too many arguments
/etc/sysclusbfix.sleep: line 53: /Applications/Wireless Network Utility.app/rfoff.rtl: No such file or directory
The file /Applications/Wireless Network Utility.app does not exist.
✘-1 ~/CodeRoot/other/sleepFix [master L|✔] 
19:37 $ 

Now the disk icon has gone from the desktop, so it looks like it was ejected OK. However I am not sure what to do to get it back again.

OldManLink avatar Aug 29 '18 17:08 OldManLink

Remount it by the following

sudo /etc/sysclusbfix.wake

syscl avatar Aug 29 '18 17:08 syscl

Unfortunately that does not work:

19:37 $ sudo /etc/sysclusbfix.wake
Unable to find disk for disk2s2
usage: ioreg [-abfilrtx] [-c class] [-d depth] [-k key] [-n name] [-p plane] [-w width]
where options are:
	-a archive output
	-b show object name in bold
	-c list properties of objects with the given class
	-d limit tree to the given depth
	-f enable smart formatting
	-i show object inheritance
	-k list properties of objects with the given key
	-l list properties of all objects
	-n list properties of objects with the given name
	-p traverse registry over the given plane (IOService is default)
	-r show subtrees rooted by the given criteria
	-t show location of each subtree
	-w clip output to the given line width (0 is unlimited)
	-x show data and numbers as hexadecimal
/etc/sysclusbfix.wake: line 22: [: too many arguments
/etc/sysclusbfix.wake: line 28: /Applications/Wireless Network Utility.app/rfoff.rtl: No such file or directory
The file /Applications/Wireless Network Utility.app does not exist.
✘-1 ~/CodeRoot/other/sleepFix [master L|✔] 
19:42 $ 

OldManLink avatar Aug 29 '18 17:08 OldManLink

@OldManLink It seems there's some error, please give me a cat of the sleep script by

cat /etc/sysclusbfix.sleep

syscl

syscl avatar Aug 29 '18 17:08 syscl

How about

diskutil list

syscl avatar Aug 29 '18 17:08 syscl

Here you go:

19:42 $ cat /etc/sysclusbfix.sleep
#!/bin/sh
#
# This script aims to unmount all external devices automatically before sleep.
#
# Without this procedure, various computers with OS X/Mac OS X(even on a real Mac) suffer from "Disk not ejected properly"
# issue when therere external devices plugged-in. Thats the reason why I created this script to fix this issue. (syscl/lighting/Yating Zhou)
#
# All credit to Bernhard Baehr ([email protected]), without his great sleepwatcher dameon, this fix will not be created.
#

#
# Added unmount Disk for "OS X" (c) syscl/lighting/Yating Zhou.
#
gMountPartition="/tmp/com.syscl.externalfix"
gDisk=($(diskutil list |grep -i -i "dev" |grep -i -o "disk[0-9]"))

for ((i=0; i<${#gDisk[@]}; ++i))
do
  gProtocol=$(diskutil info ${gDisk[i]} |grep -i "Protocol" |sed -e "s|Protocol:||" -e "s| ||g")
  if [[ ${gProtocol} == *"USB"* ]];
    then
      gCurrent_Partitions=($(diskutil list ${gDisk[i]} |grep -o "disk[0-9]s[0-9]"))
      for ((k=0; k<${#gCurrent_Partitions[@]}; ++k))
      do
        gConfirm_Mounted=$(diskutil info ${gCurrent_Partitions[k]} |grep -i Mounted |sed -e "s| Mounted:||" -e "s| ||g")
        if [[ ${gConfirm_Mounted} == *"Yes"* ]];
          then
            echo ${gCurrent_Partitions[k]} >> ${gMountPartition}
        fi
      done
      diskutil eject ${gDisk[i]}
  fi
done


#
# Fix RTLWlanUSB sleep problem credit B1anker & syscl/lighting/Yating Zhou. @PCBeta.
#

gRTWlan_kext=
gMAC_adr=$(ioreg -rc $gRTWlan_kext | sed -n "/IOMACAddress/ s/.*= <\(.*\)>.*/\1/ p")

if [[ "$gMAC_adr" != 0 ]];
  then
    gRT_Config="/Applications/Wireless Network Utility.app"/${gMAC_adr}rfoff.rtl

    if [ ! -f $gRT_Config ];
      then
        gRT_Config=$(ls "/Applications/Wireless Network Utility.app"/*rfoff.rtl)
    fi

    osascript -e 'quit app "Wireless Network Utility"'
    echo "1" > "$gRT_Config"
    open "/Applications/Wireless Network Utility.app"
fi
✔ ~/CodeRoot/other/sleepFix [master L|✔] 
19:43 $ 

OldManLink avatar Aug 29 '18 17:08 OldManLink

And this:

19:43 $ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage Macintosh SSD           999.7 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3

/dev/disk1 (internal, virtual):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Macintosh SSD          +999.3 GB   disk1
                                 Logical Volume on disk0s2
                                 F0CF6AA4-CACC-4F43-A027-547271C2E57E
                                 Unlocked Encrypted

✔ ~/CodeRoot/other/sleepFix [master L|✔] 
19:43 $ 

OldManLink avatar Aug 29 '18 17:08 OldManLink

@OldManLink Hmm, the whole disk2 has disappeared, weird. How about sleep the laptop for a while then check if the disk2 reappear again?

syscl avatar Aug 29 '18 17:08 syscl

OK, I will sleep the laptop for one minute and then wake it up again to see what happens.

OldManLink avatar Aug 29 '18 17:08 OldManLink

Done: still no disk on the desktop, and the result of diskutil list appears to be the same:

19:44 $ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage Macintosh SSD           999.7 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3

/dev/disk1 (internal, virtual):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Macintosh SSD          +999.3 GB   disk1
                                 Logical Volume on disk0s2
                                 F0CF6AA4-CACC-4F43-A027-547271C2E57E
                                 Unlocked Encrypted

✔ ~/CodeRoot/other/sleepFix [master L|✔] 
19:48 $ 

OldManLink avatar Aug 29 '18 17:08 OldManLink

So after executing sysclusbfix.sleep, the whole disk2 disappear?

syscl avatar Aug 29 '18 17:08 syscl

I only did what you suggested, i.e. sleep the laptop and wake it up a minute later. I have not executed any scripts yet after that.

OldManLink avatar Aug 29 '18 17:08 OldManLink

If you like I could reboot the laptop and see if the disk comes back. Or if there's a better way, I'd love to know it!

OldManLink avatar Aug 29 '18 17:08 OldManLink

@OldManLink Sounds good, thank you. I want to improve my program so that you can enjoy it as well!

syscl avatar Aug 29 '18 17:08 syscl

Please let me know if reboot resolve the disk disappear issue.

syscl avatar Aug 29 '18 17:08 syscl

Alright. I will reboot the laptop and I expect to answer here again in about five minutes.

OldManLink avatar Aug 29 '18 17:08 OldManLink

No worry.

syscl avatar Aug 29 '18 17:08 syscl

OK, I am back, and so is the SD disk. I await your next instructions!

OldManLink avatar Aug 29 '18 17:08 OldManLink

OK, I update my Fix-usb-script a bit, would you mind give it a try, the latest version should get rid of the RTWlan issue if you don't have the related kext. And the code should be a bit different after you execute the fixUSB.sh, please let me know if the new sysclusbfix.sh change by the following

cat /etc/sysclusbfix.sleep

thank you.

syscl avatar Aug 29 '18 18:08 syscl

We will then try to resolve the SD card eject issue.

syscl avatar Aug 29 '18 18:08 syscl

I'll just put everything here in one block:

Last login: Wed Aug 29 19:58:16 on console
✔ ~ 
19:58 $ cd CodeRoot/other/sleepFix/
✔ ~/CodeRoot/other/sleepFix [master L|✔] 
20:03 $ git remupp
Fetching origin
✔ ~/CodeRoot/other/sleepFix [master ↓·1|✔] 
20:03 $ git pull
Updating 1a0916a..7dc4273
Fast-forward
 fixUSB.sh | 4 ++++
 1 file changed, 4 insertions(+)
✔ ~/CodeRoot/other/sleepFix [master L|✔] 
20:03 $ ./fixUSB.sh 
[  OK  ]  Generate configuration file of sleepwatcher launch daemon.
[  OK  ]  Generating script to unmount external devices before sleep (c) syscl/lighting/Yating Zhou.
[  OK  ]  Generate script to load RTWlanUSB upon sleep.
[ ---> ]  Installing external devices sleep patch...
Password:
[  OK  ]  Install sleepwatcher daemon.
[  OK  ]  Install configuration of sleepwatcher daemon.
[  OK  ]  Install sleep script.
[  OK  ]  Install wake script.
[  OK  ]  Fix the permissions of /etc/sysclusbfix.sleep.
[  OK  ]  Fix the permissions of /etc/sysclusbfix.wake.
[  OK  ]  Trigger startup service of syscl.usb.fix.
[  OK  ]  Clean up.
[ Note ]  DONE! Sleep to see change.
[ Note ]  Feel free to post issue on https://github.com/syscl/Fix-usb-sleep.
✔ ~/CodeRoot/other/sleepFix [master L|✔] 
20:04 $ cat /etc/sysclusbfix.sleep
#!/bin/sh
#
# This script aims to unmount all external devices automatically before sleep.
#
# Without this procedure, various computers with OS X/Mac OS X(even on a real Mac) suffer from "Disk not ejected properly"
# issue when therere external devices plugged-in. Thats the reason why I created this script to fix this issue. (syscl/lighting/Yating Zhou)
#
# All credit to Bernhard Baehr ([email protected]), without his great sleepwatcher dameon, this fix will not be created.
#

#
# Added unmount Disk for "OS X" (c) syscl/lighting/Yating Zhou.
#
gMountPartition="/tmp/com.syscl.externalfix"
gDisk=($(diskutil list |grep -i -i "dev" |grep -i -o "disk[0-9]"))

for ((i=0; i<${#gDisk[@]}; ++i))
do
  gProtocol=$(diskutil info ${gDisk[i]} |grep -i "Protocol" |sed -e "s|Protocol:||" -e "s| ||g")
  if [[ ${gProtocol} == *"USB"* ]];
    then
      gCurrent_Partitions=($(diskutil list ${gDisk[i]} |grep -o "disk[0-9]s[0-9]"))
      for ((k=0; k<${#gCurrent_Partitions[@]}; ++k))
      do
        gConfirm_Mounted=$(diskutil info ${gCurrent_Partitions[k]} |grep -i Mounted |sed -e "s| Mounted:||" -e "s| ||g")
        if [[ ${gConfirm_Mounted} == *"Yes"* ]];
          then
            echo ${gCurrent_Partitions[k]} >> ${gMountPartition}
        fi
      done
      diskutil eject ${gDisk[i]}
  fi
done

✔ ~/CodeRoot/other/sleepFix [master L|✔] 
20:04 $ 

OldManLink avatar Aug 29 '18 18:08 OldManLink

Good, the code is better than before (I will reconstruct the RTLWan kext code block later on).

Would you please provide the log after executing the following commands

diskutil list
diskutil eject disk2
diskutil list

I just want to double check if the eject argument cause your SD card issue.

Thank you.

syscl avatar Aug 29 '18 18:08 syscl

Here you go:

20:08 $ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage Macintosh SSD           999.7 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3

/dev/disk1 (internal, virtual):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Macintosh SSD          +999.3 GB   disk1
                                 Logical Volume on disk0s2
                                 F0CF6AA4-CACC-4F43-A027-547271C2E57E
                                 Unlocked Encrypted

/dev/disk2 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *196.9 GB   disk2
   1:                        EFI EFI                     209.7 MB   disk2s1
   2:                  Apple_HFS Baseqi Ninja            196.5 GB   disk2s2

✔ ~/CodeRoot/other/sleepFix [master L|✔] 
20:09 $ diskutil eject disk2
Disk disk2 ejected
✔ ~/CodeRoot/other/sleepFix [master L|✔] 
20:09 $ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage Macintosh SSD           999.7 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3

/dev/disk1 (internal, virtual):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Macintosh SSD          +999.3 GB   disk1
                                 Logical Volume on disk0s2
                                 F0CF6AA4-CACC-4F43-A027-547271C2E57E
                                 Unlocked Encrypted

✔ ~/CodeRoot/other/sleepFix [master L|✔] 
20:09 $ 

OldManLink avatar Aug 29 '18 18:08 OldManLink

That's it, the diskutil eject cause the whole disk2 disappear. Hmm, why that would happen? Maybe we should use unmount command upon SD-card slot to resolve this issue. Would you give it a try after re-insert your sd-card then type in the following?

diskutil list
diskutil unmountDisk disk2
diskutil list

syscl avatar Aug 29 '18 18:08 syscl

Here you go:

Last login: Wed Aug 29 20:14:28 on console
✔ ~ 
20:15 $ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage Macintosh SSD           999.7 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3

/dev/disk1 (internal, virtual):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Macintosh SSD          +999.3 GB   disk1
                                 Logical Volume on disk0s2
                                 F0CF6AA4-CACC-4F43-A027-547271C2E57E
                                 Unlocked Encrypted

/dev/disk2 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *196.9 GB   disk2
   1:                        EFI EFI                     209.7 MB   disk2s1
   2:                  Apple_HFS Baseqi Ninja            196.5 GB   disk2s2

✔ ~ 
20:16 $ diskutil unmountDisk disk2
Unmount of all volumes on disk2 was successful
✔ ~ 
20:16 $ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage Macintosh SSD           999.7 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3

/dev/disk1 (internal, virtual):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Macintosh SSD          +999.3 GB   disk1
                                 Logical Volume on disk0s2
                                 F0CF6AA4-CACC-4F43-A027-547271C2E57E
                                 Unlocked Encrypted

/dev/disk2 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *196.9 GB   disk2
   1:                        EFI EFI                     209.7 MB   disk2s1
   2:                  Apple_HFS Baseqi Ninja            196.5 GB   disk2s2

✔ ~ 
20:16 $ 

OldManLink avatar Aug 29 '18 18:08 OldManLink

Cool, give me a few minutes to improve it.

syscl

syscl avatar Aug 29 '18 18:08 syscl