国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
How to Install Parted on Linux
1. Check Parted Version
2. List Disk Partitions in Linux
3. Change or Switch Partition in Linux
4. Create Partition in Linux
5. Resize Linux Disk?Partition
6. Delete?Linux Partition
7. Rescue Linux Disk Partition
8?Change Linux Partition Flag
Conclusion
Home System Tutorial LINUX 8 Parted Commands to Create and Manage Partitions in Linux

8 Parted Commands to Create and Manage Partitions in Linux

Jun 13, 2025 am 09:49 AM

Parted is a renowned command-line utility designed to facilitate the management of hard disk partitions in a user-friendly manner.

With Parted, you can effortlessly perform tasks such as adding, deleting, shrinking, and extending disk partitions, while also managing the file systems associated with them.

Over time, Parted has undergone significant development and evolution, introducing various enhancements and changes to its functionality. Certain features have been retired, while new capabilities have been introduced, rendering it a versatile tool for partition management.

This tutorial aims to provide a comprehensive introduction to Parted, covering its fundamental concepts and demonstrating practical examples. If you are new to Parted, it is essential to note that any modifications made using Parted are immediately written to the disk.

Therefore, it is crucial to exercise caution while attempting to modify your disk partitions to avoid unintended consequences or data loss. Throughout this tutorial, we will guide you step-by-step, ensuring that you grasp the basics of Parted and understand the potential implications of your actions when working with disk partitions.

If you intend to experiment with Parted, it is recommended to utilize a virtual machine or an old computer/laptop that does not contain any critical data. When making modifications to a disk partition, it is crucial that the partition is not actively in use.

In the case of primary partitions, you may consider booting into rescue mode, which provides a safe environment for performing partition-related tasks without interference from the running operating system. This precautionary approach ensures the integrity of your valuable data and minimizes the risk of unintended consequences during partition manipulation.

Note: You will need to have root access to the machine you will be working on in order to use parted.

How to Install Parted on Linux

On many Linux distributions, parted comes pre-installed. If it is not included in your distro, you can install it with:

$ sudo apt install parted         [On <strong>Debian, Ubuntu and Mint</strong>]
$ sudo yum install parted         [On <strong>RHEL/CentOS/Fedora</strong> and <strong>Rocky/AlmaLinux</strong>]
$ sudo emerge -a sys-apps/parted  [On <strong>Gentoo Linux</strong>]
$ sudo apk add parted             [On <strong>Alpine Linux</strong>]
$ sudo pacman -S parted           [On <strong>Arch Linux</strong>]
$ sudo zypper install parted      [On <strong>OpenSUSE</strong>]    

Once you have made sure that parted is installed, you can proceed further to check out some real-world examples of parted command in the rest of this article.

1. Check Parted Version

To observe a similar message as depicted in the image below, execute the following command. Please note that the output may differ slightly depending on your specific version of Parted. By default, Parted will operate on your primary drive, typically identified as /dev/sda, unless otherwise specified.

$ parted

8 Parted Commands to Create and Manage Partitions in Linux

If you want to exit parted, simply type:

$ quit

2. List Disk Partitions in Linux

Now that parted is started, let’s list the partitions of the selected hard disk. As mentioned earlier, parted chooses your?first drive by default.?To see the disk partitions?run print.

(parted) print

8 Parted Commands to Create and Manage Partitions in Linux

When running print, it will also display the hard disk information and model. Here is an example from a real hard disk (not virtual as shown in the image above) :

<strong style="color: yellow;">(parted) print</strong>

Model: ATA TOSHIBA MQ01ACF0 (scsi)
Disk /dev/sda: 320GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos

Number ?Start ? End ? ?Size ? Type ? ? ?File system ?Flags

?1 ? ? ?1049kB ?256MB ?255MB ?primary ? ext2 ? ? ? ? boot
?2 ? ? ?257MB ? 320GB ?320GB ?extended
?5 ? ? ?257MB ? 320GB ?320GB ?logical ? ? ? ? ? ? ? ?lvm

