Add startup confirmation to disk utilities
This commit is contained in:
1 parent
c777cf115b
commit
33c4229848
5 files changed
+48
-1
No files matched your search
@@ -20,7 +20,11 @@ Erase, Overwrite. За ATA избира Enhanced Security Erase, ако устр
|
|||||||
потвърждения, като второто е точното име на устройството.
|
потвърждения, като второто е точното име на устройството.
|
||||||
|
|
||||||
**Изтриването е необратимо и при режим за цял диск засяга всички дялове.**
|
**Изтриването е необратимо и при режим за цял диск засяга всички дялове.**
|
||||||
Не прекъсвай захранването или връзката с диска. При прекъсване на ATA
|
В началото скриптът предупреждава, че работата може да продължи часове, и
|
||||||
|
изисква `yes` за продължаване или `no` за прекратяване. Не изключвай,
|
||||||
|
рестартирай или приспивай компютъра и не прекъсвай захранването или връзката
|
||||||
|
с диска. За дял следва отделно потвърждение с точния device path; за цял диск
|
||||||
|
следват две допълнителни потвърждения. При прекъсване на ATA
|
||||||
Security Erase устройството може да остане заключено с временната парола,
|
Security Erase устройството може да остане заключено с временната парола,
|
||||||
посочена в съобщението за грешка. Secure Erase/Sanitize зависи от коректната
|
посочена в съобщението за грешка. Secure Erase/Sanitize зависи от коректната
|
||||||
реализация във firmware на устройството; скриптът не може да гарантира
|
реализация във firmware на устройството; скриптът не може да гарантира
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ Usage: sudo ./HDD/erase-storage.sh DEVICE [zero|random]
|
|||||||
For a partition, writes one full pass of zeros (default) or pseudorandom data.
|
For a partition, writes one full pass of zeros (default) or pseudorandom data.
|
||||||
For a whole disk, detects and runs a supported ATA Secure Erase or NVMe Sanitize
|
For a whole disk, detects and runs a supported ATA Secure Erase or NVMe Sanitize
|
||||||
operation. Whole-disk erasure requires two separate confirmations.
|
operation. Whole-disk erasure requires two separate confirmations.
|
||||||
|
At startup, asks you to confirm that you can keep the computer and drive
|
||||||
|
powered and connected for the hours the operation may take.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
DEVICE Partition (for example /dev/sda1) or whole disk
|
DEVICE Partition (for example /dev/sda1) or whole disk
|
||||||
@@ -51,6 +53,9 @@ case "$FILL_MODE" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
common::log "WARNING: Erasing data may take hours. Do not power off, reboot, or suspend the computer, or disconnect power or the drive."
|
||||||
|
common::confirm "Can the computer and drive remain powered and connected until the operation finishes?" || exit 0
|
||||||
|
|
||||||
for required_command in findmnt lsblk readlink swapon date dd sleep; do
|
for required_command in findmnt lsblk readlink swapon date dd sleep; do
|
||||||
common::require_cmd "$required_command"
|
common::require_cmd "$required_command"
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -16,6 +16,12 @@
|
|||||||
Ако дъщерно устройство не може да се демонтира, скриптът прекратява
|
Ако дъщерно устройство не може да се демонтира, скриптът прекратява
|
||||||
операцията.
|
операцията.
|
||||||
|
|
||||||
|
В началото скриптът предупреждава, че работата може да продължи часове, и
|
||||||
|
изисква отговор `yes` за продължаване или `no` за прекратяване. По време на
|
||||||
|
целия процес не изключвай компютъра, не го рестартирай/приспивай и не
|
||||||
|
прекъсвай захранването или връзката с диска. Преди самия запис има отделно
|
||||||
|
потвърждение с `YES`.
|
||||||
|
|
||||||
Използвай само с правилно идентифициран диск, който можеш безопасно да
|
Използвай само с правилно идентифициран диск, който можеш безопасно да
|
||||||
изтриеш. Изисква пряка SATA връзка; `smartctl` не използва `-d sat`, затова
|
изтриеш. Изисква пряка SATA връзка; `smartctl` не използва `-d sat`, затова
|
||||||
USB адаптер може да изисква ръчна промяна на извикванията в скрипта.
|
USB адаптер може да изисква ръчна промяна на извикванията в скрипта.
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ Usage: sudo ./HDD/repair-hdd.sh DEVICE [zero|null|random]
|
|||||||
Overwrites the selected disk, then runs a SMART extended self-test. This
|
Overwrites the selected disk, then runs a SMART extended self-test. This
|
||||||
destroys all data on DEVICE. Use only with a directly connected SATA disk;
|
destroys all data on DEVICE. Use only with a directly connected SATA disk;
|
||||||
USB adapters may require adding -d sat to the smartctl calls.
|
USB adapters may require adding -d sat to the smartctl calls.
|
||||||
|
At startup, asks you to confirm that you can keep the computer and drive
|
||||||
|
powered and connected for the hours this operation may take.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
DEVICE Whole-disk block device, for example /dev/sdX
|
DEVICE Whole-disk block device, for example /dev/sdX
|
||||||
@@ -55,6 +57,9 @@ case "$FILL_MODE" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
common::log "WARNING: This operation may take hours. Do not power off, reboot, or suspend the computer, or disconnect power or the drive."
|
||||||
|
common::confirm "Can the computer and drive remain powered and connected until this operation finishes?" || exit 0
|
||||||
|
|
||||||
for required_command in findmnt lsblk readlink swapon mkdir date tee smartctl grep umount dd sync sleep head base64; do
|
for required_command in findmnt lsblk readlink swapon mkdir date tee smartctl grep umount dd sync sleep head base64; do
|
||||||
common::require_cmd "$required_command"
|
common::require_cmd "$required_command"
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -54,6 +54,33 @@ common::log() {
|
|||||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" >&2
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# common::confirm returns success only when the user answers yes.
|
||||||
|
# A no answer or end-of-input cancels the caller; invalid answers are retried.
|
||||||
|
common::confirm() {
|
||||||
|
local prompt="$1"
|
||||||
|
local answer
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
if ! read -r -p "${prompt} [yes/no]: " answer; then
|
||||||
|
common::log "No response received; cancelling."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "${answer,,}" in
|
||||||
|
yes)
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
no)
|
||||||
|
common::log "Cancelled by user."
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf "Please answer 'yes' or 'no'.\n" >&2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# common::require_cmd fails fast with a clear message if a required
|
# common::require_cmd fails fast with a clear message if a required
|
||||||
# external command is missing from PATH, instead of letting the script
|
# external command is missing from PATH, instead of letting the script
|
||||||
# fail later with a cryptic "command not found".
|
# fail later with a cryptic "command not found".
|
||||||
|
|||||||
Reference in new issue
Block a user