In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "Linux how to use the parted command to partition the disk", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let the editor lead you to study and learn how to partition the disk using the parted command under Linux "this article.
The parted command is a powerful disk partition and partition resizing tool developed by the GNU organization. Unlike fdisk, it supports resizing partitions. As a tool designed for Linux, it is not built to handle multiple partition types associated with fdisk, but it can handle the most common partition formats, including: ext2, ext3, fat16, fat32, NTFS, ReiserFS, JFS, XFS, UFS, HFS, and Linux swap partitions.
GPT disk partitions:
First, you have to have a hard drive with a GPT partition. Disks less than 2 TB can also be converted to MBR disks, but disks larger than 2 TB need to use GPT partitions, otherwise the parts larger than 2 TB will be sealed by you.
After mounting the hard drive, open the system and log in as root. Bloggers here use CentOS 6.7 as an example, and other Linux distributions also support the parted command.
We can use the command ll / dev/ | grep sd to view the currently mounted hard disk, as follows:
[root@localhost] # ll / dev/ | grep sdlrwxrwxrwx 1 root root 4 Jan 21 03:55 root-> sda3brw-rw---- 1 root disk 8, 0 Jan 21 04:21 sdabrw-rw---- 1 root disk 8, 1 Jan 21 03:55 sda1brw-rw---- 1 root disk 8, 2 Jan 21 03:55 sda2brw-rw---- 1 root disk 8, 3 Jan 21 03:55 sda3brw-rw---- 1 root disk 8, 4 Jan 21 03:55 sda4brw-rw---- 1 root disk 8 5 Jan 21 03:55 sda5brw-rw---- 1 root disk 8, 6 Jan 21 03:55 sda6brw-rw---- 1 root disk 8, 7 Jan 21 03:55 sda7brw-rw---- 1 root disk 8, 8 Jan 21 03:55 sda8brw-rw---- 1 root disk 8, 9 Jan 21 03:55 sda9brw-rw---- 1 root disk 8, 16 Jan 21 03:55 sdb# Currently, two hard drives are mounted on the system, which are identified as sda and sdb respectively. Sda contains 9 partitions, and sdb does not have Linux before partition #. Disks of IDE type will be named hda and hdb.... SATA and SCSI type disks are named sda, sdb...#, but since the 2.6.19 kernel, Linux has uniformly named mounted disks sda, sdb.... After that, use the fdisk-l command to view the two hard drives, as shown below. [root@localhost] # fdisk-lDisk / dev/sda: 21.5GB, 21474836480 bytes255 heads, 63 sectors/track 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000f1e9dDevice Boot Start End Blocks Id System/dev/sda1 * 1 26 204800 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 26 942 7357440 83 LinuxPartition 2 does not end on cylinder boundary./dev/sda3 942 1725 6291456 83 Linux/dev/sda4 1725 2611 7116800 5 Extended/dev/sda5 1726 1987 209152 82 Linux swap / Solaris/dev/sda6 2248 2097152 83 Linux / dev/sda7 2248 2379 1048576 83 Linux/dev/sda8 2379 2509 1048576 83 Linux/dev/sda9 2509 2611 819200 83 LinuxWARNING: GPT (GUID Partition Table) detected on'/ devamp sdbstores! The util fdisk doesn't support GPT. Use GNU Parted.Disk / dev/sdb: 4398.0 GB, 4398046511104 bytes256 heads, 63 sectors/track, 532610 cylindersUnits = cylinders of 16128 * 512 = 8257536 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x3c613c22Device Boot Start End Blocks Id System/dev/sdb1 1266306 2147483647 + ee GPT# warns that fdisk does not support GPT disks, please use GNU Parted# to enter interactive mode using fdisk disk name Then enter the letter I to see the meaning of Id # 82 for Linux Swap 83 means Linux;ee means GPT.
After that, we chose Parted as the GPT disk partition.
Parted, like fdisk, has two modes:
Command line mode: parted [option] device [command]
Interaction mode: parted [option] device
The following are the specific zoning methods
(parted) followed by the input character [root@localhost ~] # parted / dev/sdbGNU Parted 2.1Using / dev/sdbWelcome to GNU Parted! Type 'help' to view a list of commands. (parted) p # p=print, view all partitions Model: VMware, VMware Virtual S (scsi) Disk / dev/sdb: 4398GBSector size (logical/physical): 512B/512BPartition Table: gpt # disk type, GPTNumber Start End Size File system Name Flags # empty here, means there is no partition (parted) mkpart # just enter mkpart to start interactive partition Partition name? []? PrimaryFile system type? [ext2]? Ext4Start? 0End? 1024GWarning: The resulting partition is not properly aligned for best performance.Ignore/Cancel? Ignore (parted) mkpart primary 1024G 3072G # create a new partition, mkpart PART-TYPE [FS-TYPE] START END, which means to create a new 2TB primary partition (parted) mkpart extended ext4 3072G 3500G # which starts at 1024g and ends at 3072G, and adds ext4 in the middle to indicate the file system. The partition type is extended partition, but merge with eggs. Anyway, he will not automatically format (parted) mkpart primary 3500G-1 #-1 means that the end position is at the end of the disk (parted) pModel: VMware, VMware Virtual S (scsi) Disk / dev/sdb: 4398GBSector size (logical/physical): 512B/512BPartition Table: gptNumber Start End Size File system Name Flags1 17.4kB 1024GB 1024GB primary2 1024GB 3072GB 2048GB primary3 3072GB 3500GB 428GB extended4 3500GB 4398GB 898GB primary# finds that the "file system" column is blank at this time, indicating that it has not been formatted After that, format (parted) quit # exit parted tool [root@localhost] # mkfs-t ext4 / dev/sdb1mke2fs 1.41.12 (17-May-2010) Filesystem label=OS type: LinuxBlock size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks62504960 inodes, 249999995 blocks12499999 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=42949672967630 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks:32768, 98304,163840,229376,294912,819200,884736, 1605632, 2654208 people 4096000, 7962624,11239424, 20480000, 23887872,71663616 7867568 mounts or180 days 102400000, 214990848Writing inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 38 mounts or180 days, whichever comes first. Use tune2fs-c or-I to override.# does not execute mkfs within the Parted tool before executing mkfs-t ext4 / dev/sdb2, mkfs-t ext4 / dev/sdb3, mkfs-t ext4 / dev/sdb4 according to the same statement because Parted cannot format the file system in ext4 format.
At this point, if you use the fdisk-l command, you cannot see the partition of the GPT disk, but you need to use parted-l.
[root@localhost] # parted-lModel: VMware, VMware Virtual S (scsi) Disk / dev/sdb: 4398GBSector size (logical/physical): 512B/512BPartition Table: gptNumber Start End Size File system Name Flags1 17.4kB 1024GB 1024GB ext4 primary2 1024GB 3072GB 2048GB ext4 primary3 3072GB 3500GB 428GB ext4 extended4 3500GB 4398GB 898GB ext4 primary
At this time, the disk has been successfully formatted, but no mount point has been specified for it. You need to see how to set the mount point. Please see the end of the article.
MBR disk partitions:
MBR disk partitioning method is exactly the same as GPT disk. MBR disks cannot be larger than 2 TB, otherwise only 2 TB will be forced.
The main steps are the same as GPT disk partitions, but there is one thing to note about MBR disk partitions:
(parted) pError: / dev/sdb: unrecognised disk label# if the above error occurs, it means that the MBR disk does not have a master boot record and needs to be converted to MBR. The command is: (parted) mklabel msdos#msdos is the MBR disk. At this time, (parted) p will not report that the disk is mounted incorrectly:
After formatting the hard disk, you need to set the mount point for each partition. There are two ways: one is to mount temporarily and the restart fails; the other is to mount automatically when you boot.
Please set the mount point for all partitions separately.
Before mounting mkdir / build#, set up the folder name that needs to be mounted. You can define your own # temporary mount, restart invalid mount / dev/sdb1 / build# mount, and modify it according to the actual situation. The following two ways: choose one of the two # first, please blkid | grep / dev/sdb1# to view the partition's UUIDecho 'UUID=XXXXXXXXXXXX / build ext4 defaults 12' > > / etc/fstab# to fill the partition's UUID in the XXXXX location # second Simple echo'/ dev/sdb1 / build ext4 defaults 1 2'> > / etc/fstabumount / dev/sdb1# this command is used to unmount # Note: sometimes you can't unmount because another user or process is accessing the file system. In a Linux system, the file system can be unmounted normally only after all accessed users or processes on the file system have completed the operation and exited. # use the command "lsof mount point" to see which processes are accessing the file system, and then use the kill command to kill the process to unmount
At this point, the mount has been set up. After restarting, you can check the mount status through the df command.
These are all the contents of this article entitled "how to partition a disk using the parted command under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.