Softpanorama

May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

parted

Parted is required utility for disks with GPT partitions. That included large USB disks.

TIP: While creating partition you can specify size in %. For example, if you do not have any partitions in your drive partition table (empty partition table) you can use the following command to create primary partition.

parted --align optimal /dev/sdb mkpart 0% 100%

Apparently, using % causes parted to automatically align the sectors for best performance:

(parted) mkpart primary ext4 0% 100%

  1. How to align partitions for best performance using parted – Rainbow Chard
    • jsaintro

      The optimal feature only works when you’re using inexact units. By default parted uses Megabytes which is an inexact unit but that only allows +/- 500 KB of adjustment. On my system proper alignment requires over 1MB of adjustment. So using the default of ‘Compact’ or ‘MB’ will always throw an aliment warning. Specifying a larger unit also specifies a larger adjustment range I.E. ‘GB’ allows +/- 500 MB of adjustment. The percentage unit, by it’s nature, will always have enough range to allow proper adjustment

      If you use ‘”mkpart primary 0% 20GB” that should work.

GUID Partition Table (GPT) is a standard for the layout of the partition table on a physical storage device used in a desktop or server PC, such as a hard disk drive or solid-state drive, using globally unique identifiers (GUID). Although it forms a part of the Unified Extensible Firmware Interface (UEFI) standard (Unified EFI Forum proposed replacement for the PC BIOS), it is also used on some BIOS systems because of the limitations of master boot record (MBR) partition tables, which use 32 bits for storing logical block addresses (LBA) and size information on a traditionally 512-byte disk sector.

All modern PC operating systems support GPT. Some, including macOS and Microsoft Windows on x86, support booting from GPT partitions only on systems with EFI firmware, but FreeBSD and most Linux distributions can boot from GPT partitions on systems with both legacy BIOS firmware interface and EFI.

The widespread MBR partitioning scheme, dating from the early 1980s, imposed limitations that affect the use of modern hardware. One of the main limitations is the usage of 32 bits for storing block addresses and quantity information. For hard disks with 512-byte sectors, the MBR partition table entries allow up to a maximum of 2 TiB (232 × 512 bytes).

Intel therefore developed a new partition table format in the late 1990s as part of what eventually became UEFI. As of 2010[update], GPT forms a subset of the UEFI specification.[2] GPT allocates 64 bits for logical block addresses, therefore allowing a maximum disk size of 264 sectors. For disks with 512-byte sectors, maximum size is 9.4 ZB (9.4 × 1021 bytes) or 8 ZiB (9,444,732,965,739,290,427,392 bytes, coming from 18,446,744,073,709,551,616 (264) sectors × 512 (29) bytes per sector).[1][3]

Alignment issue

Please not that parted provides an `–align` argument to do this automatically.

How to align partitions for best performance using parted – Rainbow Chard

  1. parted provides an `–align` argument to do this automatically.

    http://unix.stackexchange.com/questions/38164/create-partition-aligned-using-parted

 

How to

8 Linux 'Parted' Commands to Create, Resize and Rescue Disk Partitions

Resize Linux Disk Partition

Parted includes multiple useful functions and one of them is "resizepart". Looks like it works for ext4 filesystems (man page is junk and incorrect)

The command  is resizepart. As all commands in parted if parameters are not supplied they are retrieved via dialog.

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.

The command is rescue


Top Visited
Switchboard
Latest
Past week
Past month

NEWS CONTENTS

Old News ;-)

[May 06, 2020] Creating and managing partitions in Linux with parted Enable Sysadmin by Tyler Carrigan

Apr 30, 2020 | www.redhat.com

Red Hat Sysddmin

Listing partitions with parted

The first thing that you want to do anytime that you need to make changes to your disk is to find out what partitions you already have. Displaying existing partitions allows you to make informed decisions moving forward and helps you nail down the partition names will need for future commands. Run the parted command to start parted in interactive mode and list partitions. It will default to your first listed drive. You will then use the print command to display disk information.