In the example above, you can see the disk model, capacity sector size, and partition table.

3. Change or Switch Partition in Linux

If you have more than one hard disk, you can easily switch?between disks, by using the “select” command. In the example below, I will switch from /dev/sda to /dev/sdb which is a secondary drive on my system.

To easily switch between disks you can use:

(parted) select /dev/sdX

8 Parted Commands to Create and Manage Partitions in Linux

Change "X" with the letter of the disk to which you wish to switch.

4. Create Partition in Linux

The parted can be used to create primary and logical disk partitions. In this example, I will show you how to create a primary partition, but the steps are the same for logical partitions.

To create a new partition, parted uses “mkpart“. You can give it additional parameters like "primary" or "logical" depending on the partition type that you wish to create.

Before you start creating partitions, it’s important to make sure that you are using (you have selected) the right disk.

Start by using print:

(parted) print

8 Parted Commands to Create and Manage Partitions in Linux

As shown in the above image, we are using a virtual drive of 34 GB. First, we will give the new disk a label and then create a partition and set a file system on it.

Now the first step is to give the new disk a label name with:

(parted) mklabel msdos

Now create the new partition with ?mkpart. The listed units are in megabytes (MB). We will create a 10 GB partition starting from 1 to 10000:

(parted) mkpart
 
Partition type?? primary/extended? primary
File system type?? [ext2]?
Start? 1
End? 10000
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 34.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 
Number? Start ? End ? ? Size? ? Type ? ? File system? Flags
 1? ? ? 1049kB? 10.0GB? 9999MB? primary? ext2 ? ? ? ? lba

8 Parted Commands to Create and Manage Partitions in Linux

Next, ?exit parted with "quit" command. We will format our new partition in the ext4 file system using mkfs. To make this happen run the following command:

# mkfs.ext4 /dev/sdb1

Note: It’s important to select the right disk and partition when executing the above command!

Now let’s verify our results, by printing the partition table on our secondary disk. Under file system column, you should see ext4 or the file system type that you have decided to use for your partition:

8 Parted Commands to Create and Manage Partitions in Linux

5. Resize Linux Disk?Partition

Parted includes multiple useful functions and one of them is "resizepart".?As you have probably figured this out by now, "resizepart" helps you resize a partition.

In the example below,?you will see how to resize an existing partition. For the purpose of this example, we will be using the earlier created partition.

First, you will need to know the number of the partition that you will be resizing. This can be easily found by using "print":

(parted) print

8 Parted Commands to Create and Manage Partitions in Linux

In our example, the partition number is "1". Now run the resizepart command:

(parted) resizepart

You will be asked for the number of the partition that you will resize. Enter its number. After that, you will be asked to set the new ending point for this partition. Remember that by default the units are in MB. In our example, we have set the new partition size to 15 GB:

(parted) resizepart 
Partition number? 1
End?? [10.0GB]? 15000

Now verify the results with "print":

(parted) print

8 Parted Commands to Create and Manage Partitions in Linux

6. Delete?Linux Partition

The next thing you will learn is how to delete a partition from your hard drive. To do this, you will need to use the rm command within parted. To delete a disk partition you will need to know its number.

As mentioned earlier, you can easily obtain this number by using "print". In our example, we will delete the partition with a number 1 from our secondary drive /dev/sdb1:

(parted) rm 1

Verify the results by printing the partitions table:

8 Parted Commands to Create and Manage Partitions in Linux

7. Rescue Linux Disk Partition

Parted supports a “rescue" utility that helps you recover a lost partition between a starting and ending point. If a partition is found within that range, it will attempt to restore it.

Here is an example:

(parted) <strong>rescue</strong>
Start? <strong>1</strong>
End? <strong>15000</strong>
(parted) print
Model: Unknown (unknown)
Disk /dev/sdb1: 15.0GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number Start End Size File system Flags
1 0.00B 15.0GB 15.0GB ext4

8?Change Linux Partition Flag

