-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martin Butt
committed
Aug 16, 2021
0 parents
commit 3bb6835
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please refer to <https://unlicense.org> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Fix NTFS Mounts in linux | ||
|
||
`BASH` script that fixes NTFS mounts that have become `READ-ONLY` on Linux. | ||
|
||
## Dependencies | ||
|
||
The script uses `ntfs-3g` and `ntfsfix`. | ||
|
||
## Usage | ||
``` | ||
Usage: fix-ntfs.sh <mount_source> <mount_target> | ||
Options: | ||
<mount_source> The device to fix, e.g. /dev/sda1 | ||
<mount_target> The directory to mount to, e.g. /mnt/my_drive | ||
``` | ||
|
||
## Overview | ||
|
||
The script will unmount, fix and remount the drive in `READ-WRITE` mode. If there are running processes that will prevent the drive from unmounting, the script will offer to kill them. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env bash | ||
|
||
usage() { | ||
cat << EOF | ||
Usage: $(basename $0) <mount_source> <mount_target> | ||
Options: | ||
<mount_source> The device to fix, e.g. /dev/sda1 | ||
<mount_target> The directory to mount to, e.g. /mnt/my_drive | ||
EOF | ||
exit | ||
} | ||
|
||
if ! command -v ntfsfix 2>&1 > /dev/null; then | ||
echo "ERROR: 'ntfsfix' not found in PATH" | ||
exit 1 | ||
fi | ||
|
||
if ! command -v ntfs-3g 2>&1 > /dev/null; then | ||
echo "ERROR: 'ntfs-3g' not found in PATH" | ||
exit 1 | ||
fi | ||
|
||
mount_source=${1} | ||
mount_target=${2} | ||
|
||
if [ -z "${mount_source}" ] || [ -z "${mount_source}" ]; then | ||
usage | ||
fi | ||
|
||
if ! ls "${mount_source}" 2>/dev/null > /dev/null; then | ||
echo "ERROR: Mount source not found '${mount_source}'"; | ||
exit | ||
fi | ||
|
||
if [ ! -d "${mount_target}" ]; then | ||
echo "ERROR: Mount target not a directory '${mount_target}'"; | ||
exit | ||
fi | ||
|
||
processes=$(lsof +f -- "${mount_target}" 2>/dev/null | tail -n +2) | ||
|
||
while [ -n "${processes}" ]; do | ||
echo "$(echo "${processes}" | wc -l) processes preventing 'umount'" | ||
echo "${processes}" | ||
|
||
process=$(echo "${processes}" | tail -n 1) | ||
|
||
if [ -n "${process}" ]; then | ||
echo | ||
echo "Current process details:" | ||
echo "${process}" | ||
|
||
read -p "Kill it? [y/N] " -n1 kill_process | ||
|
||
if [ "${kill_process}" == "Y" ] || [ "${kill_process}" == "y" ]; then | ||
kill -9 $(echo ${process} | cut -d " " -f 2) | ||
else | ||
echo -e "\nManually exit processes and re-run" | ||
exit | ||
fi | ||
fi | ||
|
||
processes=$(lsof +f -- "${mount_target}" 2>/dev/null | tail -n +2) | ||
done | ||
|
||
sudo umount "${mount_source}" | ||
sudo ntfsfix "${mount_source}" | ||
sudo umount "${mount_source}" | ||
sudo ntfs-3g -o recover,rw,umask=000,dmask=002,fmask=113,uid=1000,gid=1000 "${mount_source}" "${mount_target}" | ||
sudo umount "${mount_target}" | ||
sudo mount "${mount_source}" "${mount_target}" |