[root@rhel ~]# parted /dev/sdc
    GNU Parted 3.2
    Using /dev/sdc
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) print                                                            
    Error: /dev/sdc: unrecognised disk label
    Model: ATA VBOX HARDDISK (scsi)                                           
    Disk /dev/sdc: 1074MB
    Sector size (logical/physical): 512B/512B
    Partition Table: unknown
    Disk Flags:
    (parted)

Creating new partitions with parted

Now that you can see what partitions are active on the system, you are going to add a new partition to /dev/sdc . You can see in the output above that there is no partition table for this partition, so add one by using the mklabel command. Then use mkpart to add the new partition. You are creating a new primary partition using the ext4 architecture. For demonstration purposes, I chose to create a 50 MB partition.

(parted) mklabel msdos                                                    
    (parted) mkpart                                                           
    Partition type?  primary/extended? primary                                
    File system type?  [ext2]? ext4                                           
    Start? 1                                                                  
    End? 50                                                                   
    (parted)                                                                  
    (parted) print                                                            
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sdc: 1074MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:
    
    Number  Start   End     Size    Type     File system  Flags
     1      1049kB  50.3MB  49.3MB  primary  ext4         lba

Modifying existing partitions with parted

Now that you have created the new partition at 50 MB, you can resize it to 100 MB, and then shrink it back to the original 50 MB. First, note the partition number. You can find this information by using the print command. You are then going to use the resizepart command to make the modifications.

(parted) resizepart                                                       
    Partition number? 1                                                       
    End?  [50.3MB]? 100                                                       
        
    (parted) print                                                            
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sdc: 1074MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:
    
    Number  Start   End    Size    Type     File system  Flags
     1      1049kB  100MB  99.0MB  primary

You can see in the above output that I resized partition number one from 50 MB to 100 MB. You can then verify the changes with the print command. You can now resize it back down to 50 MB. Keep in mind that shrinking a partition can cause data loss.

    (parted) resizepart                                                       
    Partition number? 1                                                       
    End?  [100MB]? 50                                                         
    Warning: Shrinking a partition can cause data loss, are you sure you want to
    continue?
    Yes/No? yes                                                               
    
    (parted) print
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sdc: 1074MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:
    
    Number  Start   End     Size    Type     File system  Flags
     1      1049kB  50.0MB  49.0MB  primary

Removing partitions with parted

Now, let's look at how to remove the partition you created at /dev/sdc1 by using the rm command inside of the parted suite. Again, you will need the partition number, which is found in the print output.

NOTE: Be sure that you have all of the information correct here, there are no safeguards or are you sure? questions asked. When you run the rm command, it will delete the partition number you give it.

    (parted) rm 1                                                             
    (parted) print                                                            
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sdc: 1074MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:
    
    Number  Start  End  Size  Type  File system  Flags

How to align partitions for best performance using parted

Rainbow Chard
Jonathon Anderson

parted provides an `–align` argument to do this automatically.

http://unix.stackexchange.com/questions/38164/create-partition-aligned-using-parted

2nd May 2016

Volta X

I've got a new 8TB drive, and have run into a situation where the optimal alignment calculated by parted doesn't satisfy the minimal alignment tests, so various other tools that only check minimal alignment throw errors. Maybe I'm overthinking it, but it seems that if it doesn't meet the minimal alignment it can't really be the optimal alignment.

- 8< -
$ cat /sys/block/sdi/queue/optimal_io_size
33553920
$ cat /sys/block/sdi/queue/minimum_io_size
4096
$ cat /sys/block/sdi/queue/physical_block_size
4096
$ cat /sys/block/sdi/queue/logical_block_size
512
$ cat /sys/block/sdi/alignment_offset
0
- 8< -

Parted calculates optimal alignment to 65535s, apparently aligning on logical blocks rather than physical blocks:

- 8< -
$ sudo parted /dev/sdi mkpart 8tb ext4 0% 100% unit s p free align-check min 1 align-check opt 1
Model: Seagate Expansion Desk (scsi)
Disk /dev/sdi: 15628053167s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
34s 65534s 65501s Free Space
1 65535s 15628000379s 15627934845s ext4 8tb
15628000380s 15628053133s 52754s Free Space

