How to partition a disk using parted
The key to using parted partition disks is to master several steps: 1. Preparation: Confirm the target disk device name (such as /dev/sdb) and judge its partition table type. If it is less than 2TB, use MSDOS (MBR) and if it is greater than 2TB, use GPT; 2. Create a partition table: After entering parted operation mode, execute the mklabel command to select gpt or msdos, this step will clear the disk data; 3. Start partition: Use the mkpart command to specify the partition type, file system and start and end location, such as mkpart primary ext4 0GB 50GB, and continue to add other partitions; 4. Format and mount the partition: manually execute mkfs.ext4 and other commands to format, and then create mount points through mkdir and mount to complete the mount. At the same time, you can edit /etc/fstab to achieve automatic mount on the power. The entire process requires attention to disk identification accuracy and partition alignment to avoid data loss due to incorrect operations.
Using parted
partition disks is actually not difficult, just master a few key points and you can complete them smoothly. It is a command line tool suitable for operating in Linux systems without a graphical interface, such as a server environment.
1. Preparation: Confirm the target disk and file system type
Before starting partitioning, you must first determine which disk you are operating. Don’t accidentally divide the system disk, which will be troublesome.
-
Use
lsblk
orfdisk -l
to view the current disk list:lsblk
Find the disk device name you want to partition, such as
/dev/sdb
.
Next consider the partition table type:
- If the disk capacity is less than 2TB, MSDOS (MBR) is enough;
- If it is greater than 2TB, GPT must be used.
Execute the following command to enter parted operation mode and specify the disk (taking /dev/sdb
as an example):
sudo parted /dev/sdb
2. Create a partition table: Select the appropriate format
After entering parted, create a partition table:
(parted) mklabel gpt
or:
(parted) mklabel msdos
⚠️Note: This step will clear all data on the disk, be sure to confirm before operation!
3. Start partitioning: Set size and position
The next step is to divide the numerator. Suppose we want to create a 50GB main partition on /dev/sdb
:
- Enter the following command:
(parted) mkpart primary ext4 0GB 50GB
Explain the parameters:
-
primary
means this is the primary partition (can also belogical
) -
ext4
is the file system type (optionalxfs
,fat32
, etc.) -
0GB
and50GB
are the starting and ending positions
You can continue to add more partitions, such as adding another 100GB:
(parted) mkpart primary ext4 50GB 150GB
Check the current partition situation:
(parted) print
4. Format the partition and mount it to use
Although parted can create partitions, it is not formatted automatically. You need to format it manually:
- For example, format the first partition to ext4:
sudo mkfs.ext4 /dev/sdb1
Then create the mount point and mount:
sudo mkdir /mnt/data sudo mount /dev/sdb1 /mnt/data
If you want to automatically mount it on, remember to edit /etc/fstab
to add the corresponding entry.
Basically these steps. The whole process is not complicated, but the prone to errors lies in disk identification and partition alignment, especially when using GPT, you should pay attention to whether the units are consistent (such as GB/MB). Back up the data before operation and check the information after partitioning, and it will not be too easy to overturn.
The above is the detailed content of How to partition a disk using parted. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

ArtGPT
AI image generator for creative art from text prompts.

Stock Market GPT
AI powered investment research for smarter decisions

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

When encountering brokenendopes problems, you can follow the following steps to solve them: 1. Use sudoapt--fix-brokeninstall or try to install after cleaning; 2. Check and correct software source configuration errors; 3. Manually install, uninstall or reinstall conflict packages; 4. Clean the cache or reinstall related components. In most cases, these methods can be used to fix dependency problems without excessive worry.

Toremoveapackageusingyum,usethecommandsudoyumremovepackage_name,whichremovesthepackageandpotentiallyitsunuseddependencies.Beforedoingso,ensureyouhavethecorrectpackagenamewithyumlistorrpm-q,checkdependenciesviayumdeplist,andavoidremovingcriticalsystem

To view the system log, you need to select the corresponding tool according to the operating system. Windows uses event viewer, with the path to Win R, enter eventvwr.msc, to view the "System" classification under "Windows Log", and supports filtering and saving; Linux system logs are usually located in /var/log/ directory, such as syslog, messages, dmesg files, and can be viewed by tail-f or journalctl-u service name commands; Mac can view logs through the Console application or logshow command. When viewing, you should pay attention to error and warning level information, analyze problems based on timestamps and context, and pay attention to permission requirements.

To create and use a network namespace, you need to create it first, then assign the interface and IP, and set up the routing to achieve communication. The steps are as follows: 1. Create a namespace with ipnetnsadd; 2. Create a vethpair through iplinkadd and move one end into the namespace; 3. Assign IP to the interface and enable it; 4. If you need external network access, enable IP forwarding, configure iptablesMASQUERADE and set default routes; 5. Close the interface first and clean the rules when deleting. The entire process needs to pay attention to resource cleaning and rule consistency.

netstat is a practical tool for troubleshooting network problems and checking connection status. Common uses include: 1. Use netstat-a to view all active connections, filter TCP for -t, and UDP for -u; 2. Display program name and service name plus -n parameters to improve speed; 3. Use netstat-l to view the listening port, combined with -tulnp to display process information; 4. Find programs that occupy a specific port can be implemented through grep: port number and ps command; 5. If the system is not installed, try the ss command or install the net-tools package, and the root permissions are required to execute the -p parameter to obtain the complete information.

The key to using parted partition disks is to master several steps: 1. Preparation: Confirm the target disk device name (such as /dev/sdb) and judge its partition table type. If it is less than 2TB, use MSDOS (MBR) and if it is greater than 2TB, use GPT; 2. Create a partition table: After entering parted operation mode, execute the mklabel command to select gpt or msdos, this step will clear the disk data; 3. Start partition: Use the mkpart command to specify the partition type, file system and start and end location, such as mkpartprimaryext40GB50GB, and continue to add other partitions; 4. Format and mount the partition: manually execute mkfs.ext4 and other commands to format,

To ensure that the system time synchronization is reliable, first make sure that the NTP service is installed and run, use systemctl to check the state of ntp or chronyd, and start and set up the power-on self-start if necessary. Secondly, configure a suitable NTP server, modify the /etc/ntp.conf or /etc/chrony/chrony.conf file, and recommend choosing a server with a similar geographical location such as Alibaba Cloud or Tencent Cloud. Finally, check the synchronization status and use ntpq-p or chronycsources to view the connection status. If the offset is too large, you can use ntpdate to manually calibrate it, but long-term synchronization should rely on background services to ensure stability.

When a file is occupied, you can search and end the occupied process by the following methods: 1. The Windows system can use the task manager to search for file handles with the resource monitor; 2. Use the handle.exe tool of Sysinternals to query accurately, requiring administrator permission; 3. Linux/macOS uses the lsof command to search for keywords, and grep can search for keywords; 4. Before ending the process, you must confirm the purpose. Windows can use the task manager or taskkill command, and Linux/macOS can use the kill command to avoid killing the system process by mistake.
