BASH Disk Tools

From Indie IT Wiki
Jump to: navigation, search
  • fdisk
  • sfdisk
  • cfdisk
  • parted
  • df
  • pydf
  • lsblk
  • blkid
  • hwinfo

Thanks to Binary Tides.

Rename USB Drive

sudo mlabel -i /dev/sdb1 ::USB2GB

Thanks - and


Delete Partition

sudo parted /dev/sdX
(parted) print
(parted) rm

Partition Table Type


(parted) mklabel msdos


(parted) mklabel gpt

Create Partition

To partition a disk (example sdX) with a single partition and format as ext4...

sudo parted -a optimal /dev/sdX
(parted) mklabel
Warning: The existing disk label on /dev/sdX will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted) mkpart primary ext4 0% 100%
(parted) quit

Or to avoid the prompts...

sudo parted -s -a optimal /dev/sdX mklabel
sudo parted -s -a optimal /dev/sdX mkpart primary ext4 0% 100%

Or slightly differently...

sudo parted --script --align optimal /dev/sdX 'mklabel'
sudo parted --script --align optimal /dev/sdX 'mkpart primary ext4 1 -1'

Thanks -

Thanks -