1 not aligned
1 aligned
- 8< -

Asking for minimal alignment, parted starts that partition on sector 40, which obviously doesn't pass align-check opt. Fdisk uses sector 2048, which passes parted's min check, but not opt. Frustrated at this point, I scale the 65535 parted calculated with 512b sectors to 4k sectors and make a partition starting at 524280s, which satisfies both of parted's alignment checks, and stops all the other tools complaining, at a cost of a few hundred MiB storage:

- 8< -
$ sudo parted /dev/sdi mkpart 8tb ext4 524280s 100% unit MiB p free align-check min 1 align-check opt 1
Model: Seagate Expansion Desk (scsi)
Disk /dev/sdi: 7630885MiB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
0.02MiB 256MiB 256MiB Free Space
1 256MiB 7630860MiB 7630604MiB ext4 8tb
7630860MiB 7630885MiB 25.8MiB Free Space

1 aligned
1 aligned
- 8< -

Now, certainly losing ~300MiB out of ~7.3TiB isn't an issue, but I wonder:

a) was this exercise of any value,
b) if so, is there a better way to solve for a starting sector that will satisfy both constraints, and
c) if so, how hard is it going to be for me to patch parted to do the right thing here?

Thoughts?

How To Create a Partition Using parted Command

Creating Primary or Logical Partition in Selected Disk Using mkpart

One can create either Primary or Logical partitions using mkpart command. Options can be primary and logical respectively. Example for both options are shown as below (we will create 2 partitions of 200MB each as primary and logical partition) :
a. Creating primary partition

(parted) mkpart primary                                                   
File system type?  [ext2]? ext4                                           
Start? 0                                                                  
End? 200MB
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End    Size   Type     File system  Flags
 1      512B   200MB  200MB  primary

b. Creating logical partition

(parted) mkpart logical                                                   
parted: invalid token: logical
Partition type?  primary/extended? extended                               
Start? 201M                                                               
End? 402M
(parted) print                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End    Size   Type      File system  Flags
 1      512B   200MB  200MB  primary
 2      201MB  402MB  200MB  extended               lba
NOTE: Parted asks for the FS-Type while creating primary partition unless a logical partition is to be created.

Remove a Partition Using rm Command

One can also delete an existing partition using "rm" command, as shown in below example we have 2 partitions with number 1 and 2.

(parted) print                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End    Size   Type      File system  Flags
 1      512B   200MB  200MB  primary
 2      201MB  402MB  200MB  extended               lba

To delete partition 2:

(parted) rm                                                               
Partition number? 2

Verify that you can see only the partition number 1 now.

(parted) print                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End    Size   Type     File system  Flags
 1      512B   200MB  200MB  primary

Recommended Links

Google matched content

Softpanorama Recommended

Top articles

Sites

parted(8) partition change program - Linux man page

More information about parted available from redhat: http://people.redhat.com/msnitzer/docs/io-limits.txt

Reference

parted is a disk partitioning and partition resizing program. It allows you to create, destroy, resize, move and copy ext2, linux-swap, FAT, FAT32, and reiserfs partitions. It can create, resize, and move Macintosh HFS partitions, as well as detect jfs, ntfs, ufs, and xfs partitions. It is useful for creating space for new operating systems, reorganising disk usage, and copying data to new hard disks.

This manual page documents parted briefly. Complete documentation is distributed with the package in GNU Info format; see near the bottom.

Options

-h, --help
displays a help message
-l, --list
lists partition layout on all block devices
-m, --machine
displays machine parseable output
-s, --script
never prompts for user intervention
-v, --version
displays the version
-a alignment-type, --align alignment-type
Set alignment for newly created partitions, valid alignment types are:
none
Use the minimum alignment allowed by the disk type.
cylinder
Align partitions to cylinders.
minimal
Use minimum alignment as given by the disk topology information. This and the opt value will use layout information provided by the disk to align the logical partition table addresses to actual physical blocks on the disks. The min value is the minimum aligment needed to align the partition properly to physical blocks, which avoids performance degradation.
optimal
Use optimum alignment as given by the disk topology information. This aligns to a multiple of the physical block size in a way that guarantees optimal performance.

