Skip to content

Instantly share code, notes, and snippets.

@KrzysztofHajdamowicz
Created March 26, 2025 12:47
Show Gist options
  • Save KrzysztofHajdamowicz/1618d33e76542b11dc9a5731d6415769 to your computer and use it in GitHub Desktop.
Save KrzysztofHajdamowicz/1618d33e76542b11dc9a5731d6415769 to your computer and use it in GitHub Desktop.
bcachefs read FUA test
#!/usr/bin/env python3
import os
import glob
def list_bcachefs_devices(base_dir):
# Iterate over each bcachefs filesystem UUID directory
for uuid_dir in glob.glob(os.path.join(base_dir, '*')):
if os.path.isdir(uuid_dir):
print(f"Filesystem UUID: {os.path.basename(uuid_dir)}")
# Iterate over each dev-* directory within the UUID directory
for dev_dir in glob.glob(os.path.join(uuid_dir, 'dev-*')):
if os.path.isdir(dev_dir):
model_file = os.path.join(dev_dir, 'block/device/model')
read_fua_test_file = os.path.join(dev_dir, 'read_fua_test')
# Read and print the content of the model file
if os.path.isfile(model_file):
with open(model_file, 'r') as file:
model_content = file.read().strip()
print(f"Model: {model_content}")
else:
print("Model file not found.")
# Read and print the content of the read_fua_test file
if os.path.isfile(read_fua_test_file):
with open(read_fua_test_file, 'r') as file:
read_fua_test_content = file.read().strip()
print(f"Read FUA Test: {read_fua_test_content}")
else:
print("Read FUA Test file not found.")
print("-" * 40)
# Define the base directory
base_directory = '/sys/fs/bcachefs/'
# Call the function with the base directory
list_bcachefs_devices(base_directory)
@alexminder
Copy link

Hi! Thanks for usefull script. But it fail to find Model if bcachefs drive is partition:

----------------------------------------
Model file not found.
Read FUA Test: This test must be run on an idle drive for accurate results
sda2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment