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 check if device is in use. #1

Open
nybogard opened this issue Nov 21, 2019 · 4 comments
Open

Add check if device is in use. #1

nybogard opened this issue Nov 21, 2019 · 4 comments

Comments

@nybogard
Copy link

I ran your script on an 8TB disk but it finished after just a couple of days. I discovered that badblocks had exited immediately with no apparent reason. It just said that it had finished and then the script continued with the next step.

When I ran badblocks myself I got the message

/dev/sdb is apparently in use by the system; it's not safe to run badblocks!

Apparently I had missed to unmount the drive. It would be nice if the script did a check if the device is mounted directly when you run it and warns you.

Thanks for a awsome project!

@Kryptonit3-zz
Copy link

Someone needs to convert this script to work on Freenas.
https://github.com/ezonakiusagi/bht

@Spearfoot
Copy link
Owner

I ran your script on an 8TB disk but it finished after just a couple of days. I discovered that badblocks had exited immediately with no apparent reason. It just said that it had finished and then the script continued with the next step.

When I ran badblocks myself I got the message

/dev/sdb is apparently in use by the system; it's not safe to run badblocks!

Apparently I had missed to unmount the drive. It would be nice if the script did a check if the device is mounted directly when you run it and warns you.

Thanks for a awsome project!

Thanks for your comment! I've never run into the problem of mounted drives not being available, probably because I only ever run the script on new drives, or old drives that I want to vet before putting them into service. I either case, I always pay very close attention to drive ID so that I won't mistakenly destroy data on the wrong drive! That said, do you know of a reliable way for a script to determine whether or not it's safe to run badblocks on a drive?

@nybogard
Copy link
Author

Hello @Spearfoot! Sorry for the ridiculous long time it took me to answer.

Whether it's safe or not to run badblocks on a device is kinda up to the user. Badblocks wont complain if a device have one or more partitions, it'll just happily write them over if none of them are mounted.

I only suggest that early in the script (before the SMART tests) there is a check if any partition on the device is mounted. Otherwise the script will run for several hours before it comes to badblocks which then fails if anything actually was mounted.

If you want I can make a small check using grep and /proc/mounts and send a PR.

@Spearfoot
Copy link
Owner

nybogard: pulls requests are always welcome!

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