top of page
Search

Tips on how to use parted to partition a disk in Linux.txt

  • gormsenbladt70hoiw
  • Jun 12, 2020
  • 3 min read

Compiled from: https://opensource.com/article/18/6/how-partition-disk-linux

Author: DanielOh

Translator: amwps290

Learn the best way to use the parted command to partition storage devices in Linux.

Creating and deleting partitions in Linux is a popular operation since storage devices (for example tough drives and USB drives) should be structured in some way before they are able to be employed. In most circumstances, substantial storage devices are divided into separate components called partitions. Partitioning enables you to divide the really hard disk into separate components, each aspect is like a tough drive. When you are running various operating systems, partitioning is quite beneficial.

There are several effective tools in Linux which will build, delete, and manipulate disk partitions. Within this report, I will clarify the way to use the parted command, which is in particular valuable for big disk devices and several disk partitions. The differences in between parted plus the additional common fdisk and cfdisk commands involve:

GPT format: The parted command can generate a globally exclusive identifier partition table GPT, when fdisk and cfdisk are restricted to DOS partition tables. Larger disk: The DOS partition table can format as much as 2TB of disk space, though in some instances it may be as much as 16TB. However, a GPT partition table can handle as much as 8ZiB of space. Far more partitions: Working with main and extended partitions, the DOS partition table only enables 16 partitions. In GPT, you can get 128 partitions by default, and you can pick additional partitions. Reliability: Within the DOS partition table, only one copy of your partition table backup is saved, and two copies of the partition table backup are kept in GPT (at the starting and end on the disk), and GPT also utilizes a CRC checksum to Check the integrity from the partition table, which can be not implemented inside the DOS partition. Since the present disks are larger and need to have to be utilized much more flexibly, it really is encouraged to make use of parted to deal with disk partitions. Most of the time, the disk partition table is developed as component with the operating method installation approach. When adding storage devices to an current method, it's incredibly helpful to work with the parted command directly.

Try parted. The following explains the procedure of partitioning a storage device working with the parted command. As a way to try these methods, I strongly propose utilizing a brand new storage device or even a device that you do not thoughts deleting its contents.

1. List the partitions and use parted-l to identify the device you need to partition. Generally, the initial hard disk (/dev/sda or /dev/vda) holds the operating system, so appear for one more disk to locate the disk you want to partition (by way of example, /dev/sdb, /dev/ sdc, /dev/vdb, /dev/vdc, and so on.).

$sudoparted-l

[sudo]passwordfordaniel:

Model:ATARevuAhn_850X1TU5(scsi)

Disk/dev/vdc: 512GB

Sectorsize(logical/physical): 512B/512B

PartitionTable:msdos

DiskFlags:

NumberStartEndSizeTypeFilesystemFlags

11049kB525MB524MBprimaryext4boot

2525MB512GB512GBprimarylvm

2. Open the storage device and use parted to choose the device you need to partition. Within this instance, it is actually the third disk (/dev/vdc) around the virtual method. It is actually critical to indicate which device you need to use. If you only enter the parted command without the need of specifying the device name, it's going to randomly select a device to operate.

$sudoparted/dev/vdc

Using/dev/vdc

WelcometoGNUParted!Type'help'toviewalistofcommands.

(parted)

three. Set the partition table Set the partition table to GPT, after which enter Yes to begin the execution.

(parted)mklabelgpt

Warning:theexistingdisklabelon/dev/vdcwillbedestroyed

andalldataonthisdiskwillbelost.Doyouwanttocontinue?

Yes/No?Yes

The mklabel and mktable commands are made use of for exactly the same objective (creating a partition table around the storage device). The supported partition tables are: aix, amiga, bsd, dvh, gpt, mac, ms-dos, pc98, sun, and loop. Try to remember mklabel won't build a partition, but make a partition table.

four. Check the partition table to view storage device info:

(parted)print

Model:VirtioBlockDevice(virtblk)

Disk/dev/vdc: 1396MB

Sectorsize(logical/physical): 512B/512B

PartitionTable:gpt

DiskFlags:

NumberStartEndSizeFilesystemNameFlags

5. Get aid To know the way to make a new partition, enter: (parted)helpmkpart.

(parted)helpmkpart

mkpartPART-TYPE[FS-TYPE]STARTENDmakeapartition

PART-TYPEisoneof:principal,logical,extended

FS-TYPEisoneof:btrfs,nilfs2,ext4,ext3,ext2,fat32,fat16,hfsx,hfs+,hfs,jfs,swsusp,

linux-swap(v1), linux-swap(v0), ntfs, reiserfs, hp-ufs, sun-ufs, xfs, apfs2, apfs1, asfs, amufs5,

amufs4,amufs3,amufs2,amufs1,amufs0,amufs,affs7,affs6,affs5,affs4,affs3,affs2,affs1,

affs0, linux-swap, linux-swap(new), linux-swap(old)

STARTandENDaredisklocations,suchas4GBor10%.Negativevaluescountfromtheendofthe

disk.Forexample,-1sspecifiesexactlythelastsector.

'mkpart' makesapartitionwithoutcreatinganewfilesystemonthepartition.FS-TYPEmaybe

specifiedtosetanappropriatepartitionID.

6. Build a partition To create a new partition (in this example, partition 0 has 1396MB), enter the following command:

(parted)mkpartprimary01396MB

Warning: Theresultingpartitionisnotproperlyalignedforbestperformance

Ignore/Cancel? data recovery software

(parted)print

Model:VirtioBlockDevice(virtblk)

Disk/dev/vdc: 1396MB

Sectorsize(logical/physical): 512B/512B

PartitionTable:gpt

DiskFlags:

NumberStartEndSizeFilesystemNameFlags

117.4kB1396MB1396MBprimary

The file technique kind (fstype) does not generate an ext4 file method on /dev/vdc1. The partition types from the DOS partition table are main partition (primary), logical partition (logical) and extended partition (extended). Within the GPT partition table, the partition variety is employed as the partition name. go more have to be supplied beneath GPT; inside the above example, main may be the partition name, not the partition variety.

7. Save and exit Once you exit parted, the modification are going to be automatically saved. To exit, enter the following command:

(parted)quit

Information: Youmayneedtoupdate/etc/fstab.

$

Don't forget when you add a new storage device, make certain to ascertain the right disk ahead of beginning to transform its partition table. For those who incorrectly modify the disk partition containing the computer's operating system, your program is not going to start.

through:https://opensource.com/article/18/6/how-partition-disk-linux

 
 
 

Recent Posts

See All

Comments


Join my mailing list

Thanks for submitting!

© 2023 by The Book Lover. Proudly created with Wix.com

bottom of page