Commands

[device]
The block device to be used. When none is given, parted will use the first block device it finds.
[command [options]]
Specifies the command to be executed. If no command is given, parted will present a command prompt. Possible commands are:
align-check alignment-type partition
Determine whether the starting sector of partition is aligned for the disk. alignment-type is "minimal" or "optimal".
check partition
Do a simple check on partition.
cp [source-device] source dest
Copy the source partition's filesystem on source-device (or the current device if no other device was specified) to the dest partition on the current device.
help [command]
Print general help, or help on command if specified.
mkfs partition fs-type
Make a filesystem fs-type on partition. fs-type can be one of "fat16", "fat32", "ext2", "linux-swap", or "reiserfs".
mklabel label-type
Create a new disklabel (partition table) of label-type. label-type should be one of "bsd", "dvh", "gpt", "loop", "mac", "msdos", "pc98", or "sun".
mkpart part-type [fs-type] start end
Make a part-type partition with filesystem fs-type (if specified), beginning at start and ending at end (by default in megabytes). fs-type can be one of "fat16", "fat32", "ext2", "HFS", "linux-swap", "NTFS", "reiserfs", or "ufs". part-type should be one of "primary", "logical", or "extended".
mkpartfs part-type fs-type start end
Make a part-type partition with filesystem fs-type beginning at start and ending at end (by default in megabytes). Using this command is discouraged. Instead use mkpart to create an empty partition, and then use external tools like mke2fs(8) to create the filesystem.
move partition start end
Move partition so that it begins at start and ends at end. Note: move never changes the minor number.
name partition name
Set the name of partition to name. This option works only on Mac, PC98, and GPT disklabels. The name can be placed in quotes, if necessary.
print
Display the partition table.
quit
Exit from parted.
rescue start end
Rescue a lost partition that was located somewhere between start and end. If a partition is found, parted will ask if you want to create an entry for it in the partition table.
resize partition start end
Resize the filesystem on partition so that it begins at start and ends at end (by default in megabytes).
rm partition
Delete partition.
select device
Choose device as the current device to edit. device should usually be a Linux hard disk device, but it can be a partition, software raid device, or an LVM logical volume if necessary.
set partition flag state
Change the state of the flag on partition to state. Supported flags are: "boot", "root", "swap", "hidden", "raid", "lvm", "lba", "legacy_boot" and "palo". state should be either "on" or "off".
unit unit
Set unit as the unit to use when displaying locations and sizes, and for interpreting those given by the user when not suffixed with an explicit unit. unit can be one of "s" (sectors), "B" (bytes), "kB", "MB", "GB", "TB", "%" (percentage of device size), "cyl" (cylinders), "chs" (cylinders, heads, sectors), or "compact" (megabytes for input, and a human-friendly form for output).
version
Display version information and a copyright message.

Known Issues

ext3 filesystem functionality does not currently work. To manage ext3 type filesystems use tools like resize2fs(8) or mke2fs(8). Note that the currently supported ext2 filesystem will be deprecated once ext3 support is finalized. Further note that ext3 support will have limited functionality that is yet to be defined. Use tools like resize2fs(8) and mke2fs(8) to manage these types of filesystems.

To manually resize an ext3 filesystem and/or a partition use resize2fs(8), fdisk(8) or similar tools. For LVM situations, you will need to use the LVM commands to resize the LVM elements.

See Also

fdisk(8), mkfs(8), The parted program is fully documented in the info(1) format GNU partitioning software manual.

Author

This manual page was written by Timshel Knoll <[email protected]>, for the Debian GNU/Linux system (but may be used by others).

Etc

Society

Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

Quotes

War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

Bulletin:

Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

History:

Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D


Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to to buy a cup of coffee for authors of this site

Disclaimer:

The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Last modified: May, 05, 2020