Re: How to find disk is in use?




adar wrote:
I am looking for a system call or something similar to check whether
given disk (node /dev/sda, /dev/sdh etc) is in use. This will be
implemented in C language on Linux, so please suggest from C language
point.

For example,

#check-disk-in-use /dev/sda
Yes, in use
#check-disk-in-use /dev/sdh
Not in use

Please understand that user can provide only block device node, not a
partition.

Disk is use means:
A running application is born from this disk
A running application is reading/writing to this disk
Disk or disk partition is mounted and used
RAW read/write is happening on this disk
etc.
Basically if disk is used by any means from system/Linux this program
should be able to identifiy it. My system has 16 disks, and Linux OS
would be born from one of this disk and remaining 15 disk may be used
for data storage and for some application program.

The command 'fuser -m <device>' will do this. If you get no output at
all, then the block device is not in use. If you get output, it is a
list of process IDs of processes using that device along with a code
for how they are using it if appropriate.

If you need to write your own code to do it, obtain the source code to
'fuser' and borrow what you need.

DS

.



Relevant Pages

  • Re: mirroring
    ... *Migrating an Existing Linux to RAID1* ... this copies your data from the existing disk to the new disk then overwrites your existing disk* ... Change the partition type on the existing non-raid disk to type 'fd' ... Create the degraded RAID array on the empty disk, but leave out the existing system disk for now. ...
    (RedHat)
  • Re: mirroring
    ... *Migrating an Existing Linux to RAID1* ... Change the partition type on the existing non-raid disk to type 'fd' ... Changed system type of partition 1 to fd (Linux raid autodetect) ...
    (RedHat)
  • Re: Panasonic HD Recorders - What disk format?
    ... The earlier part of this is more about what may be Linux partitioning, ... might be possible to present the recorder with a larger disk already ... Most DOS/Windows utilities such as FDisk, Ghost, and Partition Magic Pro ... prompts to format it. ...
    (alt.os.linux)
  • Re: defrag in linux?
    ... heads of your HD advance sequentially through the hard disk. ... fragmentation is a concern when one ... On the other hand, if you are Linux, you reorder the ... 'file fragmented' Linux file system and a 'file unfragmented' Linux ...
    (alt.os.linux.suse)
  • [ANNOUNCE]: RIP Linux rescue system!
    ... This is a bootable CD Linux boot/rescue system! ... The bootable CD image `RIP-12.7.iso.bin' can be written to a CD disk, ... It also includes the CD/DVD UDF filesystem packet writing tools (cdrwtool, ... a Linux reiserfs and reiser4 filesystem. ...
    (comp.os.linux.announce)