In this article, we will instruct steps of mouting a new disk into Linux server. For professional (who have quite long time to experience Linux), you can skip to the next session.
Of course for whom is newbie, please slowly read the following session.
Table of Content:
Partition Overview
Partition is a small pieces disk, it is logical unit to devide the disk into smaller storage space. In one disk, there might be some partition. You can use specified partition for OS, another one for persistent data, and one for your memorable media, which are all stored in just single disk.
Every single action or modify on partition A will be separated with partition B, there is no effect on partition unless physical disk is damaged.
There are 3 main partition type: primary, extended and logical.
Primary: the partition can be used to boot up your OS.
Extended partition: remaining partitions after partitioning primary, extended partitions can contain other logical partions. There is only one extended partition in one disk.
Logical partition: smaller partitions in extended partition, be usually used to store persistent data.
MBR vs GPT
The metadata information is stored on MBR (Master Boot Record) or GPT (GUID Partition Table), which depends on supported specs of your disk. Both MBR & GPT are standard of managing partitions. The information of MBR & GPT is mainly about offset and size of partitions.
MBR
MBR is legacy (or basis) one. A disk will be separated into sectors with fixed size (512 bytes). In Linux, a disk will be partitioning into several partitions with code name, such as: /dev/hda1, /dev/hda2, /dev/sda1, /dev/sda2, etc. We could use the command fdisk or parted to show the information about the MBR enabled disk.
With the legacy disks, we could create upto 4 primary partition including extended partion. All the information of all partitions will be written in the first sector of disk, this sector is named Master Boot Record.
GPT
GUID Partition Table (GPT) is newer one than MBR, it could support upto 128 partitions within 1 disk. The information of all partitions will be written multiple copies in some places in disk. GPT also support checking and modifying data based on CRC (cylic redundancy check).
With the new technology, GPT effectively reduce data loss. Moreover, GPT enable you to create partition with size of over 2TB, instead of maximum 2TB on MBR.
Linux File System (FS)
Every partition is attached with a file system specification. File system will tell OS the way to organize, store and index data within partition. There are some popular file system usually used in Linux:
File system for hard disk drive: ext2, ext3, ext4 (new Linux kernel), BTRFS, JFS, XFS, NTFS, etc.
File system for flash drive: UBIFS, JFFS2, YAFFS, etc.
Other file system: ProcFS, SysFS, TmpFS, DebugFS, etc.
How to configure a brand new disk in Linux
It should follow these steps:
Decide which partition standard: MBR or GPT.
Attach (physical) or Mount (logical in Linux) the disk drive.
Partitioning.
Format file system (Ext4, xfs) for recently created partition.
Mount the partition.
Configure automatically mount partition (usually in /etc/fstab) due to mouting disk on reboot.
You could use these following command to change between GPT and MBR:
# parted /dev/sdb mklabel gpt
OR
# parted /dev/sdb mklabel msdos
With above steps, the partition will disappear after rebooting. We will configure automatically mounting disk in /etc/fstab
Every line in /etc/fstab will define the parameter for mounting on boot. The format for one line is:
<device /dev/...> <mount_point> <file_system> <options> <dump> <pass_num/fsck_order>
The specification for every fields as below:
<device /dev/...>: the partition for mounting. E.g: /dev/sdb1, /dev/sda, etc.
<mount_point>: the path to directory in Linux. E.g: /tmp, /data, /mnt/part1.
<file_system>: file system type. E.g: vfat, ntfs, ext2, ext3, ext4.
<options>: the options when mount, separated by comma
defaults: contain rw,suid,dev,exec,auto,nouser,async
sync: write to disk first before continuing next instructions.
aysnc: write to buffer first, your program/software will continue to work without waiting for successfully writing to disk.
auto/noauto: auto or no-auto mount when booting.
exec/noexec: allow or deny executing binary file in file system.
suid/nosuid: allow or deny using SUID, SGID bit.
ro: read-only partition.
rw: read-write partition.
user: allow user to work with partition.
nouser: only root user could work with partition.
_netdev: flag to indicate that disk attached from network.
<dump>: enable/disable backup filesystem. Set 0 for disable, 1 for enable.
<pass_num/fsck_order>: this parameter will identify the order of fsck (file system check) will be executed in booting process:
0: not check file system.
1: check this partition first. Using for primary partition "/" root.
2: check this partition after first checked partition. Except root "/" partition.
Example: Automatically mount partitition /dev/sdb1 to /mnt/data
# vim /etc/fstab
[...]
/dev/sdb1 /mnt/data ext4 defaults 0 0
Reboot and check again
Comments