Repair Disk Permissions

Discussion in 'Mac Programming' started by BlueRevolution, Feb 28, 2010.

  1. BlueRevolution macrumors 603

    BlueRevolution

    Joined:
    Jul 26, 2004
    Location:
    Montreal, QC
    #1
    I wrote this AppleScript last night. Basically, this thread keeps getting resurrected by people with the same problem over and over, so I thought I'd make a script that goes through the troubleshooting and repair process.

    Any bug reports or feedback would be welcome.

    Code:
    --
    -- Repair Disk Permissions 0.1.3
    -- By Mikkel Paulson ([email address in app])
    --
    -- THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND. USE AT YOUR OWN RISK.
    --
    -- You should always have an up-to-date backup of all of your important files before scratching your
    -- nose, let alone mucking around with disk permissions and such.
    --
    -- This script implements most of the suggestions from the ongoing thread "How do I unlock my
    -- external hard drive?" http://forums.macrumors.com/showthread.php?t=417647 Specifically, it:
    --
    -- • Tests all volumes for writability by saving a 0-byte invisible file ".permissions_test_file" to each
    --    volume's root directory, then deleting it again.
    -- • Reports which volumes are writable and which are not.
    -- • Asks the user for permission to attempt to fix writing issues.
    -- • Prompts to correct permissions (to drwxrwxr-x root:admin) for HFS+ and JHFS+ volumes.
    -- • Gives the option to install MacFUSE and NTFS-3G for NTFS volumes.
    -- • Gives the option to format NTFS volumes to JHFS+, FAT32, or a manually-entered format.
    -- • Produces a log, including before & after ls -l listings of /Volumes.
    --
    -- This script has been tested on Mac OS X 10.4 PowerPC and 10.5 Intel computers.
    --
    -- Please post any questions or bug reports to:
    -- http://forums.macrumors.com/showthread.php?t=871557
    -- If the script is unable to solve your problem, the best place to go is back in the original thread:
    -- http://forums.macrumors.com/showthread.php?t=417647
    --
    -- This script is hereby released into the public domain. Feel free to use it or its code for any purpose,
    -- with or without attribution.
    --
    -- Changelog:
    -- 0.1.0 - original release
    -- 0.1.1 - fixed bug preventing the format process from working
    -- 0.1.2 - now works with volumes with spaces in their names
    -- 0.1.3 - now a universal binary
    --
    Sample log:

    Code:
    Original permissions:
    total 24
    drwxrwxr-x   8 mikkel  staff   340 Feb 28 17:03 Kohlberg
    drwxrwxrwx@  1 root    admin  8192 Feb 28 17:03 Miniluv
    d---------  15 root    admin   578 Feb 28 17:03 Minipax
    lrwxr-xr-x   1 root    admin     1 Feb 27 07:39 Minitrue -> /
    
    Kohlberg: writable
    Miniluv: writable
    Minipax: permission denied
    Minitrue: writable
    Minipax: currently formatted as Journaled HFS +
    Minipax: permission repair attempted
    Minipax: works now!
    
    New permissions:
    total 24
    drwxrwxr-x   8 mikkel  staff   340 Feb 28 17:04 Kohlberg
    drwxrwxrwx@  1 root    admin  8192 Feb 28 17:04 Miniluv
    drwxrwxr-x@ 15 root    admin   578 Feb 28 17:04 Minipax
    lrwxr-xr-x   1 root    admin     1 Feb 27 07:39 Minitrue -> /
    Code:
    Original permissions:
    total 8
    drwxr-xr-x    1 mikkel  mikkel     0 Apr 22  2009 Kohlberg
    lrwxr-xr-x    1 root    admin      1 Feb  3 01:36 The Creature -> /
    drwxr-xr-x   38 mikkel  mikkel  1248 Feb 28 17:33 mikkel
    
    Kohlberg: permission denied
    The Creature: writable
    mikkel: writable
    Kohlberg: currently formatted as NTFS
    Kohlberg: reformatted to JHFS+
    Kohlberg: works now!
    
    New permissions:
    total 8
    drwxr-xr-x    4 mikkel  mikkel   238 Feb 28 17:36 Kohlberg
    lrwxr-xr-x    1 root    admin      1 Feb  3 01:36 The Creature -> /
    drwxr-xr-x   38 mikkel  mikkel  1248 Feb 28 17:34 mikkel
     

    Attached Files:

  2. IEatApples macrumors 6502a

    IEatApples

    Joined:
    Jan 26, 2004
    Location:
    Northern Hemisphere (Norway)
    #2
    WoW! This is great! :)

    Man I wish I knew how to make AppleScrips. :(

    Anyway, thanks for your great work! :)
    I'll be sure to recommend it to "those in need", and I'll give it a try myself if my previous problems should reemerge. :)
     
  3. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #3
    You should resave it as a .app bundle (I think in 10.5 the option is "Application Bundle", 10.6 automatically saves as a universal app). Right now it's PPC only.
     
  4. BlueRevolution thread starter macrumors 603

    BlueRevolution

    Joined:
    Jul 26, 2004
    Location:
    Montreal, QC
    #4
    Why? It works fine on both Intel and PowerPC Macs...
     
  5. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #5
    1. Rosetta is an optional install for 10.6. Not everyone has it on their machines
    2. Even when it's enabled, it's slow
    3. PPC is dead ;)
     
  6. BlueRevolution thread starter macrumors 603

    BlueRevolution

    Joined:
    Jul 26, 2004
    Location:
    Montreal, QC
    #6
    Oh wow, I didn't realize that Script Editor in Leopard didn't save universal binaries by default. How bizarre. Anyway, I've updated the script. Thanks for pointing that out.
     
  7. yuyu8286 macrumors newbie

    Joined:
    May 18, 2010
    #7
    BlueRevolution, thank you for the script. I tried it on my laptop and got the following:

    Original permissions:
    total 8
    lrwxr-xr-x 1 root admin 1 May 12 19:17 Macintosh HD -> /
    drwxrwxrwx 11 Adriana staff 442 May 16 15:01 video

    Macintosh HD: writable
    video: permission denied
    video: currently formatted as HFS +
    video: permission repair attempted
    video: still borked 'cos of touch: /Volumes/video/.permissions_test_file: Read-only file system

    New permissions:
    total 8
    lrwxr-xr-x 1 root admin 1 May 12 19:17 Macintosh HD -> /
    drwxrwxrwx 11 Adriana staff 442 May 16 15:01 video

    I still can't write on my HD. Anone have any other tips?? Thanks.
     
  8. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #8
    I would suggest posting about your issue over here: Mac Basics and Help
     
  9. unovirgola macrumors newbie

    Joined:
    Mar 10, 2009
    #9
    thanks..

    cheers bluerevolution.. your script has worked for me..

    many thanks...
     
  10. slarph macrumors newbie

    Joined:
    Sep 13, 2010
    #10
    Unbelievable! Worked like a charm. I've been banging my head on the desk for a week with this issue. Thanks so much.
     
  11. hoofedcracker macrumors newbie

    Joined:
    Dec 9, 2010
    #11
    Cheers for the applescript, You saved My Arse!!

    Thanx again


    Peace
     
  12. CarstenO macrumors newbie

    Joined:
    Jan 26, 2011
    #12
    Locked=Owners Enabled:No ??

    I have an external drive that I can see on the desktop, I am able to write to it and read from it, but for some reason when I look in Disk Utility the Ownership Enable is set to No. I first became aware of this when I tried to back up the disk, using SuperDupers SmartCopy-option. I took forever, so I contacted the developer who noted that the Ownership-issue might play a part.

    The backup-speed problem has been resolved another way, but I'm still puzzled as to why the Ownership Enabled is set to No for this disk - and I can't Check or Repair the permissions. The same goes for the disk that I back up onto. Both are USB2-disks. I tried running the script, that was supplied in this thread and got the message that everything was fine. But they remain set to No and with no possibility to repair permissions.

    Any idea about what's going on with this?

    TIA for any advice or help
    CarstenO
     
  13. BlueRevolution thread starter macrumors 603

    BlueRevolution

    Joined:
    Jul 26, 2004
    Location:
    Montreal, QC
    #13
    Owners is normally disabled for external drives.

    http://grab.by/8KfX

    Repair permissions applies only to your boot volume. Basically, it checks file (especially system file) permissions against the OS index of what the permissions should be. It doesn't know what the permissions should be on an external drive, so it doesn't know how to fix it. That's why my script is needed.

    To me, it sounds like your hard drive is failing.
     
  14. CarstenO macrumors newbie

    Joined:
    Jan 26, 2011
    #14
    External drive

    Does it add to the suspicion of a failing drive that I regularly get the following error message in iTunes:

    The iTunes Library cannot be saved. An unknown error occured (-50).

    I have the option to check a Do not Warn Me Again-box, and if I don't check that but just click the OK the button, the message will reappear after a few seconds, redenring the app virtually useless. Should I check that box?

    If I quit iTunes and try to relaunch, it says The iTunes application could not be opened. An unknown error occured (13014)

    Not until after a reboot of the entire machine does it go away. Sometimes I also have to trash the Library Extras-file and the Library Extras Genius file from my iTunes folder. But in a wider perspective I wouldn't want to have to do that ever so often to have my music playing.
     
  15. BlueRevolution thread starter macrumors 603

    BlueRevolution

    Joined:
    Jul 26, 2004
    Location:
    Montreal, QC
    #15
    If your iTunes library is located on the external drive, then definitely. If it's on your computer's internal hard drive, then that may be the one that's failing and slowing down your SuperDuper backup.

    Open Disk Utility and select the drive (the one with a size and serial number) in the sidebar. What does it say next to S.M.A.R.T. Status?

    I would however attempt a permission repair on your boot drive before writing it off as a lost cause.
     
  16. CarstenO macrumors newbie

    Joined:
    Jan 26, 2011
    #16
    The library is on the external drive. I can easily move it to the internal harddrive, though. But I need to keep the mediafiles (music, podcast and movis) on the external drive. Might this altogether be a better solution?

    The speedproblem with SuperDuper was miraculously solved when I plugged the source drive (the iTunes drive) into another usb-port.

    The S.M.A.R.T.-status in DU says Not Supported for that drive.
     
  17. BlueRevolution thread starter macrumors 603

    BlueRevolution

    Joined:
    Jul 26, 2004
    Location:
    Montreal, QC
    #17
    Yeah, S.M.A.R.T. doesn't work with USB/FireWire connections.

    A damaged USB port can have the same symptoms. Just maintain a complete backup of important files (as always), and be alert for any of the following:

    • clicking noises
    • unexpected slowdowns
    • data corruption
    • read/write errors
    • spinning up repeatedly
     
  18. CarstenO macrumors newbie

    Joined:
    Jan 26, 2011
    #18
    Interesting - I mean it was born a USB-disk.

    Anyhow, do you think I should try moving the library files to the iTunes-folder on the internal drive? (I do keep a weekly backup)
     
  19. BlueRevolution thread starter macrumors 603

    BlueRevolution

    Joined:
    Jul 26, 2004
    Location:
    Montreal, QC
    #19
    Shouldn't have any effect on reliability or SMART vs. a drive placed in an enclosure.


    No need if everything's working fine now. So long as the external drive is backed up too, I don't see any benefit one way or the other.
     
  20. CarstenO macrumors newbie

    Joined:
    Jan 26, 2011
    #20
    Well if those errors return I'll try to move the files. If not I'll just leave it alone.

    Thanks a lot for your help. It's been a pleasure :)

    C
     
  21. CarstenO macrumors newbie

    Joined:
    Jan 26, 2011
    #21
    External drive iTunes trouble continues

    I threw in the towel and went to the store and returned my Verbatim 2TB external drive that was causing problems with my iTunes Library, giving the frequent Error Message "The iTunes Library file cannot be saved. An unknown error occurred (-50)" :-(

    Unfortunately the new disk shows the same symptom. I need to reboot the entire machine, trash the iTunes Library Extras and iTunes Library Genius-files to be able to play music

    Do I need to actually zero-out the external drive to get rid of whatever it is that's corrupting my Library? It's formatted as a GUID-partition, read/write, SMART Not Supported, Mac OS Extended (Journaled). Or do I simply end up at Verbatim not being the thing for me and my setup and go get an entirely different drive?

    Any advice is greatly appreciated
    Thanks, Carsten
     
  22. BlueRevolution thread starter macrumors 603

    BlueRevolution

    Joined:
    Jul 26, 2004
    Location:
    Montreal, QC
    #22
    Try repairing permissions on your internal drive first. If you still have problems, yeah, zero out the Verbatim drive and give it one last chance. Zeroing will fix any bad sectors that might be present.
     
  23. CarstenO macrumors newbie

    Joined:
    Jan 26, 2011
    #23
    External drive iTunes trouble continues

    I did repair the permissions on my internal drive and the problem remains. Mind you, the Library Files are on the External drive as well, along with the media files, the Playlists folder, Album Artwork folder and the Previous iTunes Libraries folder.

    I'm wondering whether I should move some of those, e.g. the Library files to the Music-folder on the internal drive.

    I'll try zeroing the external drive and see if that helps.

    I'll be happy to hear/read any thoughts/comments

    thanx
    Carsten
     
  24. Harrietlayhe macrumors newbie

    Joined:
    Mar 12, 2011
    #24
    Still not working

    Hi, I just tried the script but it said it couldn't fix the problem with my external hard drive. I got a new macbook pro recently and it wouldn't back up with the new one at first, but then I sorted that and it's been backing up fine ever since. Then for the past few days it says I don't have permission to access the disk, and when I try to change the permission from "custom" to "read and write" it just flicks back to "custom". This was the message I got:


    Original permissions:
    total 8
    lrwxr-xr-x 1 root admin 1 Mar 13 01:00 Macintosh HD -> /
    drw-rw-r--+ 11 root admin 442 Mar 3 00:15 My Passport
    drwxrwxrwx@ 10 Nibbles staff 340 Nov 14 2009 WD SmartWare

    Macintosh HD: writable
    My Passport: permission denied
    WD SmartWare: permission denied
    My Passport: currently formatted as Journaled HFS +
    My Passport: permission repair attempted
    My Passport: still borked 'cos of touch: Passport/.permissions_test_file: No such file or directory
    WD SmartWare: currently formatted as HFS +
    WD SmartWare: permission repair attempted
    WD SmartWare: still borked 'cos of touch: SmartWare/.permissions_test_file: No such file or directory

    New permissions:
    total 8
    lrwxr-xr-x 1 root admin 1 Mar 13 01:00 Macintosh HD -> /
    -rw-r--r-- 1 Nibbles admin 0 Mar 13 01:23 My
    drwxrwxr-x 11 root admin 442 Mar 3 00:15 My Passport
    -rw-r--r-- 1 Nibbles admin 0 Mar 13 01:23 WD
    drwxrwxrwx@ 10 Nibbles staff 340 Nov 14 2009 WD SmartWare

    Any help would be greatly appreciated. The reason I got a new laptop in the first place was because my old one broke and Apple couldn't fix it, I really don't want to have to spend another minute in the Apple shop!
     
  25. Harrietlayhe macrumors newbie

    Joined:
    Mar 12, 2011
    #25
    Wow!

    Wow, thank you so much! Although it didn't fix the problem, I tried to change the permission again and it let me. Before my user, system and admin all had "custom" permission, but when I tried it after your script my user wasn't on there and I was able to add it and set to "read and write". Seems to be backing up fine so far, so thank you!

    I'm still unsure why this happened in the first place, but very glad I found this! Thanks again,

    Harriet
     

Share This Page