Tuesday, October 25, 2011

Getting partition's size

Getting the size of a partition in Linux is very simple if you're logged in as root:

olimpo:~# fdisk -l /dev/sda

Disk /dev/sda: 160.0 GB, 160000000000 bytes
255 heads, 63 sectors/track, 19452 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xabd592d5

Device Boot Start End Blocks Id System
/dev/sda1 * 1 1567 12586896 7 HPFS/NTFS
/dev/sda2 1568 2546 7863817+ 17 Hidden HPFS/NTFS
/dev/sda3 2547 2796 2008125 82 Linux swap / Solaris
/dev/sda4 2797 19452 133789320 83 Linux

But it might be that you're just a DBA with access only to some partitions instead of the whole disk, and you got this server with no idea about partition sizes. If this is the case, then you can still know the size of your partitions with fdisk:

oracle@olimpo:/myASM$ /sbin/fdisk -l /dev/sda
Cannot open /dev/sda
oracle@olimpo:/myASM$ ls -la
total 8
drwxr-xr-x 2 oracle dba 4096 Oct 25 12:15 .
drwxr-xr-x 113 root root 4096 Oct 25 12:15 ..
brw-rw---- 1 oracle dba 8, 4 Oct 3 08:44 sda4
oracle@olimpo:/myASM$ /sbin/fdisk -s sda4
133789320

In Solaris is a bit different as the -s flag is not the same as in Linux:

oracle@myserver:/myASM$ ls -la
total 4
drwxr-xr-x 2 oracle dba 512 Oct 22 2008 .
drwxr-xr-x 38 root root 1024 Oct 18 16:57 ..
crw-r--r-- 1 oracle dba 32, 24 Oct 22 2008 disk1
crw-r--r-- 1 oracle dba 32, 25 Oct 25 09:31 disk2
crw-r--r-- 1 oracle dba 32, 26 Oct 22 2008 disk3

oracle@myserver:/myASM$ /sbin/fdisk -Rg disk2
* Label geometry for device disk2
* PCYL NCYL ACYL BCYL NHEAD NSECT SECSIZ
35135 35135 2 0 64 255 512

oracle@myserver:/myASM$ echo "(35135*64*255*512)/1024/1024"|bc
279982

With the last command you calculate the partition size in megabytes.

No comments:

Post a Comment