Storage media management is a fundamental aspect of working with Linux systems. Whether you’re a new Linux user or looking to expand your knowledge, understanding how to work with different storage devices is essential. This guide will walk you through the basics of storage media management in Linux, from mounting devices to creating file systems.
The mount
command attaches storage devices to your file system, while umount
safely detaches them.
# Mount a USB drive sudo mount /dev/sdb1 /mnt/usb # Unmount a device sudo umount /dev/sdb1
Use fsck
to check and repair file system errors:
# Check file system integrity sudo fsck /dev/sdb1 # Force check on next reboot sudo touch /forcefsck
fdisk
is used for creating, deleting, and managing partitions:
# Start fdisk for a device sudo fdisk /dev/sdb # Common commands: # p - print partition table # n - create new partition # d - delete partition # w - write changes
Create new file systems using mkfs
:
# Create ext4 filesystem sudo mkfs -t ext4 /dev/sdb1 # Create FAT32 filesystem sudo mkfs -t vfat /dev/sdb1
lsblk
sudo mkdir /mnt/usb
sudo mount /dev/sdb1 /mnt/usb
# Mount CD/DVD sudo mount /dev/cdrom /mnt/cdrom # Create ISO image dd if=/dev/cdrom of=backup.iso
# Mount NFS share sudo mount -t nfs server:/share /mnt/nfs # Mount Samba share sudo mount -t cifs //server/share /mnt/samba
Problem: Create a new partition and format it with ext4.
Steps:
lsblk
fdisk
Solution:
sudo fdisk /dev/sdb # Use n for new partition sudo mkfs.ext4 /dev/sdb1 sudo mount /dev/sdb1 /mnt/data df -h /mnt/data
Q: How do I safely remove a USB drive? A: Always use umount
before physical removal to prevent data corruption.
Q: Why can’t I mount my drive? A: Check permissions, ensure the mount point exists, and verify the file system type.
Q: How do I check disk space? A: Use df -h
for mounted file systems and du -h
for directory usage.
Q: Can Linux read NTFS drives? A: Yes, with the ntfs-3g driver installed.
Q: How do I repair a corrupted file system? A: Use fsck
in recovery mode or from a live USB.