Recently, I was given a task to create on a HP-UX system a dummy file for each local filesystem in it's lost+found directory. This is needed for having a free space to create solution before extending a 100% full logical volume (LV) which requires a minimum of a 1 or 2 free physical extends (PE) on HP-UX LVM. This is called best practices. The filesystem shouldn't be NAS or SWAP and should be mounted. The challenge with this task is to extract for each active volume group (VG) it's proper PE size which is common for all the LVs and to create the dummy file twice the size of the PE, 2*PE size. To omit other unnecessary LVs like SWAP and NAS filesystems. Here's how I solved this task with Perl. First, I use vgdisplay -Fv output to get the data:
vg_name=/dev/vg00:vg_write_access=read,write:vg_status=available:max_l +v=255:cur_lv=9:open_lv=9:max_pv=16:cur_pv=1:act_pv=1:max_pe_per_pv=29 +53:vgda=2:pe_size=16:total_pe=2055:alloc_pe=1984:free_pe=71:total_pvg +=0:total_spare_pvs=0:total_spare_pvs_in_use=0:vg_version=1.0.0 lv_name=/dev/vg00/lvol1:lv_status=available,syncd:lv_size=1024:current +_le=64:allocated_pe=64:used_pv=1 lv_name=/dev/vg00/lvol2:lv_status=available,syncd:lv_size=4096:current +_le=256:allocated_pe=256:used_pv=1 lv_name=/dev/vg00/lvol3:lv_status=available,syncd:lv_size=1024:current +_le=64:allocated_pe=64:used_pv=1 lv_name=/dev/vg00/lvol4:lv_status=available,syncd:lv_size=1024:current +_le=64:allocated_pe=64:used_pv=1 lv_name=/dev/vg00/lvol5:lv_status=available,syncd:lv_size=2048:current +_le=128:allocated_pe=128:used_pv=1 lv_name=/dev/vg00/lvol6:lv_status=available,syncd:lv_size=8192:current +_le=512:allocated_pe=512:used_pv=1 lv_name=/dev/vg00/lvol7:lv_status=available,syncd:lv_size=4096:current +_le=256:allocated_pe=256:used_pv=1 lv_name=/dev/vg00/lvol8:lv_status=available,syncd:lv_size=8192:current +_le=512:allocated_pe=512:used_pv=1 lv_name=/dev/vg00/lvol9:lv_status=available,syncd:lv_size=2048:current +_le=128:allocated_pe=128:used_pv=1 pv_name=/dev/disk/disk2_p2:pv_status=available:total_pe=2055:free_pe=7 +1:autoswitch=On:proactive_polling=On pv_name=/dev/disk/disk2_p3:pv_status=available:total_pe=2055:free_pe=7 +1:autoswitch=On:proactive_polling=On pv_name=/dev/disk/disk2_p4:pv_status=available:total_pe=2055:free_pe=7 +1:autoswitch=On:proactive_polling=On vg_name=/dev/vg01:vg_write_access=read,write:vg_status=available:max_l +v=255:cur_lv=4:open_lv=4:max_pv=16:cur_pv=1:act_pv=1:max_pe_per_pv=43 +51:vgda=2:pe_size=4:total_pe=4351:alloc_pe=2646:free_pe=1705:total_pv +g=0:total_spare_pvs=0:total_spare_pvs_in_use=0:vg_version=1.0.0 lv_name=/dev/vg01/lvol1:lv_status=available,syncd:lv_size=7000:current +_le=1750:allocated_pe=1750:used_pv=1 lv_name=/dev/vg01/lvol2:lv_status=available,syncd:lv_size=512:current_ +le=128:allocated_pe=128:used_pv=1 lv_name=/dev/vg01/lvol3:lv_status=available,syncd:lv_size=2048:current +_le=512:allocated_pe=512:used_pv=1 lv_name=/dev/vg01/lvol4:lv_status=available,syncd:lv_size=1024:current +_le=256:allocated_pe=256:used_pv=1 pv_name=/dev/dsk/c0t1d0:pv_status=available:total_pe=4351:free_pe=1705 +:autoswitch=On:proactive_polling=On
Here we have two VGs, vg00 and vg01: first with 9 LVs and second with 4. One caveat, HP-UX does not support the -F mode in versions previous to 11.31 so a different approach has to be taken. At least in versions 11.11 and 11.23 I have tried. And second, I use dd if=/dev/zero of=dummy bs=1024k count=2*PE to create the file, which perhaps one might want to do it other way. One last thing to add is that the program is not checking for the free available space in advance, it just goes and creates the file whenever it can so perhaps some filesystems may become full. The Perl code follows. It does not contain comments, I apologize in advance.
#!/usr/bin/env perl $FILE="/etc/mnttab"; open FILE or die "Can't open $FILE: $!"; while (<FILE>) { chomp; ($lv, $fs) = split; push @mnttab, ($lv, $fs) } %mnttab = @mnttab; open(LVM, "vgdisplay -Fv |") || die "Can't fork vgdisplay: $!"; while (<LVM>) { chomp; $h_ref = {}; %{ $h_ref } = split(/[=:]/); if ( $h_ref->{vg_name} && $a_ref->[0]->{vg_name} ) { push @vgdisplay, $a_ref; $a_ref = () } delete $a_ref->[0] unless ( %{ $a_ref->[0] } ); push @{ $a_ref }, $h_ref } push @vgdisplay, $a_ref if ref($a_ref); for $i ( @vgdisplay ) { print "Detected VG: $i->[0]->{vg_name}\n"; print "The PE size is: $i->[0]->{pe_size}\n"; $count = 2*$i->[0]->{pe_size}; for ( $j = 1; $i->[$j]->{lv_name}; $j++ ) { next unless defined $mnttab{$i->[$j]->{lv_name}}; print "Detected LV: $i->[$j]->{lv_name}\t"; print "The LV is mounted on: $mnttab{$i->[$j]->{lv_nam +e}}\n"; print "Changing directory to the $mnttab{$i->[$j]->{lv +_name}}/lost+found\n"; chdir "$mnttab{$i->[$j]->{lv_name}}/lost+found" or war +n "Can't cd to $mnttab{$i->[$j]->{lv_name}}/lost+found: $!\n" and nex +t; print "Creating the dummy file: dummy\n"; !system "dd if=/dev/zero of=dummy bs=1024k count=$coun +t" or warn "Can't dd to file dummy\n"; } # for ( ; $i->[$j]->{pv_name}; $j++ ) { # print "Detected PV: $i->[$j]->{pv_name}\n"; # } print "########################################\n"; } close(LVM) || die "Can't close vgdisplay: $!";

In reply to HP-UX best practices by rustic

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.