Disk Management on Linux
In this article, I resume some bash commands to check up or manage partitions on a linux system. The commands would check what partitions there are on each disk and other details like the total size, used up space and file system etc.
List block devices lsblk
lsblk
lists the different partitions and block devices in the system with their ids. The command prints all block devices (except RAM disks) in a tree-like format.
lsblk
Mount a disk
We have to create a directory which will be the mount point for the device. The command mount
mounts the device to the mount point.
sudo mkdir /{your directory name here}
sudo mount /dev/{specific device id} /{your directory name here that is already created}
unmount a disk
umount
command unmounts any mounted filesystem on your system. It requires disk name or mount point name to unmount currently mounted disk.
sudo umount /dev/sdb
Permanently mount a disk
Set the system so that your devices will be automatically mounted. All information about device, format and mountpoint can be checked on /etc/fstab
cat /etc/fstab
To add a new drive to the mounted devices, edit /etc/fstab
sudo vi /etc/fstab
This file is a table of 6 columns, each row describes a mounted devices.
- Device specifies the mount device. These are usually device filenames. Most distributions now specify partitions by their labels or UUIDs.
- Mount point specifies the mount point, the directory where the partition or disk will be mounted. This should usually be an empty directory in another file system.
- File system type specifies the file system type i.e. ext4
- Options specifies the mount options. Most file systems support several mount options, which modify how the kernel treats the file system. You may specify multiple mount options, separated by commas.
- Backup operation contains a 1 if
dump
should back up a partition or a 0 if it shouldn’t. If you never usedump
you can ignore this option. - File system check order specifies the order in which
fsck
checks the device/partition for errors at boot time. A 0 means that fsck should not check a file system. Higher numbers represent the check order. The root partition should have a value of 1 , and all others that need to be checked should have a value of 2.
Once, fstab is filled, we have to test it.
sudo mount -a
If this command works, then we can reboot the system. By experience, errors returned by mount
is often due to a bad file system type.
sudo reboot
References
Learning the bash Shell: Unix Shell Programming
Cameron Newham and Bill Rosenblatt
O'Reilly Media, 1995. ISBN‑13: 978-0596009656
Relevant Tags
About the Author
Latest Articles
-
Chado: the GMOD Database Schema
Chado is a relational database schema that underlies many GMOD installations. It is capable of representing many of the general classes of data frequently encountered in modern biology such as sequence, sequence comparisons, phenotypes, genotypes, ontologies, publications, and phylogeny. It has been designed to handle complex representations of biological knowledge and is the most sophisticated relational schemas currently available in molecular biology.JAN 2025 · PIERRE-EDOUARD GUERIN -
Error Messages with a CLI
I am an anxious person. So error messages always makes my heart beat faster. Hopefully, following the Pareto Principle, 80% of error messages are mild while 20% are the really tough one. The point is to solve the first kind as quickly as possible and effortless. To do so, allow the user to solve the issue by himself with clear messages and hints (in the case of errors related to input files or parameters). Clear presentation of the context and precise localization of the error in the code will save a lot of useless and tedious work to the developer. The time spared on the easy errors just by having better messages, then can be reallocated to the second kind of errors, the troublemakers.NOV 2024 · PIERRE-EDOUARD GUERIN -
Generative AI: Integrate openAI API with Python
I was fortunate to follow the course of Sven Warris about software tools to integrate genAI into your own work and applications. The course is aimed at data scientists and bioinformaticians.MAY 2024 · PIERRE-EDOUARD GUERIN