• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Verify if a Disk/Partition is in Use by Oracle ASM, was used by Oracle ASM or is never used by Oracle ASM

by admin

The below small C program will help us to identify if a Disk/Partition is still used by ASM, has been used by ASM or has not been used by ASM on Unix or Linux platforms.

1. First of all, we need to compile the below C code:

#include <stdio.h>
#include <fcntl.h> 
#define BLOCK_SIZE 4096 
int main(int argc, char *argv[]) 
{ 
    char buf[BLOCK_SIZE]; 
    char *fname; 
    int  fd; 
    int  count; 

    if (argc != 2) 
    { 
      fprintf(stderr, "Exactly one argument required\n"); 
      return (-1); 
    } 

    fname = argv[1]; 
    fd = open(fname, O_RDONLY); 
    if (fd < 0) 
    { 
      perror(fname); 
      return (-1); 
    } 

    count = read(fd, buf, sizeof(buf)); 
    if (count < 0) 
    { 
      perror(fname); 
      return (-1); 
    } 
    if (count < sizeof(buf)) 
    {  
      return (1); 
    } 

    if ( buf[32] == 'O' && buf[33] == 'R' && buf[34] == 'C' && buf[35] == 'L' 
      && buf[36] == 'D' && buf[37] == 'I' && buf[38] == 'S' && buf[39] == 'K') 
    {  

      if (buf[71] != 4) { 
        printf("This disk %s still used by ASM\n",argv[1]); 
        return (0);                                      
      } 
      else 
      printf("This disk %s has been used by ASM\n",argv[1]); 

      return (0);         
     } 

    printf("This disk %s has not been used by ASM\n",argv[1]); 
    return (1); 
}

2. Save the above code as an ASCII file, then using a C Compiler compile it as follow:

$ ls  
-rw-r--r--  1 oracle oinstall 2014 Jun 16 15:57 checkasmdisk.c
$ cc checkasmdisk.c -o checkasmdisk
$ ls  
-rwxr-xr-x  1 oracle oinstall 5670 Jun 16 15:57 checkasmdisk 
-rw-r--r--  1 oracle oinstall 2014 Jun 16 15:57 checkasmdisk.c

3. Check the desired disk(s) with the compiled script. we can obtain 4 states as shown below as a result of the script:

1. Disk has not been used by ASM

Connected to: 
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production 
With the Partitioning, OLAP, Data Mining and Real Application Testing options 

SQL> !dd if=/dev/zero of=/dev/sda14 bs=8192 count=12800 
12800+0 records in 
12800+0 records out 

SQL> !checkasmdisk /dev/sda14 

This disk /dev/sda14 has not been used by ASM

2. Disk is still used by ASM

SQL> create diskgroup DATADG external redundancy disk '/dev/sda14'; 

Diskgroup created. 

SQL> !checkasmdisk /dev/sda14 

This disk /dev/sda14 still used by ASM 

3. Disk has been used by ASM

SQL> drop diskgroup DATADG; 

Diskgroup dropped. 

SQL> !checkasmdisk /dev/sda14 

This disk /dev/sda14 has been used by ASM

4. Disk cannot be accessed

# ls -l /dev/sda14 

brw-rw---- 1 oracle dba 8, 14 Jun 11 19:12 /dev/sda14 

# chown root:disk /dev/sda14 

# ls -l /dev/sda14 
brw-rw---- 1 root disk 8, 14 Jun 11 19:12 /dev/sda14 

SQL> !checkasmdisk /dev/sda14 

/dev/sda14: Permission denied 

brw-rw---- 1 root disk 8, 14 Jun 11 19:12 /dev/sda14 
Oracle ASM : Shell script to map physical disk devices to ASMLIB disks

Filed Under: ASM, Linux, oracle

Some more articles you might also be interested in …

  1. oracleasm Command Examples (Cheat Sheet)
  2. tar Command Examples in Linux
  3. CentOS / RHEL : How to delete LVM volume
  4. mpirun.openmpi: command not found
  5. How to Save Command history of Selected Users in Linux
  6. CentOS / RHEL 7 : Booting process
  7. RCRON – Setup High Availability of cron Jobs
  8. Oracle Database 12c New Feature: SYSRAC administrative privilege
  9. SQL query error when Using Shell Script
  10. CentOS / RHEL : How to backup/restore configuration using authconfig

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright