Single-Line Parted Command to Partition and Mount a 100% Linux Disk

Single-Line Parted Command to Partition and Mount a 100% Linux Disk

When provisioning additional storage volumes for GlusterFS and Kubernetes worker VMs, interactive fdisk prompts slow down automation. Using GNU parted in script mode (-s), you can initialize a partition table and allocate 100% of the disk in a single command:

bash
sudo parted -s /dev/sdb mklabel msdos mkpart primary 0% 100%

Note: Replace /dev/sdb with your target block device. Running parted -s executes non-interactively with zero confirmation prompts.

Formatting with ext4 and Persistent /etc/fstab Mounting

After using this single line to use 100% of the new volume in parted, we want to make a quick ext4 format:

bash
sudo mkfs.ext4 /dev/sdb1

After this is completed you are good to mount the partition of our new disk.

To make the mount resilient to device-name shifts across reboots, assign a filesystem label with e2label, create the mount point, and register `LABEL=glusterfs` in /etc/fstab:

bash
sudo e2label /dev/sdb1 glusterfs
sudo mkdir /glusterfs
sudo echo 'LABEL=glusterfs /glusterfs ext4 defaults 0 0' >> /etc/fstab

These four commands can be dropped directly into Ansible playbooks, Cloud-Init user-data, or shell scripts to provision new Linux disks unattended. View the complete script on GitLab: script_on_git

>_ Engineering Discussion 2 Comments

+ Add Field Note ↓
  1. Using parted -s -a optimal /dev/sdb mklabel gpt -- mkpart primary ext4 1MiB -1s in a single non-interactive command is a lifesaver for Ansible disk provisioning playbooks.

  2. That 1MiB starting sector alignment (1MiB -1s) is so important on modern 4Kn enterprise SSDs and hardware RAID LUNs—prevents the classic parted alignment warning every time.

Leave a Technical Comment

Share CLI tips, hardware notes, or questions below. Inline backticks (`command`) are supported.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Engineering Notes