Created
April 9, 2019 06:28
-
-
Save jgrevich/624d687d8c323597561bf9f63b4d54eb to your computer and use it in GitHub Desktop.
Automate process of running bad blocks based on LBA number of errors found in smartctl
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
#!/usr/local/rvm/rubies/ruby-2.6.2/bin/ruby | |
# b = (int)((L-S)*512/B) | |
# where: | |
# b = File System block number | |
# B = File system block size in bytes | |
# L = LBA of bad sector | |
# S = Starting sector of partition as shown by fdisk -lu and (int) denotes the integer part. | |
lba = ARGV[0].to_i | |
dev = ARGV[1] || 'add_your_device_label_here' | |
block_range = ARGV[2].to_i || 64 | |
iterations = ARGV[3].to_i || 100 | |
block_number = ((lba - 2048)*512)/4096 | |
bb_cmd = "sudo badblocks -b 4096 -p #{iterations} -s -vw /dev/#{dev} #{block_number+block_range} #{block_number-block_range}" | |
puts "execute command: #{bb_cmd}? [y/N]" | |
run_command = $stdin.gets.chomp | |
if run_command == ("y" || "Y") | |
`#{bb_cmd}` | |
else | |
puts "run: #{bb_cmd}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment