device or resource busy при прошивке

Часто при работе с флешками, дисками, образами или другими подобными объектами может возникать ошибка device or resource busy. Она может выводится, когда вы пытаетесь отмонтировать внешний диск, раздел, а также при попытке переместить или удалить файл.

В этой небольшой статье мы рассмотрим, почему может возникать данная ошибка, а также пути её устранения. Конечно, в случае с флешкой вы можете просто вынуть её из компьютера, но это не решение, потому что высока вероятность потерять не сохранённые данные. Есть пути обхода этой проблемы.

Содержание

  1. Что означает «device or resource busy»?
  2. Как исправить device or resource busy?
  3. Выводы
  4. 9 Answers 9
  5. Comments
  6. ryanpamplin commented Jun 17, 2017

Что означает «device or resource busy»?

Если переводить дословно с английского, то это сообщение означает, что устройство или ресурс занято. Если объяснять более подробно — файл, который вы пытаетесь удалить или диск, который нужно отмонтировать, ещё используется одной из запущенных программ.

Это могло произойти потому, что программа ещё не завершила свою работу, зависла, возникли какие-либо проблемы в процессе её работы. Это актуально как для файлов, так и для съёмных носителей.

Как исправить device or resource busy?

Самое первое, что можно посоветовать — закрыть программы, которые могут использовать этот файл или один из файлов на съёмном носителе. Например, если сейчас воспроизводится один из видеофайлов, то проигрыватель надо закрыть. И только поле этого пробовать ещё раз выполнять операции.

Если вы не знаете какая программа мешает вам выполнить операцию, то это можно очень просто узнать с помощью команды lsof. Просто выполните её и отсейте только те записи, которые относятся к точке монтирования вашего носителя:

lsof | grep /media/sergiy/83AE-2346

Чтобы отсеять нужные процессы в самой утилите, используйте опцию +D, так даже лучше, потому что она не будет показывать системные службы, а отобразит только программу, которую надо завершить:

lsof +D /media/sergiy/83AE-2346

Теперь вы можете видеть все процессы, которые используют файлы на нашем носителе, и завершить их с помощью команды kill. В нашем случае надо завершить плеер totem с PID 5616:

Также, чтобы посмотреть, какие процессы используют файл, можно использовать команду fuser:

fuser -vm /home/sergiy/83AE-2346

Здесь вы тоже увидите всю необходимую информацию: будет отображаться пользователь, от имени которого запущен процесс. Точно так же можно его завершить:

Если вы закрыли все программы, но это не помогло, можно попытаться очистить файловый кэш системы с помощью такой команды:

sync && echo 2 > /proc/sys/vm/drop_caches

Выводы

В этой небольшой статье мы рассмотрели, как бороться с ошибкой device or resource busy Linux. Как видите, её очень просто исправить, даже если по началу кажется, что совсем непонятно, что можно сделать.

I tried to rm -rf a folder, and got «device or resource busy».

In Windows, I would have used LockHunter to resolve this. What’s the linux equivalent? (Please give as answer a simple «unlock this» method, and not complete articles like this one. Although they’re useful, I’m currently interested in just ASimpleMethodThatWorks™)

9 Answers 9

The tool you want is lsof , which stands for list open files.

It has a lot of options, so check the man page, but if you want to see all open files under a directory:

That will recurse through the filesystem under /path , so beware doing it on large directory trees.

Once you know which processes have files open, you can exit those apps, or kill them with the kill(1) command.

. Works for me. Thanks @camh – Vikas Goel Jun 27 ’18 at 23:33

sometimes it’s the result of mounting issues, so I’d unmount the filesystem or directory you’re trying to remove:

I use fuser for this kind of thing. It will list which process is using a file or files within a mount.

Here is the solution:

  1. Go into the directory and type ls -a
  2. You will find a .xyz file
  3. vi .xyz and look into what is the content of the file
  4. ps -ef | grep username
  5. You will see the .xyz content in the 8th column (last row)
  6. kill -9 job_ids — where job_ids is the value of the 2nd column of corresponding error caused content in the 8th column
  7. Now try to delete the folder or file.

I had this same issue, built a one-liner starting with @camh recommendation:

The awk command grabs the PIDS. The tail command gets rid of the pesky first entry: «PID». I used -9 on kill, others might have safer options.

I had this problem when an automated test created a ramdisk. The commands suggested in the other answers, lsof and fuser , were of no help. After the tests I tried to unmount it and then delete the folder. I was really confused for ages because I couldn’t get rid of it — I kept getting «Device or resource busy»!

By accident I found out how to get rid of a ramdisk. I had to unmount it the same number of times that I had run the mount command, i.e. sudo umount path

Due to the fact that it was created using automated testing, it got mounted many times, hence why I couldn’t get rid of it by simply unmounting it once after the tests. So, after I manually unmounted it lots of times it finally became a regular folder again and I could delete it.

Hopefully this can help someone else who comes across this problem!

Comments

Copy link Quote reply

ryanpamplin commented Jun 17, 2017

Hello! I’m super grateful for your amazing work! I was planning to try to do this myself until I came across your work. You saved me so much time!

I have 18 Move units and really want to get them working with the RB PI 3 I bought for this project. It’s running the latest Raspbian with all of the required libs.

I’ve scanned for the CSRMESH using «sudo hcitool lescan» and found my MAC is the same as yours and everyone else’s: «LE Scan . 43:C5:5B:04:00:06 CSRmesh»

I reset my Move units and set the pin to 8888, because I used a 5 digit before. I powered off all but 1 unit for testing and to get this working. It’s working in the app, and I shut off the app before trying the following.

When I run «./csrmesh-cli move —dest 43:C5:5B:04:00:06 —pin 8888 —position 0» from pi@raspberrypi:

/Desktop/csrmesh/bin, I get this output:

«Running: gatttool -b 43:C5:5B:04:00:06 —char-write-req -a 0x0021 -n 44a78b0080a06dba678d37d188b5d988f832ff
connect: Device or resource busy (16)

After 100s of tries it said it wrote to the Move successfully once, but it didn’t react physically.

Your help would be greatly, greatly appreciated! Happy to donate to you or a cause of your choice to show you some appreciate beyond my gratitude for your project! Thank you again!

Источник: computermaker.info

Понравилась статья? Поделиться с друзьями:
Ок! Компьютер
Добавить комментарий