Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
OldManLink opened this issue Aug 21, 2018 · 52 comments
Open

Comments

@OldManLink
Copy link

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.

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

@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

@OldManLink
Copy link
Author

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!

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

Thank you, I will add the SD support now.

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

@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

@OldManLink
Copy link
Author

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.

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

Remount it by the following

sudo /etc/sysclusbfix.wake

@OldManLink
Copy link
Author

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 $ 

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

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

cat /etc/sysclusbfix.sleep

syscl

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

How about

diskutil list

@OldManLink
Copy link
Author

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
Copy link
Author

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 $ 

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

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

@OldManLink
Copy link
Author

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

@OldManLink
Copy link
Author

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 $ 

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

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

@OldManLink
Copy link
Author

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
Copy link
Author

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!

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

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

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

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

@OldManLink
Copy link
Author

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

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

No worry.

@OldManLink
Copy link
Author

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

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

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
Copy link
Owner

syscl commented Aug 29, 2018

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

@OldManLink
Copy link
Author

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 $ 

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

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.

@OldManLink
Copy link
Author

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 $ 

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

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

@OldManLink
Copy link
Author

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 $ 

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

Cool, give me a few minutes to improve it.

syscl

@OldManLink
Copy link
Author

OldManLink commented Aug 29, 2018

Nice! I will be available for about another 25 minutes, then I'll drive home. So if you want me to try stuff out when I get home I will be available for that (30 minutes after I leave the office).

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

Please give the latest fixUSB.sh a try.

Thank you.

@OldManLink
Copy link
Author

Looks like an "oops"

20:16 $ 
✔ ~ 
20:32 $ pwd
/Users/peter
✔ ~ 
20:32 $ cd CodeRoot/other/sleepFix/
✔ ~/CodeRoot/other/sleepFix [master L|✔] 
20:33 $ git remupp
Fetching origin
✔ ~/CodeRoot/other/sleepFix [master ↓·1|✔] 
20:33 $ git pull
Updating 7dc4273..ee1d78a
Fast-forward
 fixUSB.sh | 132 +++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------
 1 file changed, 67 insertions(+), 65 deletions(-)
✔ ~/CodeRoot/other/sleepFix [master L|✔] 
20:33 $ ./fixUSB.sh 
./fixUSB.sh: line 260: syntax error near unexpected token `('
./fixUSB.sh: line 260: `    echo '# Added mount Disk for "OS X" (c) syscl/lighting/Yating Zhou.'                                                                                    >> "$gUSBWakeScript"'
✘-2 ~/CodeRoot/other/sleepFix [master L|✔] 
20:33 $

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

Thank you for your report, please try the latest one.

@OldManLink
Copy link
Author

Here you go:

