I have Ubuntu server 12.04 installed with no GUI. I would like to list my hard drive and it's partitions along with how big each partition is using the command line.
I have Ubuntu server 12.04 installed with no GUI. I would like to list my hard drive and it's partitions along with how big each partition is using the command line.
Here are a few ways:
If you have an MBR partition table:
or sudo sfdidk -l
These do not give particularly human readable output though. The next choices are better.
For both GPT and MBR partition tables:
lsblk
Install
inxi
then runHere's couple of other approaches:
lshw
The short version of
lshw
conveniently lists the size of disks in the descriptionAnd for more detailed info use
lshw -class volume,disk
udiscsctl
udiscsctl
hasinfo
option which coupled with-b
(for block-device) flag, can show detailed information. Using a simple for loop andawk
, we can make it show partition and size information specifically. Here is my example:df command
df
command shows information about all currently mounted filesystems. Again, we can use this command directly, but also clean up the output usingawk
Here we just print the header and use -h flag that makes size be printed in human-readable format
/sys/class/block/sd* files
Inside
/sys/class/block/
folder you will find files related to block devices( which typically refer to physical memory devices ) . In particular we want to focus on any file that starts withsd
letters.For instance, I have one hard drive with only one partition. Thus
/sys/class/block/sda
refers to my whole hard-drive, while/sys/class/block/sda1
refers to my Ubuntu partition.Inside each folder for each device, you will find the
size
file , which lists how many blocks of 512 MB there are on the device. So the true size isnumber of blocks x 521
.Again, with little command line magic, we get:
Or a bit shorter with
awk
:In terminal :
Type your password.
lsblk
command :I got to this by searching "ubuntu server list gpt partitions". I was searching for an answer when using 16.04.1 LTS. For those of you who want to list partitions (MBR or GPT), fdisk seems to have support for both (and not just MBR as in earlier Ubuntu versions) in 16.04.1 LTS. Also
parted
isn't installed by default when the "basic system utilities" option is selected during install. So the following command is all you need on 16.04.1 LTS: