In this section we will covering everything one need to know regarding storage in Linux system.
Physical storage / Block storage
- Storage devices such as hard disk drive (HDD), solid state drive (SSD) are block devices, which means that data is read from and written to the device in fixed size blocks or chunks of space by Kernel.
Disk Partitioning
- Disk can be formatted and used without partitioning. It is generally recommended to partition new drive for greater flexibility.
- Disk partitioning is process to segment available storage into smaller units for different purpose. Each partition can be treated as same way as a drive itself.
- Operating system look into partition table (/etc/fstab) to find the partition.
- fdisk command is used to partition disk drive.
Partitions formats
- It cannot be used for disks over 2TB in size
- It can only have a maximum of four primary partitions.
- It resolves some of the issues inherent with MBR
- GPT can have many more partitions per disk.
- GPT is the better choice unless your operating system prevents you from using it
Formatting and Filesystems
- To use newly added raw disk. It must be formatted.
- Formatting is process of writing a filesystem to the disk and preparing it for file operations
- Without a filesystem, you could not use the storage device for any standard filesystem operations
- Some of the more popular filesystems for Linux are:Ext4 : It is most popular one and a successor to Ext2 and Ext3XFSBtrfsZFS
- mkfs command is used to format and assign a filesystem.
Mounting formatted Block Devices
- Mounting is the process of attaching a formatted partition or drive to a directory within the Linux filesystem.
- The drive’s contents can then be accessed from that directory.
Making Mounts Permanent with /etc/fstab
- OS uses /etc/fstab file (filesystem table) to determine which filesystems(partition) to mount during the boot process.
- No mount will be done on reboot, If entry did not find in this file.
Block device in /dev directory
- In Linux, almost everything is represented by a file somewhere in the filesystem hierarchy.
- storage drives are represented on the system as files in the /dev directory.
- File with sd or hd followed by a letter represents storage device. E.g /dev/sda.
- Block device can be seen in Linux with below command.
Command to partition drive
- Select storage disk you want to create partitions on by running the following command.
- Run the n command to create a new partition.
- Select the partition number by typing the default number (2).
- After that, you are asked for the starting and ending sector of your hard drive.
- The last prompt is related to the size of the partition.
- A message appears confirming that the partition is created.
- To write the changes on disk, run the w command.
- Verify that the partition is created by running the following command.
Format Partition command
# sudo mkfs -t ext4 /dev/sdb1
Mount Partition commands
# sudo mount -t auto /dev/sbd1 /mt/sdb1
Verify if partition is mounted by using the df hT command.
Nice explanation great work