20:40 $ ./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.
[FAILED]  Install sleep script.
cp: /tmp/sysclusbfix.sleep: No such file or directory
[  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.
[FAILED]  Clean up.
rm: /tmp/sysclusbfix.sleep: No such file or directory
[ Note ]  DONE! Sleep to see change.
[ Note ]  Feel free to post issue on https://github.com/syscl/Fix-usb-sleep.
✘-1 ~/CodeRoot/other/sleepFix [master L|✔] 
20:40 $ 

@OldManLink
Copy link
Author

Now I must drive home, but I will check my mail again in about 30 minutes.

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

See you and please try the lastest script (seems previous version has a bug that cause the sleep script generate fail.

@OldManLink
Copy link
Author

Ok, I am home now, so will grab some food then try out the new version.

@OldManLink
Copy link
Author

Here we go:

21:45 $ cd CodeRoot/other/sleepFix/
✔ ~/CodeRoot/other/sleepFix [master L|✔] 
21:45 $ git remupp
Fetching origin
✔ ~/CodeRoot/other/sleepFix [master ↓·1|✔] 
21:45 $ git pull
Updating f587f8e..e2486c2
Fast-forward
 fixUSB.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
✔ ~/CodeRoot/other/sleepFix [master L|✔] 
21:45 $ ./fixUSB.sh 
[  OK  ]  Generate configuration file of sleepwatcher launch daemon.
[  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|✔] 
21:46 $ 

Next I will sleep the laptop for one minute and report what happens.

@OldManLink
Copy link
Author

21:46 $ echo "Sleep done"
Sleep done
✔ ~/CodeRoot/other/sleepFix [master L|✔] 
21:51 $ 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|✔] 
21:52 $ 

@OldManLink
Copy link
Author

So now the disk is gone again after the sleep.

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

OK. Would you please re-insert the sd card then try to execute the script manually

sudo /etc/sysclusbfix.sleep

Thank you.

@OldManLink
Copy link
Author

OK:

22:17 $ 
✔ ~/CodeRoot/other/sleepFix [master L|✔] 
22:19 $ sudo /etc/sysclusbfix.sleep
Password:
/etc/sysclusbfix.sleep: line 32: [: too many arguments
Unmount of all volumes on disk2 was successful
✔ ~/CodeRoot/other/sleepFix [master L|✔] 
22:19 $ 

@OldManLink
Copy link
Author

Also:

22:19 $ 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|✔] 
22:20 $ 

And the disk icon is gone from the desktop.

@OldManLink
Copy link
Author

Now it's getting late, so I'll call it a day and check in again tomorrow.

Thanks for trying to fix this!

@syscl
Copy link
Owner

syscl commented Aug 29, 2018

Have a good night.

It seems that the sleep script has correctly unmount the sd card. How about executing the wake script(by sudo /etc/sysclusbfix.wake after wake from sleep? I think the problem now turns out to be the wake script.

@OldManLink
Copy link
Author

I put the laptop to sleep just now. When I woke it up I was greeted with this:
wakefromsleep

Then I did the following:

09:17 $ 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

✔ ~ 
10:18 $ sudo /etc/sysclusbfix.wake
Password:
cat: /tmp/com.syscl.externalfix: No such file or directory
rm: /tmp/com.syscl.externalfix: No such file or directory
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 ~ 
10:18 $ 

@syscl
Copy link
Owner

syscl commented Sep 10, 2018

TL;DR. It seems the SD card hasn't been ejected correctly which is operated by the *HCI kext. It seems the comment unmount then remount method does not work in this case. I wish I can come up to a better solution and will let you know. once I push a new update.

@syscl
Copy link
Owner

syscl commented Dec 1, 2018

Please try the latest version of script.

@OldManLink
Copy link
Author

Sorry for the delay, I was travelling without my MacBook for the last few days. So here is the latest console log:

11:25 $ ./fixUSB.sh -u 
[  OK  ]  Unload /Library/LaunchDaemons/com.syscl.externalfix.sleepwatcher.plist.
[  OK  ]  Remove /usr/local/sbin/.
[  OK  ]  Remove /Library/LaunchDaemons/com.syscl.externalfix.sleepwatcher.plist.
[  OK  ]  Remove /etc/sysclusbfix.sleep.
[  OK  ]  Remove /etc/sysclusbfix.wake.
✔ ~/CodeRoot/other/sleepFix [master L|✔] 
11:26 $ 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|✔] 
11:26 $ ./fixUSB.sh
[  OK  ]  Generate configuration file of sleepwatcher launch daemon.
[  OK  ]  Generate script to load RTWlanUSB upon sleep.
[ ---> ]  Installing external devices sleep patch...
[  OK  ]  Create /usr/local/sbin/.
[  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|✔] 
11:27 $ 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]"))
gUSBDisk=""

for ((i=0; i<${#gDisk[@]}; ++i))
do
  gProtocol=$(diskutil info ${gDisk[i]} |grep -i "Protocol" |sed -e "s|Protocol:||" -e "s| ||g")
  is_SDCard=$(diskutil info ${gDisk[i]} |grep -i "Device / Media Name" |grep -i "SD Card")
  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
      if [ -z ${is_SDCard} ]; then
          diskutil eject ${gDisk[i]}
      else
          gUSBDisk="${gUSBDisk}
${gDisk[i]}"
      fi
  fi
done
echo -e "${gUSBDisk}
" | xargs -I {} diskutil eject {}

✔ ~/CodeRoot/other/sleepFix [master L|✔] 
11:28 $ sudo /etc/sysclusbfix.sleep
/etc/sysclusbfix.sleep: line 33: [: too many arguments
Unable to find disk for -e disk2
✘-1 ~/CodeRoot/other/sleepFix [master L|✔] 
11:30 $ 

@OldManLink
Copy link
Author

OldManLink commented Dec 4, 2018

Note: the disk is still mounted:

11:33 $ 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|✔] 
11:33 $ 

@axeII
Copy link

axeII commented Nov 13, 2019

Thank you for working on this. Any update? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants