Managing Disk Partitions
Creating Filesystems
Mounting and Unmounting Filesystems
Maintaining Filesystems
Advanced Disk Management
RAID
LVM
Partition Types
Device File Name: /dev/sda1
Partitioning tools:
fdisk
parted
gparted
MBR partitioning scheme allows you to have up to 4 partitions on a drive, one of those partitions can be an "extended partition", which acts as a container for 16 "logical partitions". The partitions which are not inside the extended partition are called "primary partitions".
In layman's words: when a partition is created simply on a drive (in a MBR partition-scheme), it is called "primary", when it is created within an extended partition, it is called "logical". Read more about it below:
Read about types pf drives:
​
sudo fdisk -l
=> gives the information about the drive(s)
sudo fdisk /dev/sdb
=> select the disk you want to work with. I choose sdb
, for example. Once done, you will get the program and the program will help you go through this simple process.
Prepare a partition to accept the data. Once you create the partition, it is not ready for accept the data, you have to format it using some sort of a file system that file system decides how the files and folders are laid out in the partition.
For Linux:
ext4: default filesystem for most Linux distros.
xfs: more robust than ext4. Default filesystem for Red Hat Enterprise distros. Also default for SUSE "/home" partition.
btrfs: Default filesystem for SUSE "/" partition. Available in RHEL7 as "technology preview", but now deprecated.
sudo mkfs.ext4 -m 0 /dev/sdb1
After having formatted a file system, you need to mount it somewhere to make it accessible. There are many places where you can mount the drive but in the following example, I have mounted in inside /mnt/data
In the following example, I am formatting the /dev/sdc1
to xfs and then mounting it to a directory called my-sdc1-drive
inside /mnt
. Full process:
Remember this is not a persistent mounting at this point. If you reboot the machine now, the mounting will go away and you will have to mount it again. Check out /etc/fstab
for persistent mounting.
First check the block id of the device you want to mount. In this example, I want to mount sdb1 to be mounted permanently: sudo blkid /dev/sdb1
Then, copied the UUID and pasted it to the /etc/fstab
After pasting it, you can specify where you want it to be mounted. Remember, you can mount it anywhere.You just need to create a folder and mount the partition it there.
You can check it by the command mount | grep 'sd'
Imagine you want to change the permission on the sdb1 from rw to ro. You can of course go ahead umount it and change the permission and remount it but there is easier way to do so. sudo mount -o remount,ro /dev/sdb1 /mnt/data
Toots of the trade
fsck - check if the disk is corrupted
df and du - check the space availability
lsof - check what filesystem is using it. For example, if you want to umount a drive, and something is using it, using this tool, you can know what is using the drive.
fuser - almost the same function as lsof
dumpe2fs - info about parameters set on the filesystem
tune2fs - modify that info if you need to.
Never run fsck against a mounted device or you may end up corrupting the drive. Always unmount first.
-b
superblock => it is the metadata of the filesystem. Information like the type of file system, the size, status, etc. If you lose your superblock on the filesystem, you lose access to the file system.