Andrew Mercer
on this page

Reference: ArchWiki: parted.

Partitioning commands act on the disk immediately. Verify the device (lsblk) first and unmount anything on it.

Inspect

sudo parted /dev/sdb print
sudo parted /dev/sdb unit s print          # sector units
sudo parted -l                              # all disks

Example output:

Model: Kingston DataTraveler 3.0 (scsi)
Disk /dev/sdb: 7751MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number  Start   End     Size    Type     File system  Flags
 1      4129kB  7751MB  7747MB  primary  fat32        boot, lba

MBR (msdos) partitions

sudo parted /dev/vdb mklabel msdos
sudo udevadm settle
sudo parted /dev/vdb mkpart primary xfs 2048s 1000MB        # first partition, starts at sector 2048
sudo parted /dev/vdb mkpart primary xfs 1000MB 2000MB       # second, from 1000 MB to 2000 MB

GPT partitions

sudo parted /dev/vdc mklabel gpt
sudo udevadm settle
sudo parted /dev/vdc mkpart userdata xfs 2048s 1000MB       # on GPT the second argument is a partition name

Then create a filesystem on the new partition, for example sudo mkfs.xfs /dev/vdc1.

Two partitions, second takes the remaining space

Example: a small partition for an ISO image and the rest for persistent storage:

sudo parted /dev/sdb
(parted) mkpart primary 1MiB 3276MiB
(parted) mkpart primary 3277MiB 100%
(parted) print
(parted) quit

Use MiB/GiB units for alignment-friendly sizes, and 100% for "to the end".

Delete partitions

sudo parted /dev/vdb rm 1
sudo parted /dev/vdb rm 2

# interactive
sudo parted /dev/sdb
(parted) print
(parted) rm 1

Remove the partition table / filesystem signatures

sudo wipefs --all /dev/vdb

See wipefs. After changes, make the kernel re-read the table with partprobe (or blockdev --rereadpt, see blockdev).