A Look Inside Linux series
A series of short topics on how Linux works and how to make it work the way you want it to, which I present during the weekly sessions of the Linux User Net. The target audience is Hams who are new to Linux and want to know more about it, as well as experienced Linux users who can learn more about their chosen operating system. These are my notes for the presentations. (Russ, KC7MM)
We own computers in order to work with data. We acquire it, we process it, and we store it – lots of it. We store it on hard disk drives, on solid state drives, flash memory cards, in the cloud.
Data is moved into and out of storage in discrete chunks, or blocks. As a result, we refer to data storage devices as block devices.
Block devices got some notice last time, when we looked at the /dev directory in the Linux file system. Today we'll take a more detailed look at how to work with them in Linux.
Storage is an area in which every computer is unique. That means there's little point in talking about specific devices and configurations. What I'll do instead is to use the utility programs present on most Linux systems to show how to manage them. If you have a Linux box handy, you can open up a terminal follow along with me. That will let you see how your system is set up.
We'll spend most of our time today looking at local storage: devices physically attached to our machine.
Every computer needs to have some local data storage capacity. Even cloud devices such as tablets and Chromebooks need somewhere to store their operating system, configuration, and some user data. A Linux box generally will have much more space for user data, plus the capability of replacing or expanding it. Let's see how storage works in a Linux system.
There are two general classes of storage in use today:
The general procedures for handling these drives are the same for both classes, the primary difference being the need to dynamically connect and disconnect removable drives while the system is running.
Finding the block devices on a system is easy. In a terminal, type
lsblk. This will produce a list of block devices, with some useful information on each one. I'm composing my notes for this topic on Linux Mint laptop. It has a single solid-state drive, and is set up for dual boot with Windows 10. When I run lsblk on it, I get the following output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT nvme0n1 259:0 0 477G 0 disk ├─nvme0n1p1 259:1 0 260M 0 part /boot/efi ├─nvme0n1p2 259:2 0 16M 0 part ├─nvme0n1p3 259:3 0 104.2G 0 part ├─nvme0n1p4 259:4 0 1000M 0 part └─nvme0n1p5 259:5 0 371.5G 0 part /
It shows six devices, one disk and five partitions. For each device it gives information that's useful to me:
This works for all block devices that are present – fixed and removable.
Before a device can be used by the system, it must be properly prepared. This is a two-step process:
Why is he formatting process necessary, given that the device already is mapped to /dev subdirectory by its driver?
In Linux, disk partitions are managed by using a partition editor:
A quick way to view the partitions currently on your system is to open a terminal and type:
sudo parted -l. This will produce a list of partitions, along with their size and installed file system. You also can view them by running gparted. When I do that on my dual-boot laptop, it shows all the partitions, including those for Windows:
Model: KXG6AZNV512G TOSHIBA (nvme) Disk /dev/nvme0n1: 512GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 274MB 273MB fat32 EFI system partition boot, hidden, esp 2 274MB 290MB 16.8MB Microsoft reserved partition msftres 3 290MB 112GB 112GB ntfs Basic data partition msftdata 5 112GB 511GB 399GB ext4 4 511GB 512GB 1049MB ntfs Basic data partition hidden, diag
The basic partitioning process is:
Once a partition is created and formatted, it is used by mounting it on a directory in the Linux file system.
Mounting a partition does two things:
You can get a list of currently-mounted partition by using the mount command. Simply type
mount in a terminal, and you'll see which partitions are mounted where.
There are multiple ways to mount a partition:
Linux comes with built-in tools for using data storage on another host on a network. It's a sizeable topic for another day, but there are some things worth mentioning now.
Using network storage is similar in many ways to local storage. In particular, remote devices are mounted to a directory in the Linux file system, making their use transparent to the user.
There are two main methods of working with remote storage in Linux: