Storage¶
Differences between MBR and GPT¶
MBR (Master Boot Record)¶
- Partition Style: Older partitioning method.
- Partition Limit: Supports up to 4 primary partitions. Can be extended to more partitions using extended partitions.
- Disk Size Support: Maximum disk size of 2 TB.
- Compatibility: Widely supported by many operating systems, including older versions.
- Boot Data Location: Stores boot data in the first sector of the disk.
- Data Security: Less resilient to corruption, as the boot data is stored in a single location.
GPT (GUID Partition Table)¶
- Partition Style: Modern partitioning method, part of the UEFI standard.
- Partition Limit: Supports up to 128 primary partitions without the need for extended partitions.
- Disk Size Support: Supports disks larger than 2 TB.
- Compatibility: Requires UEFI firmware, not supported by older systems.
- Boot Data Location: Stores multiple copies of boot data across the disk for redundancy.
- Data Security: More resilient to corruption with CRC32 checksums for header and partition tables.
Summary¶
- MBR is suitable for older systems and smaller drives (up to 2 TB) but has limitations in partition numbers and resilience.
- GPT is ideal for modern systems with large drives and offers better data security and flexibility in partition management.
Differences between fdisk, gdisk, and parted¶
fdisk¶
- Usage: Primarily used for managing MBR partition tables.
- Compatibility: Works with MBR and, to a limited extent, GPT.
- Interface: Command-line interface with interactive prompts.
- Functionality: Basic partitioning tasks such as creating, deleting, and resizing partitions.
- Support: Limited support for GPT, mainly focuses on MBR.
gdisk¶
- Usage: Designed for managing GPT partition tables.
- Compatibility: Works exclusively with GPT.
- Interface: Command-line interface similar to fdisk, but tailored for GPT.
- Functionality: Advanced GPT-specific features such as backing up and restoring partition tables, and repairing GPT structures.
- Support: Full support for GPT, not suitable for MBR.
parted¶
- Usage: Versatile tool for managing both MBR and GPT partition tables.
- Compatibility: Supports both MBR and GPT.
- Interface: Command-line interface with both interactive and scriptable modes.
- Functionality: Comprehensive partition management including creating, deleting, resizing, moving, and copying partitions. Also supports file system creation and management.
- Support: Broad support for various disk labels and file systems, making it suitable for a wide range of tasks.
Summary¶
- fdisk is best for basic MBR partition management with limited GPT support.
- gdisk is specialized for advanced GPT partition management.
- parted offers versatile and comprehensive partition management for both MBR and GPT, along with additional file system support.
Differences between XFS and EXT4¶
XFS¶
- Developer: Originally developed by SGI (Silicon Graphics Inc).
- Release Date: Initially released in 1994.
- File System Type: 64-bit journaling file system.
- Maximum File Size: Up to 8 exabytes.
- Maximum Volume Size: Up to 8 exabytes.
- Performance: Excellent for large files and parallel I/O operations. Known for high performance with large amounts of data.
- Defragmentation: Supports online defragmentation.
- Snapshot Support: Relies on external tools like LVM (Logical Volume Manager) for snapshot capabilities.
- Quota Management: Advanced quota management including project quotas.
- Use Case: Ideal for environments that require handling large files and high performance, such as media servers and enterprise environments.
EXT4¶
- Developer: Developed by the open-source community, primarily driven by Linux kernel developers.
- Release Date: Introduced in 2008 as an evolution of EXT3.
- File System Type: 64-bit journaling file system.
- Maximum File Size: Up to 16 terabytes.
- Maximum Volume Size: Up to 1 exabyte.
- Performance: Balanced performance for general-purpose use. Optimized for both small and large files.
- Defragmentation: Limited support for online defragmentation.
- Snapshot Support: Relies on external tools like LVM for snapshot capabilities.
- Quota Management: Standard quota management.
- Use Case: Versatile and suitable for a wide range of applications, from personal use to enterprise servers.
Summary¶
- XFS excels in handling large files and high-performance environments, offering features like online defragmentation and advanced quota management.
- EXT4 provides a balanced performance for both small and large files, with broad compatibility and ease of use for general-purpose applications.
Explanation of the Command parted /dev/vda
¶
The command parted /dev/vda
is used to start an interactive session with the parted
utility on a specific storage device.
Breakdown of the Command¶
- parted: This is the command-line utility used for managing disk partitions.
- /dev/vda: This specifies the device you want to work on. In this case,
/dev/vda
refers to a virtual disk commonly used in virtualized environments.
Interactive Session¶
When you run parted /dev/vda
without additional arguments, it opens an interactive shell where you can enter various parted
commands to manage the disk. In this session, you can:
- print: Display the partition table.
- mklabel: Create a new partition table.
- mkpart: Create a new partition.
- rm: Remove a partition.
- resizepart: Resize a partition.
- quit: Exit the interactive session.
Example Interaction¶
(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 538MB 537MB ext4
2 538MB 21.5GB 20.9GB ext4
(parted) mkpart
Partition type? primary/extended? primary
File system type? [ext2]? ext4
Start? 1GB
End? 5GB
(parted) quit
Explanation of the Command parted /dev/vdb mklabel msdos
¶
The command parted /dev/vdb mklabel msdos
is used to create a new partition table on a specific storage device with the MBR (Master Boot Record) partitioning scheme.
Breakdown of the Command¶
- parted: This is the command-line utility used for managing disk partitions.
- /dev/vdb: This specifies the device you want to work on. In this case,
/dev/vdb
refers to the target disk. - mklabel: This
parted
command is used to create a new partition table on the disk. - msdos: This specifies the type of partition table to create.
msdos
refers to the MBR (Master Boot Record) partitioning scheme.
Effect of the Command¶
Running this command will:
- Erase Existing Partitions: All existing partitions and data on
/dev/vdb
will be erased. This is because creating a new partition table overwrites the existing one. - Create MBR Partition Table: The disk will be set up with an MBR partition table, which supports up to 4 primary partitions (or 3 primary partitions and 1 extended partition, which can contain additional logical partitions).
Example Usage¶
Example Output¶
After confirmation, the MBR partition table is created on the specified disk.
Summary¶
- The
parted /dev/vdb mklabel msdos
command is used to initialize a disk with an MBR partition table. - This operation will erase all existing data on the disk.
- Useful for setting up new disks or re-partitioning existing disks with the MBR scheme.
Explanation of "The mklabel subcommand wipes the existing partition table"¶
Key Points¶
- mklabel Subcommand: This subcommand in
parted
is used to create a new partition table (label) on a disk. - Wipes Existing Partition Table: When you use
mklabel
, it overwrites the existing partition table. This means all information about the current partitions is erased. - Reuse the Disk: Use
mklabel
when you intend to reuse the disk for new partitions and are not concerned about preserving existing data.
Implications of Using mklabel¶
- Data Erasure: Creating a new partition table will make all current data on the disk inaccessible because the information about the partitions (where data is stored) is erased.
- New Partition Boundaries: If the new partition table (label) changes where the partitions are located on the disk (partition boundaries), then the existing data will no longer be properly indexed or accessible.
Example¶
Before mklabel¶
- Disk has existing partitions with data.
- Partition table maps data to specific locations on the disk.
After mklabel¶
- Partition table is overwritten.
- No information on existing partitions.
- Data on the disk becomes inaccessible because the new partition table does not reference it.
Practical Usage¶
- Disk Reinitialization:
mklabel
is useful when you need to reinitialize a disk, such as setting up a new file system from scratch or completely repurposing the disk. - Data Backup: Ensure you back up any important data before using
mklabel
, as it will destroy existing partition information and make data recovery difficult.
Summary¶
- The
mklabel
subcommand is a powerful tool for reinitializing disks but should be used with caution. - It effectively wipes out all existing partition information, making current data on the disk inaccessible.
- Ideal for situations where the existing data is no longer needed, and the disk needs to be reused for new purposes.
Differences between mklabel and mkpart¶
mklabel¶
- Purpose: Used to create a new partition table on a disk.
- Effect: Erases all existing partitions and data on the disk, as it overwrites the current partition table.
- Usage: Typically used to reinitialize a disk or change the partitioning scheme.
- Syntax:
parted /dev/sdX mklabel <label-type>
- Example:
parted /dev/sda mklabel gpt
- Partition Table Types: Common types include
msdos
(MBR) andgpt
. - When to Use: When you want to start fresh with a new partition layout and do not need the existing data.
mkpart¶
- Purpose: Used to create a new partition on a disk.
- Effect: Adds a partition to the existing partition table without affecting other partitions.
- Usage: Used to define specific partitions within the existing partition table structure.
- Syntax:
parted /dev/sdX mkpart <part-type> <fs-type> <start> <end>
- Example:
parted /dev/sda mkpart primary ext4 1GB 10GB
- Partition Types: Can specify
primary
,extended
, orlogical
for MBR; for GPT, just the partition name. - When to Use: When you want to create a new partition within the current disk layout without deleting existing data.
Summary¶
- mklabel:
- Function: Creates a new partition table, erasing all existing data and partitions.
- Use Case: Reinitializing a disk or changing the partitioning scheme.
-
Effect: Completely resets the disk's partitioning structure.
-
mkpart:
- Function: Creates a new partition within the existing partition table.
- Use Case: Adding new partitions without affecting existing ones.
- Effect: Modifies the partition table to include the new partition while preserving existing data and partitions.
Using mklabel
is a more drastic action compared to mkpart
, as it removes all existing data and pa
Explanation of the fstab Entry¶
This fstab
entry specifies how a file system should be mounted. Let's break it down:
Breakdown of Each Field¶
1. Device (UUID)¶
- Field:
UUID=7a20315d-ed8b-4e75-a5b6-24ff9e1f9838
- Explanation: This specifies the device to be mounted using its UUID (Universally Unique Identifier). The UUID is unique to each file system and is stored in the partition superblock when the file system is created.
- Alternative: You can also use the device file path, such as
/dev/vdb1
.
2. Mount Point¶
- Field:
/dbdata
- Explanation: This is the directory where the device will be accessible in the file system. The directory must exist; if it doesn't, create it using the
mkdir
command (e.g.,mkdir /dbdata
).
3. File System Type¶
- Field:
xfs
- Explanation: This specifies the type of file system on the device. Common types include
xfs
andext4
.
4. Mount Options¶
- Field:
defaults
- Explanation: This is a comma-separated list of options to apply when mounting the device.
defaults
is a set of commonly used options. Refer to themount(8)
man page for other available options.
5. Dump Field¶
- Field:
0
- Explanation: This field is used by the
dump
command to determine if the device should be backed up. Most backup applications do not use this field, and0
typically means the device will not be backed up.
6. fsck Order¶
- Field:
0
- Explanation: This field determines the order in which the
fsck
command should check the file systems at boot to ensure they are clean. - For XFS: Set to
0
because XFS does not usefsck
for this purpose. - For ext4: Set to
1
for the root file system and2
for other ext4 file systems. This ensures the root file system is checked first, followed by other file systems on separate disks concurrently and on the same disk sequentially.
Example¶
Explanation¶
- UUID=7a20315d-ed8b-4e75-a5b6-24ff9e1f9838: Mounts the device with this UUID.
- /dbdata: Makes the device accessible at the
/dbdata
directory. - xfs: Specifies that the file system type is XFS.
- defaults: Uses the default mount options.
- 0: Device is not backed up by the
dump
command. - 0:
fsck
does not check the XFS file system at boot.
This entry in /etc/fstab
ensures that the specified device is automatically mounted at boot with the given options.