Using parted, you can change the state of a?flag for disk partitions. The supported flags are:

  1. boot
  2. root
  3. swap
  4. hidden
  5. raid
  6. lvm
  7. lba
  8. legacy_boot
  9. irst
  10. esp
  11. palo

The states can be either "on" or "off". To change a flag simply run "set" command within parted:

(parted) set 2 lba on

The above command sets lba flag to on for the second partition. Verify the results with print:

8 Parted Commands to Create and Manage Partitions in Linux

Conclusion

Parted is a useful and powerful utility that can help you manage your disk partitions in Linux systems. As always, when working with disk partitions you need to be extra careful.

It is strongly recommended to go through parted man pages to learn how you can customize its output and find more information about its capabilities.

If you have any questions or comments, please do not hesitate to use the comment section below.

The above is the detailed content of 8 Parted Commands to Create and Manage Partitions in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SCP Linux Command – Securely Transfer Files in Linux SCP Linux Command – Securely Transfer Files in Linux Jun 20, 2025 am 09:16 AM

Linux administrators should be familiar with the command-line environment. Since GUI (Graphical User Interface) mode in Linux servers is not commonly installed.SSH may be the most popular protocol to enable Linux administrators to manage the servers

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux Jul 05, 2025 am 09:25 AM

LXD is described as the next-generation container and virtual machine manager that offers an immersive for Linux systems running inside containers or as virtual machines. It provides images for an inordinate number of Linux distributions with support

How To Install R Programming Language in Linux How To Install R Programming Language in Linux Jun 23, 2025 am 09:51 AM

R is a widely-used programming language and software environment designed for developing statistical and graphical computing tools within data science. It closely resembles the S programming language and environment, with R serving as an alternative

7 Ways to Speed Up Firefox Browser in Linux Desktop 7 Ways to Speed Up Firefox Browser in Linux Desktop Jul 04, 2025 am 09:18 AM

Firefox browser is the default browser for most modern Linux distributions such as Ubuntu, Mint, and Fedora. Initially, its performance might be impressive, however, with the passage of time, you might notice that your browser is not as fast and resp

Clear Linux Distro - Optimized for Performance and Security Clear Linux Distro - Optimized for Performance and Security Jul 02, 2025 am 09:49 AM

Clear Linux OS is the ideal operating system for people – ahem system admins – who want to have a minimal, secure, and reliable Linux distribution. It is optimized for the Intel architecture, which means that running Clear Linux OS on AMD sys

How to create a self-signed SSL certificate using OpenSSL? How to create a self-signed SSL certificate using OpenSSL? Jul 03, 2025 am 12:30 AM

The key steps for creating a self-signed SSL certificate are as follows: 1. Generate the private key, use the command opensslgenrsa-outselfsigned.key2048 to generate a 2048-bit RSA private key file, optional parameter -aes256 to achieve password protection; 2. Create a certificate request (CSR), run opensslreq-new-keyselfsigned.key-outselfsigned.csr and fill in the relevant information, especially the "CommonName" field; 3. Generate the certificate by self-signed, and use opensslx509-req-days365-inselfsigned.csr-signk

How to Hide Files and Directories in Linux How to Hide Files and Directories in Linux Jun 26, 2025 am 09:13 AM

Do you sometimes share your Linux desktop with family, friends, or coworkers? If so, you may want to hide some personal files and folders. The challenge is figuring out how to conceal these files on a Linux system.In this guide, we will walk through

How to extract a .tar.gz or .zip file? How to extract a .tar.gz or .zip file? Jul 02, 2025 am 12:52 AM

Decompress the .zip file on Windows, you can right-click to select "Extract All", while the .tar.gz file needs to use tools such as 7-Zip or WinRAR; on macOS and Linux, the .zip file can be double-clicked or unzip commanded, and the .tar.gz file can be decompressed by tar command or double-clicked directly. The specific steps are: 1. Windows processing.zip file: right-click → "Extract All"; 2. Windows processing.tar.gz file: Install third-party tools → right-click to decompress; 3. macOS/Linux processing.zip file: double-click or run unzipfilename.zip; 4. macOS/Linux processing.tar

See all articles