Uncategorized 05/04/2026 6 דק׳ קריאה

Mastering Disk Partitioning with Parted: A Comprehensive Pentest Course

פבלו רותם · 0 תגובות

Course #428: Using Parted for Effective Disk Management

# Course #428: Using Parted for Effective Disk Management ## Section 5/5: Advanced Techniques with Parted ### Installation and Configuration on Kali Linux Kali Linux comes with a variety of tools pre-installed, and `parted` is typically included in these distributions. However, it is essential to ensure that you have the latest version and that it is properly installed. Here’s how to check and configure `parted` on your Kali Linux system. #### Checking Installation Open your terminal and run the following command to check if `parted` is installed: If `parted` is installed, you will see the version information. If it is not installed, you can install it using the following command:

sudo apt update
sudo apt install parted
#### Configuration `parted` does not require extensive configuration but does need to be run with administrative privileges to modify disk partitions. You can use it directly from the terminal: You will enter the interactive `parted` shell, where you can execute various commands to manage disk partitions effectively. ### Step-by-Step Usage and Real-World Use Cases In this section, we will cover the various functionalities of `parted` with practical examples. #### 1. Understanding Partitions Before you start using `parted`, it's critical to understand the concept of partitions. A partition is a division of a disk drive into sections, each of which can be managed independently. This is essential for multi-boot environments and efficient disk usage. #### 2. Listing Partitions To begin, you can use `parted` to view the current partitions on your disk. For example, to list the partitions on `/dev/sda`, use: This command will display a summary of the disk, including the partition table type, the partitions themselves, their sizes, and their file systems. #### 3. Creating a New Partition Let’s create a new partition. First, we need to resize the existing partition to make space for the new one. Assume you want to resize `/dev/sda1`:

sudo parted /dev/sda
(parted) resizepart 1 50GB
Now, create a new partition:

(parted) mkpart primary ext4 50GB 100GB
This command creates a new primary partition of type `ext4`, starting at 50GB and ending at 100GB. #### 4. Deleting a Partition To delete a partition, you can use the `rm` command. For instance, if you want to delete partition 2: This will remove the second partition from the disk. #### 5. Formatting a Partition Once a new partition is created, it’s crucial to format it before using it: This formats the second partition (`sda2`) to the `ext4` file system. #### 6. Mounting a Partition After formatting, you need to mount the partition to access it. First, create a mount point: Now mount the partition: #### 7. Real-World Use Case: Setting Up Dual Boot One of the most common real-world use cases for `parted` is setting up a dual boot system. Here’s a step-by-step process: 1. **Backup Your Data**: Always ensure your data is backed up before modifying disk partitions. 2. **Shrink Your Current OS Partition**: Use `parted` to resize your existing partition to make room for the new OS. 3. **Create a New Partition for the Second OS**: As demonstrated above, create a partition for the new operating system. 4. **Install the New OS**: Boot from the installation media of the second OS, and when prompted, select the newly created partition for installation. 5. **Configure Bootloader**: After installation, make sure to configure your bootloader (like GRUB) to recognize both OS installations. ### Advanced Commands and Techniques Now that we have covered basic operations, let’s dive into some advanced commands and techniques available in `parted`. #### 1. Scripting with Parted For automation, you can run `parted` in script mode without user interaction. Create a script file, e.g., `partition_script.sed`, with the following content:

mklabel gpt
mkpart primary ext4 0% 50%
mkpart primary ext4 50% 100%
And execute it using: sudo parted /dev/sda < partition_script.sed [/dm_code_snippet] #### 2. Repairing File Systems Sometimes, partitions can become corrupted. While `parted` does not repair file systems, you can use it alongside `fsck`: [dm_code_snippet background="yes" background-mobile="yes" slim="yes" line-numbers="no" bg-color="#abb8c3" theme="dark" language="php" wrapped="yes" height="" copy-text="העתק את הקוד" copy-confirmed="הועתק"] sudo fsck /dev/sda1 [/dm_code_snippet] #### 3. Handling GPT and MBR Formats `parted` can handle both GUID Partition Table (GPT) and Master Boot Record (MBR) partition formats. To create a GPT partition table, use: [dm_code_snippet background="yes" background-mobile="yes" slim="yes" line-numbers="no" bg-color="#abb8c3" theme="dark" language="php" wrapped="yes" height="" copy-text="העתק את הקוד" copy-confirmed="הועתק"] sudo parted /dev/sda mklabel gpt [/dm_code_snippet] For MBR, replace `gpt` with `msdos`. ### External References 1. Official Documentation: [GNU Parted Manual](https://www.gnu.org/software/parted/manual/) 2. Detailed Guides: [Linux Parted Guide](https://linuxconfig.org/how-to-use-parted-in-linux) ### Conclusion In this final section, we covered advanced usage of `parted`, including installation, configuration, and step-by-step examples of managing disk partitions effectively. With this knowledge, you can now confidently navigate disk management tasks and apply these techniques in real-world scenarios. For further exploration, practice these commands in a safe environment, and consider experimenting with various disk configurations. As always, ensure you back up your data before making changes to disk partitions. --- Made by pablo rotem / פבלו רותם