1. The Importance of Understanding File Systems
Welcome to a new lecture in the course, where we're diving into the fascinating world of Linux file systems. Today we’ll learn how to find devices, understand their structure, and figure out what types of file systems are installed on them. We'll add a bit of command-line magic with tools like lsblk and blkid. Plus, we’ll talk about why programmatically controlled picks for "data digging" are always awesome!
What is a File System?
If the operating system is the "heart" of your computer, then the file system is its "nervous system." It's what organizes and manages access to data on storage devices (hard drives, SSDs, USB drives). It determines how data is stored, read, and written.
Examples of file systems you might encounter:
- ext4 — the standard file system for most Linux distributions.
- NTFS — the file system used by Windows.
- FAT32 — popular for external drives and flash drives.
- XFS, btrfs — more advanced Linux alternatives with features like snapshots.
When you plug in a disk or flash drive into Linux, its file system needs to be "mounted" so the system can start working with it. We’ll manage this (and much more) using commands.
2. The lsblk Command: Overview of Connected Devices
Basics of the lsblk Command
Linux has tons of tools for working with devices and partitions. One of the most useful ones is the lsblk command. Its name stands for "list block devices" — showing a list of block devices.
Simple syntax:
lsblk
This command outputs a table of all block devices in the system, including hard drives, SSDs, USB drives, and their partitions.
Example output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 500G 0 disk
├─sda1 8:1 0 50G 0 part /
├─sda2 8:2 0 200G 0 part /home
└─sda3 8:3 0 250G 0 part
sdb 8:16 1 16G 0 disk
└─sdb1 8:17 1 16G 0 part /media/usb
- NAME: Device name. For example,
sda,sdb. The letters (a,b...) correspond to the order in which devices are detected by the system. - SIZE: The size of the device.
- TYPE: The type of the device. For instance,
diskis a physical disk, whilepartis its partition. - MOUNTPOINT: The path where the device is mounted in the file system.
Useful Flags
lsblk is a pretty flexible command. By using additional options, you can get even more info:
lsblk -f— shows the file system type and UUID (unique identifier) of each device.lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT— outputs only the columns you're interested in (like name, size, file system, mount point).
Example:
lsblk -f
Output:
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 ext4 rootfs 1111-2222-3333-4444 /
├─sda2 ext4 home 5555-6666-7777-8888 /home
└─sda3 swap 9999-AAAA-BBBB-CCCC [SWAP]
sdb vfat USB_DISK AAAA-BBBB /media/usb
3. The blkid Command: The Magic of Unique Identifiers
Sometimes you need detailed info about a storage device or its file system. That’s where the blkid command comes in handy. Its job is to identify devices based on their file system and UUID.
Basics of the blkid Command
Run it without any parameters:
blkid
Example output:
/dev/sda1: UUID="1111-2222-3333-4444" TYPE="ext4"
/dev/sda2: UUID="5555-6666-7777-8888" TYPE="ext4"
/dev/sda3: UUID="9999-AAAA-BBBB-CCCC" TYPE="swap"
/dev/sdb1: UUID="AAAA-BBBB" TYPE="vfat" LABEL="USB_DISK"
- UUID: Unique partition identifier (doesn’t change, even if the device is renamed, e.g., from
sdatosdb). - TYPE: File system type.
- LABEL: Partition label.
Practical Use of UUID
UUID is super important in Linux because devices can dynamically change their names during boot. For instance, what’s called /dev/sda today might become /dev/sdb tomorrow. Thanks to UUID, you can use stable identification for mounting devices. We’ll discuss this further in the next lecture, where we’ll cover working with the /etc/fstab file.
4. Working with Unmounted Devices
Sometimes you plug in a disk or flash drive, but it doesn’t show up as mounted. This might happen because there’s no active file system. Use lsblk and blkid to quickly figure out what’s going on.
Let’s say you connected a USB drive, but in the lsblk output you see:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 16G 0 disk
This means that the sdb device doesn’t have an active partition. Check the blkid output to see if there’s a file system on it:
blkid /dev/sdb
If there’s no response, this confirms that the device isn’t formatted yet. We’ll talk about formatting in the next lecture.
5. Comparison of lsblk and blkid
Both commands are super useful, but their uses are different:
- Use
lsblkto get an overview of the whole system: where everything is, which partitions are mounted. - Use
blkidto get specific details about the file system (type, label, UUID).
Comparison Table
| Command | Main Purpose | Output |
|---|---|---|
lsblk |
Show devices, their partitions, and mount points | NAME, SIZE, TYPE, MOUNTPOINT, FSTYPE, etc. |
blkid |
Query file system info (UUID, LABEL, TYPE) | UUID, TYPE, LABEL |
6. Example: From Finding a Device to Understanding Its Structure
Task
- Find the connected USB device.
- Determine its file system.
- Prepare the device for mounting.
Steps
Connect the device and run:
Find your device. For example,lsblksdb.Check if a file system is present:
blkid /dev/sdbIf there's no file system, you'll get an empty output. This means the device needs to be formatted.
If a file system is present, you'll see its type and UUID. Now it can be used for further work (like mounting).
Now you're armed with knowledge to work with file systems in Linux. In the next lecture, we'll dive into formatting devices, creating file systems, and setting them up for operation! Get ready for the exciting process of turning a "raw" disk into a ready-to-use tool.
GO TO FULL VERSION