Visit Our UNIX and Linux User Community


Getting Storage Device Sizes and Paths


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Getting Storage Device Sizes and Paths
# 1  
Old 08-20-2009
Getting Storage Device Sizes and Paths

What I'm Doing:
I'm developing a python script that scans for all storage devices and their respective sizes. Python does not have a command that returns the /dev paths of storage devices or the respective sizes. So, I need to pipe a shell command to python.

The Problem:
In root, I've used fdisk to get all storage device paths and their respective sizes and send that to a file that python can open to retrieve the path and size info. Here is what fdisk sends to a file:

Code:
Disk /dev/sda: 320.0 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x8941fb29

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1       12748   102398278+  83  Linux
/dev/sda2           37811       38913     8859847+   5  Extended
/dev/sda3           12749       20397    61440592+  83  Linux
/dev/sda4           25497       37810    98912205   83  Linux
/dev/sda5           37811       38913     8859816   82  Linux swap / Solaris

Partition table entries are not in disk order

Disk /dev/sdb: 126 MB, 126779392 bytes
4 heads, 61 sectors/track, 1014 cylinders
Units = cylinders of 244 * 512 = 124928 bytes
Disk identifier: 0x5b1b8282


Disk /dev/sdc: 2004 MB, 2004877312 bytes
255 heads, 63 sectors/track, 243 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000a8c94

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         243     1951866   83  Linux

My Question
Is there a way to grep this info so that the paths and their respectives sizes are returned? Or, for anyone who understands what I'm trying to achieve here, could you offer some other solution besides an attempt to grep?
# 2  
Old 08-20-2009
Code:
# fdisk -l | grep Disk | awk '{print $2, $3 $4}' | cut -d ',' -f 1
/dev/sda: 449.9GB
/dev/sdb: 193.2GB
/dev/sdc: 193.2GB

# 3  
Old 08-20-2009
Thanks. I feel like this may be solved soon. It does work for devices, but not the partitions on the device.

I have several partitions on sda that it did not return the size.

Also, is there a way to print actual bytes, this seams to be human readable form.

I'm going to have to study these commands a bit. I'll probably get it soon one way or another.

Thanks for putting me on the right track.
# 4  
Old 08-20-2009
If you want to calculate bytes from the given blocks, maybe:

fdisk
Code:
# fdisk -l /dev/sda

Disk /dev/sda: 449.9 GB, 449932427264 bytes
255 heads, 63 sectors/track, 54701 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14       54701   439281360   8e  Linux LVM

Get blocks & partitions
Code:
# egrep -v "#blocks|^$" /proc/partitions|awk '{print $3, $4}'
439387136 sda
104391 sda1
439281360 sda2

# 5  
Old 08-20-2009
Perfect solution.

Thank you very much.
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #539
Difficulty: Medium
In C, int x; creates an integer variable associated with the identifier x initialized to one .
True or False?

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File representing the hard disk storage device

I want example of a file representing the hard disk storage device In UNIX ? (6 Replies)
Discussion started by: tamer11007
6 Replies

2. Shell Programming and Scripting

Detecting A USB Storage Device From A Script

I need a way to reliably detect a USB storage device from a bash script. I know how to use 'lsusb' to list the USB devices - but then how can I match a device listed in 'lsusb' output to an actual disk device? Is there some way to map one to the other? Any help appreciated. (3 Replies)
Discussion started by: dmaddox099
3 Replies

3. Shell Programming and Scripting

crontab; copy most recent *.mpg file from local machine to smb storage device

Hello, I've been searching your forum for an answer to the following question and whilst I've seen several which may help I'm afraid my inexperience with UNIX systems has got the better of me and I'm incapable of piecing your considerable expertise together. Problem: I have a linux box which... (5 Replies)
Discussion started by: julezsht
5 Replies

4. AIX

Storage paths

Have connected a non-IBM storage device to AIX host via fibre channel. If the storage is rebooted or a raid controller fails over whilst connected to the host, the paths that drop do not come back online when the ports become active again. I have tried enabling dynamic tracking and delayed_fail... (3 Replies)
Discussion started by: Storeman
3 Replies

5. UNIX for Dummies Questions & Answers

path_to_inst output for usb storage device

Hello, I have a sun blade 100 with solaris 10 and am perplexed by the instances of devices that I see when I attach a usb flash stick to one of the ports in the back of the chassis. Here is what I see for USB storage in /etc/path_to_inst: "/pci@1f,0/usb@c,3/storage@3" 0 "scsa2usb"... (0 Replies)
Discussion started by: montana77
0 Replies

6. Linux

Some problem about usb mass storage device

Dear linuxers, I have a usb mess storage device. My OS is rh as3 update2. Each time I use the command mount -t vfat /dev/sda1 /mnt/usb I got the error "the device is not a valid block device". I found from google that I should install the module sd_mod I use the command insmod sd_mod... (2 Replies)
Discussion started by: niukun
2 Replies

Featured Tech Videos