Operating System - HP-UX
1832973 Members
2379 Online
110048 Solutions
New Discussion

Re: Finding out the VGID for a volumegroup (CLI of C program)

 
vikrantl
Advisor

Finding out the VGID for a volumegroup (CLI of C program)

I want a simple CLI (that would be present on all hpux systems) that will give me the VGID for the given volumegroup.
If not CLI, will any small C code work?

Jeff Schussele provided a good solution (below)in another thread, but probably since adb wont be available, I can't use it on all the systems.
Hi,

I think what you're looking for is the VGID for that volume group.
If so here's a method

----------------------------------------

echo 0x2010?2X|adb /dev/dsk/cXtYdZ|expand|tr -d " "

This should yield a result like

2010: 778B50B1 3D5D3888

If you drop the 2010: & combine the next two fields - there's your VGID

778B50B13D5D3888

HTH,
Jeff
vikrantl
4 REPLIES 4
Sundar_7
Honored Contributor

Re: Finding out the VGID for a volumegroup (CLI of C program)

You should have adb in all HP-UX systems. There is also couple of more ways to find out the VGID

1) echo "0x2008?4D" | adb /dev/dsk/CXtYdZ" | awk '{print $NF}'

Last field is the VGID

2)you can also use vgexport

# vgexport -p -s -m /tmp/vg02.map /dev/vg02.map 1>/dev/null 2>&1

# head -1 /tmp/vg02.map | awk '{print $2}'

It will give you 16 hex digits. The first 8 digits are the CPU ID of the system the vg was initally created. the next 8 digits are your VGID for the VG.

Sundar
Learn What to do ,How to do and more importantly When to do ?
Colin Topliss
Esteemed Contributor

Re: Finding out the VGID for a volumegroup (CLI of C program)

Here's a bit of C Code that will do the trick.

It definitely works under HP-UX 11i.

Col

//------------------------------------------------------------//
// Description: //
// //
// Quick bit of C code to extract the LVMREC from an LVM disk //
// //
//------------------------------------------------------------//

#include
#include
#include

main(int argc, char* argv[])
{
//-----------------------------------------------------------------------//
// Define the structure (as it doesn't appear in a header file anywhere) //
//-----------------------------------------------------------------------//

struct pvraHdr
{
char magic[8];
long long pvid;
long long vgid;
} *pvp;

//----------------------//
// Set up the variables //
//----------------------//

char buf[1024];
char magic[9];
int fd;

//-------------------------//
// Try and open the device //
//-------------------------//

if (( fd = open(argv[1],O_RDONLY)) == -1 )
{
perror("Open failed");
exit(1);
}

//----------------------------------------//
// Set the file pointer to an 8192 offset //
// and read data into buffer. //
//----------------------------------------//

lseek(fd,8192,SEEK_SET);
read(fd,buf,sizeof(buf));

//-------------------------------//
// Map the data to the structure //
//-------------------------------//

pvp=(struct pvraHdr*)buf;
strncpy(magic,pvp->magic,8);
magic[8]='\0';

//---------------------------//
// Print out what we get.... //
//---------------------------//

if (! strcmp(magic,"LVMREC01"))
{
printf("%s %s %#llx %#llx\n",argv[1],magic,pvp->pvid,pvp->vgid);
}
else
{
printf("%s doesn't look like an LVM disk\n");
exit(2);
}
}
SS_6
Valued Contributor

Re: Finding out the VGID for a volumegroup (CLI of C program)

do vgexport with preview and vgid scan option:
#vgexport -p -s -m /tmp/vgxxx.map /dev/vgxxx
It will create vgxxx.map file. View it and you will find the vgid at the very first line.
By providing solutions I am helping myself
David Ritchie
Frequent Advisor

Re: Finding out the VGID for a volumegroup (CLI of C program)


And here is a version of the code that will
compile under the bundled non-ANSI cc
compiler....