Categories
Tags
Advanced Concepts AI Algorithms Back-End C C++ CMD Commands Comparison Design Development Examples Extensions Flash Drive Front-End Full-Stack Git Guide Language Linux Machine Learning MacOS Music Neural Networks Overview Productivity Programming Recovery Shell Technology Terminal Tools VSCode Web Development Windows
299 words
1 minutes
Flash Drive Setup and Recovery on Linux
Flash Drive Setup and Recovery on Linux
This document provides a step-by-step guide to checking, recovering, and formatting a flash drive on Linux.
Step 1: Verify Disk Information
List all connected drives to identify the correct device:
sudo fdisk -l
- This command lists all disk partitions and details such as disk size, sector size, and partition layout.
- Output will help confirm the actual capacity of the flash drive (e.g.,
/dev/sdb
).
Step 2: Check for Errors
Install and use smartctl
to perform a health check:
- Install the
smartmontools
package:sudo pacman -S smartmontools
- Get detailed device information:
sudo smartctl -i /dev/sdb
- Run a non-destructive health test (if supported):
sudo smartctl -t long /dev/sdb
- Note: If tests fail with errors like “unsupported SCSI opcode,” the device might not support SMART features.
Step 3: Wipe the Disk
To erase all data, including the partition table:
sudo dd if=/dev/zero of=/dev/sdb bs=1M count=10
- Explanation:
if=/dev/zero
: Input file is/dev/zero
(produces zeroed-out bytes).of=/dev/sdb
: Output file is the flash drive.bs=1M
: Block size is 1MB.count=10
: Write 10 blocks (10MB).
Step 4: Create a New Partition Table
Launch fdisk
to create a new partition layout:
sudo fdisk /dev/sdb
- Commands in
fdisk
:- Create a new partition table (MBR):
o
- Create a primary partition:
n
- Accept defaults for partition number, start, and end sectors to use the entire disk.
- Write changes to disk:
w
- Create a new partition table (MBR):
Verify the partition table:
sudo fdisk -l /dev/sdb
Step 5: Format the Partition
Format the newly created partition with your desired file system:
- For Linux-only systems (ext4):
sudo mkfs.ext4 /dev/sdb1
- For cross-platform compatibility (FAT32):
sudo mkfs.vfat -F 32 /dev/sdb1
Step 6: Mount the Partition
- Create a mount point:
sudo mkdir /mnt/flashdrive
- Mount the partition:
sudo mount /dev/sdb1 /mnt/flashdrive
- Verify the mount:
df -h
Optional: Test Flash Drive for Counterfeiting
If the drive shows incorrect capacity, use f3
to verify its true size:
- Install
f3
:sudo pacman -S f3
- Test the drive:
sudo f3probe --destructive --time-ops /dev/sdb
Conclusion
By following these steps, you can recover and set up a flash drive, ensuring its capacity and functionality are restored. For additional automation, you can add the partition to /etc/fstab
for persistent mounting.
Flash Drive Setup and Recovery on Linux
https://banije.vercel.app/posts/flash_drive_setup/