BASH Disk Tools

From Indie IT Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
  • fdisk
  • sfdisk
  • cfdisk
  • parted
  • df
  • pydf
  • lsblk
  • blkid
  • hwinfo

Thanks to Binary Tides.

Rename USB Drive

sudo mlabel -i /dev/sdb1 ::USB2GB

Thanks - https://help.ubuntu.com/community/RenameUSBDrive and https://askubuntu.com/questions/194510/how-to-edit-label-of-usb-drive

Parted

http://www.thegeekstuff.com/2011/09/parted-command-examples/

Delete Partition

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

Partition Table Type

msdos

(parted) mklabel msdos

gpt

(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 - https://blog.yo61.com/creating-an-optimally-aligned-full-disk-partition-with-parted/

Thanks - http://stackoverflow.com/questions/12917678/fill-a-disk-with-an-ext4-partition-in-a-script