OS X - copy files issue - Resource busy

6,433

UPDATE: I think I figured out how you may be able to fix this.

Try this from terminal:

cd <drag and drop the volume you want to copy here>

Now do:

lsof +D <drag and drop the volume you want to copy here> | grep <drag and drop the volume you want to copy here>

This command will show you all of the open files on that volume. You will see the application name of the application that is holding onto the file. Lets say for argument's sake that it is Finder.

Now type in (Just make sure you have closed out of all of your applications first to be on the safe side):

killall Finder

Now run the lsof command again and you should no longer see those files. Now you should be able to copy them.

Hope that does the trick.


Previous Post

In Terminal type in env.

Look at where it says USER= and copy that name exactly.

Now we will change the owner of all of the files on the drive, just make sure you are mounted to the drive you want to copy and not your system drive. Mount the root directory of the drive you want to copy and type:

sudo chown -fhRL [owner]

For where it says [owner], enter, enter the user name from above. You will be prompted for your password because we added sudo which is Super User do.

If it exits with a status of 0, then there were no errors. If you are getting an exit code > than 0, then you can drop the f and you will see all of the diagnostic messages.

Next we are going to change the permissions of the files. Enter:

sudo chmod -fhRL u=rwx

u - user r - read w - write x - execute Again, if there was an error, the exit status will be greater than 0 Next, we will change the flags:

sudo chflags -fhRL nouchg 
sudo chflags -fhRL noschg

Now go back to your copy command and for good measure add sudo in front of it, and hopefully this will have resolved the issue.

Share:
6,433

Related videos on Youtube

Dave F
Author by

Dave F

PM and PgM by day, drummer by night. Sometimes a QA Manager.

Updated on September 18, 2022

Comments

  • Dave F
    Dave F almost 2 years

    Calling all OS X experts.

    I copied two 1Tb drives (ex-Windows) onto a new 2Tb USB 3.0 drive using Finder on the Mac (OS X 10.9). The 2Tb drive is now about 90% full.

    I now want to duplicate that 2Tb drive to another 2Tb drive using the Mac, however it keeps claiming about 40% of the files are busy. None of the files on the 2Tb drive have ever been opened in any app, other than this attempt to copy the files across.

    I tried copying 2Tb to 2Tb using finder, which once it found 1 file busy just stopped copying altogether. Not particularly useful. I tried using the icons view, the list and columns views.

    I then switched to Terminal using cp -RXvn and later just -cp RXn. Both were able to copy about 60% of the files.

    I've tried unmounting both drives, rebooting and reformatting the 2nd drive. I've tried all three before attempting again and I get to about 1.34 Tb each time. I've tried several times and I'm noting it's not always the same files having the issue, although it's hard to tell when there's thousands of files.

    What I get looks like this:

    cp -RXn "/Volumes/USBdrive 1/" "/Volumes/USBdrive 2"
    cp: /Volumes/USBdrive 1/My photos/USA trip/image 1472.png: Resource busy
    cp: /Volumes/USBdrive 1/My photos/USA trip/image 1483.png: Resource busy
    cp: /Volumes/USBdrive 1/Our holiday/Rome/tour map 2014.pdf: Resource busy
    

    I'm new-ish to OS X, so I don't understand how the file has become in a busy state, or what to do about it. It doesn't make much sense to me to not copy the file even if it's in use anyway (Windows would).

    Can anyone suggest how to get around this and get all the files from one drive to the other? Do I need to find a way to stop the resource from being considered Busy first, and if so, how?

    • AMR
      AMR almost 9 years
      I just want to make sure, these are data files, you don't have applications on this drive, correct? Because changing the owner for applications can mess with there ability to work if they are digitally signed.
    • Dave F
      Dave F almost 9 years
      These are all image, audio, text and video files. No apps.
    • fd0
      fd0 almost 9 years
      Any of the following could be the cause, corrupt filesystem/files, TimeMachine, fsevents, spotlight, a running application that has the file open. First I would close all the visible applications except the Terminal.app. I would get the latest version of rsync and attempt to copy the files with rsync. If that fails then I would start turning off those services and attempt to repair the source filesystem.
    • AMR
      AMR almost 9 years
      @DaveF, If you know Windows OS better maybe check originals there to see if you have files that are locked up there.
    • AMR
      AMR almost 9 years
      @fd0 has a point. I have a USB Thumb drive on my laptop that I use for data storage, so that I always have my important files with me. I usually try to eject my external drives before I shutdown. Every so often that drive says their are files in use and it can't be ejected. If I restart and then eject the drive again this can help. "I KNOW!" sorry I went to the old IT support standby, "Reboot!" but sometimes it can be just that simple. Also as I said in a comment before, external USB drives have been nothing but problems for me, so I avoid them at all costs.
    • AMR
      AMR almost 9 years
      I posted an update that I think should work. Fingers crossed!
  • Dave F
    Dave F almost 9 years
    No change. Still lots of Resource Busy. I followed these instructions to the letter, although -h and -RL can't be used together, so I ran the commands with those switches separately. Nice idea, but no luck.
  • AMR
    AMR almost 9 years
    Darn. Did you format the drives using Disk Utility, and Mac OsX extended (journaled)? This article talks about it... Only thing is you can't use journaled with other OS, but there are advantages with A Mac... support.apple.com/en-us/HT201909 . If you did, then go to Disk Utility and try the Verify and Repair options. That can sometimes fix the issue. If you didn't but have the time, maybe you can reformat the drives and start th process again. If you type man cp it will give you the options you can use to rest files as you copy from one place to another.
  • AMR
    AMR almost 9 years
    also from personal experience, I have had a great deal of problems with USB external drives and photo files. Read thousands of dollars in drive recovery costs. The solution I hit upon which has been more reliable for me have been NAS from Synology with HGST drives. They are fairly simple to set up and have a ton more features than USB drives. I use Raid 6 and that has protected my data when I lost one of the WD drives that I first had. It was as simple as powering down, pulling the old drive, then putting a new one in. Restart and it rebuilds the strip and you are back on your way.
  • AMR
    AMR almost 9 years
    Sorry, The lsof command should have been +D not -D
  • Dave F
    Dave F almost 9 years
    I had done an lsof previously, and I think then the response was Resource Busy (which I thought was particularly useless), but I wasn't sure if my memory was correct. I did lsof with the grep on both drives and got nothing. I going to try cycles of unmount, reboot, then the cp -RXn again to see it moves any closer to a complete write each time. As this takes a while even when it fails, I'll know more later tonight.
  • Dave F
    Dave F almost 9 years
    A NAS may be my only option. This is all to try and make the drive available to my router - The USB 3.0 router doesn't get enough power from the router, and the 2nd drive is an older USB 2.0 with a separate power supply.
  • AMR
    AMR almost 9 years
    Darn I thought I had it. I had some deadlocked files today and that was how I got them to behave. I will not talk you out of the NAS route. I can sleep better at night. Synology makes a great product and even though their support is overseas, you send them an email and the reply within the day with usually the right answer.
  • Dave F
    Dave F almost 9 years
    Thanks for the recommendation. My progress on the drive copy has been slowed by other issues. I'm now getting prices on NASs, as I'm starting to suspect a hardware issue.