RAID Rescue in Linux

Share this post on:

Diagnosing Disk Health with Smartctl and Managing Storage

As a system administrator or a curious Linux enthusiast, understanding the health of your storage devices is crucial. In this blog post, we’ll explore a few essential commands to diagnose disk health and manage storage resources effectively.

1. Smartctl: Assessing Disk Health

What is Smartctl?

Smartctl (Smartmontools) is a command-line utility that interacts with the Self-Monitoring, Analysis, and Reporting Technology (SMART) system in hard drives and solid-state drives. It provides valuable information about the drive’s health, performance, and potential issues.

Using Smartctl

To check the health of a specific disk (e.g., /dev/sdc), run the following command:

sudo smartctl -a /dev/sdc

Pay attention to the following key attributes:

  • Raw_Read_Error_Rate (id 1): Indicates read errors.
  • Reallocated_Sector_Ct (id 5): Reflects the number of reallocated sectors.
  • Spin_Retry_Count (id 10): Monitors spindle motor retries.
  • Reported_Uncorrect (id 187): Tracks uncorrectable errors.
  • Offline_Uncorrectable (id 198): Identifies uncorrectable errors that occurred while the drive was offline.

Remember that even if Smartctl reports a “PASSED” status, abnormal values in these attributes could indicate impending disk failure. If you encounter such issues, consider replacing the drive promptly.

2. Managing Storage with lsblk

Listing Block Devices

The lsblk command provides a concise overview of block devices (disks and partitions). To display relevant information (name, size, filesystem type, type, and mount point), use:

lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT

This output helps you identify available storage devices, their sizes, and their current mount points.

Listing UUIDs

UUIDs (Universally Unique Identifiers) are essential for identifying partitions consistently across reboots. To list UUIDs for all block devices, execute:

lsblk -o NAME,UUID

3. Checking RAID Status with /proc/mdstat

Understanding /proc/mdstat

The /proc/mdstat file provides information about software RAID (Redundant Array of Independent Disks) arrays. It shows the status of RAID devices, including any failures or resync progress.

To view the RAID status, simply run:

cat /proc/mdstat

If you encounter issues like a degraded array or failed disks, investigate further and take corrective actions.

Managing Storage and RAID

1. Zeroing Out a Disk with dd

What Does dd if=/dev/zero of=/dev/sdc bs=1M count=100 Do?

The command sudo dd if=/dev/zero of=/dev/sdc bs=1M count=100 serves a specific purpose: it writes 100 megabytes of zeros to the /dev/sdc block device. Let’s break it down:

  • if=/dev/zero: Specifies the input source as a stream of zeros.
  • of=/dev/sdc: Indicates the output destination, which is our target disk (/dev/sdc).
  • bs=1M: Sets the block size to 1 megabyte.
  • count=100: Limits the operation to writing 100 blocks (100 megabytes).

Why would we do this? Zeroing out a disk is often done before repurposing it or creating a new filesystem. It ensures that any existing data or metadata is wiped clean, preparing the disk for a fresh start.

2. Examining a Disk with mdadm

What Does sudo mdadm --examine /dev/sdc Reveal?

The mdadm utility manages software RAID arrays. When we examine /dev/sdc, we’re checking its metadata for any existing RAID information. This step is crucial before creating or adding disks to an array. It helps prevent conflicts and ensures proper configuration.

3. Creating a RAID 1 Array

Creating a RAID 1 Array with mdadm

RAID 1 (mirroring) duplicates data across multiple disks for redundancy. Let’s look at the provided commands:

  1. sudo mdadm --create /dev/md4 --level=1 --raid-devices=2 /dev/sdc missing: This command creates a RAID 1 array named /dev/md4 with two devices (/dev/sdc and a missing device). The missing device will be replaced later.
  2. sudo mdadm --create /dev/md4 --level=1 --raid-devices=2 /dev/sdc /dev/sdd: Here, we add /dev/sdd to the RAID 1 array. Now, both /dev/sdc and /dev/sdd mirror each other, providing redundancy.

Remember to adjust the commands according to your specific setup and requirements. Properly managed RAID arrays enhance data reliability and availability.

Managing RAID Arrays and Disk Mounting

1. Stopping a RAID Array

Stopping an Active RAID Array

The mdadm utility allows you to manage software RAID arrays. To stop an active array (e.g., /dev/md4), follow these steps:

  1. Unmount the Array: First, unmount the array if it’s currently mounted. Navigate out of the mounted directory using cd ~, and then unmount the device:sudo umount /mnt/md0
  2. Stop the Array: You can stop all active arrays by running:sudo mdadm --stop --scan If you want to stop a specific array (e.g., /dev/md4), pass it to the mdadm --stop command:sudo mdadm --stop /dev/md4

2. Assembling RAID Arrays

Scanning for RAID Devices

To assemble RAID arrays during system startup, use the --assemble --scan option. This command scans for existing arrays and automatically assembles them:

sudo mdadm --assemble --scan

Assembling with Specific Devices

Sometimes you need to manually assemble an array, especially when dealing with failed or missing devices. For example:

  • To assemble /dev/md0 with read-only access and /dev/sdb2 as a component device:sudo mdadm --assemble --readonly /dev/md0 /dev/sdb2
  • To forcefully assemble /dev/md4 with /dev/sdc and /dev/sdd:sudo mdadm --assemble --verbose /dev/md4 /dev/sdc /dev/sdd --force

3. Mounting the RAID Array

Mounting the Array

Once the RAID array is assembled, you can mount it to a directory (e.g., /mnt/8tb):

sudo mount /dev/md4 /mnt/8tb

Remember to adjust the commands based on your specific setup and requirements. Properly managed RAID arrays ensure data redundancy and reliability.

Managing RAID Configuration and System Files

1. Updating mdadm Configuration

Storing RAID Information

When working with RAID arrays, it’s essential to ensure that the array configuration persists across reboots. We achieve this by updating the /etc/mdadm/mdadm.conf file. Let’s break down the steps:

  1. Querying RAID Information: To manage RAID arrays effectively, we need detailed information about their structure, component devices, and current state. Use the following command to display crucial details about a RAID device (e.g., /dev/md0):sudo mdadm -D /dev/md0 The output includes the RAID level, array size, health status, UUID, and roles of component devices1.
  2. Updating mdadm.conf: To ensure automatic reassembly of RAID arrays during boot, append the array details to the mdadm.conf file:sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf This step ensures that the array configuration is preserved even after system restarts2.

2. Editing System Files

Modifying /etc/fstab

The /etc/fstab file contains information about filesystems and their mount points. Use a text editor (e.g., nano) to modify this file:

sudo nano /etc/fstab

In this file, you define which partitions or devices should be mounted at boot. Ensure that your RAID array is correctly listed here to mount it automatically.

Adjusting mdadm.conf

If you need to make manual changes to the mdadm.conf file, use:

sudo nano /etc/mdadm/mdadm.conf

Here, you can fine-tune RAID settings, specify component devices, and manage arrays.

Conclusion

By mastering these commands, you’ll be better equipped to manage RAID arrays and maintain system stability. Remember to adapt the steps to your specific setup and requirements. Happy RAID administration! 🛡️🚀

Share this post on:

Author: tayyebi

Tayyebi works in the role of Director at Gordarg where he is the founder. He is passionate about people, technology, and arts. Mohammad believes in communications, each of us has the power to empower their people with knowledge. He can be seen writing codes, playing music, biking, and reading.

View all posts by tayyebi >






www.Gordarg.com