11.10.2004

VXFS: Disk Group Clone and Splitting






How many times have you wanted to split up a disk group into two distinct disk groups? I can't count times (once so far) that it would have be benifical to back up a disk group to disk or to clone a system. The nice thing is, starting at Veritas 3.1, there is the option called Fast Resync that will allow you to break up disk groups into two unique disk groups. When you have two disk groups you can export/import them independantly of each other between systems which is a big help.

Before you attempt this I would ensure that you have a license for the Fast Resync option, otherwise the split command in step 6 won't work. Also I would suggest testing this before using in any kind of production environment. If you want split up a disk group like a high school kegger, do this:

1. Add mirror plexs to the volumes you wish to move in the disk group. Make sure that the physical volume(the actual disk) you add the mirrored plex(es) to does not contain any information other than plex(es) you wish to move.

vxassist -g dgname mirror volname newdisk1

2. Once the mirroring is complete (which can be done in advance) umount and stop the veritas volume(s):

umount /filesystem
vxvol -g dgname stop volname

3. Disassociate the Mirrored plex(es) from all the unmounted filesystem(s):

vxplex -g dgname dis plex_name

4. Modify the disassociated mirrored plex(es) to become their own volume(s)

vxpplex –g dgname dis plex_name
vxmake –g dgname –U fsgen vol new_volname plex=plex_name

5. At this point if you want to verify that the volume you just created is ok you can mount it up (you don't need to do this but whatever):

vxvol -g dg_name start new_volname
mount -F vxfs /dev/vx/dsk/dgname/new_volume /mountpoint

Check the volume however you would, once you are satisfied that every thing is ok unmount the volume and stop it again.

umount /mountpoint
vxvol -g dgname stop new_volname

If you don't trust me and have completed step 5, you might also want to run a vxprint to cover yourself:

vxprint -ht > /tmp/disk_layout

6. Run a vxdg split command to break the volumes off into a new disk group. You will need to know the Veritas name for the physical disk that will be making your new disk group (hint is will be in the vxprint -ht output from above):

vxdg split dgname new_dgname newdisk1 (newdisk2,newdisk3, ...)

At this point you will have two copies of the same data, in two distinctly different disk groups! At this point the sky is the limit, you can do just about anything (that is if what you want to do is something with the two disk groups). If you are on a SAN, you can export one of the disk groups and import them into a different host:

On host1:

vxdg deport new_dgname
vxdisk -o alldgs list

On host2:

vxdg import new_dgname
vxdisk -o alldgs list
vxvol -g dg_name start new_volname
mount -F vxfs /dev/vx/dsk/dgname/new_volume /mountpoint


8.04.2004

Solaris: Creating Solaris packages


Packaging organize the required software into a package that can be quickly added to another host or removed as quickly from the first host. This greatly decreases the time needed to add software to a host. Most of the information contained in this posting was derived from documents on ibiblio.org.

Creation of the software

To package any software you need to know which files are to be included in the package which is easy if you created the software. Since in our application this will generally be the case, it will be covered by this blog.

1. Complete the following step, replacing "YOUR_DIR" with the directory that contains the software that you want to install:



% cd /YOUR_DIR
% find . -print sed 's/^\.//g' > /tmp/files


2. Create a prototype file to uses with your package. This file contains a table of contents suitable to be used by the package creation tool.

% cat /tmp/files l pkgproto > /tmp/Prototype


This will take the /tmp/files file and with each entry it will look at the file and it's attributes and then create a /tmp/Prototype file with the following in it:


d none /dir1 0755 actraadm actra
f none /script1.sh 0755 actraadm actra
f none /dir1/readme 0644 actraadm actra


The character in for of the line depicts which type of item is being created.

'i' means it's an informational or control file for the package subsystem.
'd' means the file in question is a directory.
'f' means the file is a regular file.

After manually reviewing the /tmp/Prototype file you may notice the permissions are not to your liking. The Prototype file can be edited by hand to change the owner, group or file permissions.

3. Add an entry to the Prototype file for the "pkginfo" file. This file contains a lot of the details about the package including who made it and how to install it. Add the following line to the TOP of the Prototype file.



i pkginfo

If you want a checkinstall, preinstall, postinstall or postremove script to run on installation of the package simply include them at the top of the prototype file after the pkginfo line. Make sure to prefix the line with the
'i'
A checkinstall is a script that is run at install time, by the user "nobody". With it you can check for dependancies and problems and if needed, exit the pkgadd gracefully.

preinstall is run as root when the package is being installed An abort here will require the user to pkgrm the half installed package. You are asked by pkgadd if you want to run this script.

postinstall is a script that runs after the rest of the package has been installed, as the root user. With it you can do tasks like startup the software you just installed.

postremove is a script that runs after the package has been removed from the system as root. It can be used for additional clean up steps which may need to be run after the package is removed.

To add them to the Prototype file put in a line like:


i postinstall
i postremove
Finally our Prototype file looks like:


i pkginfo
i postinstall
d none /dir1 0755 actraadm actra
f none
/script1.sh 0755 actraadm actra
f none /dir1/readme 0644 actraadm actra

See the prototype man page for further information on this file (man -s 4 prototype).

4. Create a pkginfo file in the /YOUR_DIR directory. The pkginfo file tells pkgmk what you actually want the package to be called. Here is an example of a pkginfo file, see the pkginfo man page for more details (man -s 4 pkginfo):



PKG="MIKESPKG"
NAME="Mikes test package"
VERSION="1.0"
ARCH="sparc"
CLASSES="none"
CATEGORY="utility"
VENDOR="WPS"
PSTAMP="4thOct2002"
EMAIL="support@yourdomain.com"
BASEDIR="/YOUR_DIR"
5. Create the package.

% pkgmk -o -r /YOUR_DIR -d /tmp
The above command means make the package, overwrite any previous attempts (-o), use '/YOUR_DIR' as the root directory for locating the files (-r) and build the package in the /tmp directory (-d)

The output produced was:



## Processing pkginfo file.
## Attempting to volumize 5 entries in pkgmap.
part 1 -- 990 blocks, 6 entries
## Packaging one part.
/tmp/pkginfo
/tmp/postinstall
/tmp/dir1
/tmp/script1.sh
/tmp/dir1/readme
## Packaging complete.
This command created a directory in /tmp called MIKESPKG. Inside that directory were two files called pkgmap and pkginfo. This is your completed package.

6. To allow easy storage and transportation of this package all you need to do is run the pkgtrans command to make a single archive of the package.


%pkgtrans -s /tmp/ /tmp/MIKESPKG.pkg
This command searches the /tmp for packages (-s) and any packages which you decided to include will be added to the file /tmp/MIKESPKG.pkg.

7.15.2004

UNIX: Converting numbers with printf

Print a decimal number

$ printf "%d\n" 5
5

Print as float (default 6 decimal places)

$ printf "%f\n" 5
5.000000

Convert a hex number to decimal

$ printf "%d\n " 0xF
15

Convert a decimal number to Hex

$ printf "0x%X\n " 15
0xF

Convert a decimal number to Octal

$ printf "0%o\n " 8
010

7.13.2004

Solaris: Truss basics

The truss command traces library and system calls and signal activity for a given process. This can be very useful in locating problems with a particular process. To run the command you must be root and know the process Id of the command you wish to trace:

truss -p PID

You'll end up getting some output in the following format:

F15K >truss -p 4660
*** SUID: ruid/euid/suid = 200 / 0 / 0 ***
*** SGID: rgid/egid/sgid = 200 / 100 / 100 ***
semop(262145, 0x006C74E8, 1) (sleeping...)
Received signal #14, SIGALRM, in semop() [caught]
semop(262145, 0x006C74E8, 1) Err#4 EINTR
kill(4658, SIG#0) = 0
times(0x006C6FB0) = 55227913
alarm(3) = 0
setcontext(0x006C7140)
semop(262145, 0x006C74E8, 1) (sleeping...)


Your command output will vary, but you can see some of following items in a truss output:


brk() requests memory during execution.

exec() opens a program.

fcntl() performs control functions on open files.

fstat() obtains information about open files.

getdents64() reads directory information.

ioctl() performs terminal I/O.

lstat() obtains file attributes.

mmap() maps the program image into memory.

open() opens a file. It returns a number which is referenced when the file is used.

write() writes to an open file/device.



Obviously, this is only a subset of the system calls seen in truss output, but this subset is usually sufficient to figure out what is going on. Other system calls can be looked up in the Sun web pages or man pages. In most cases we will be looking for error messages in the truss output. These entries will contain the string "Err" in the last column of the output.

These errors can be categorized as system call errors or missing file errors. Many missing file errors are the result of a library not being in a directory early in the LD_LIBRARY_PATH or something of the sort. If the truss output shows a successful open() (or whatever) of the file name later in the process, that is probably not your culprit.

System call errors can be interpreted by looking at the man page of the specific system call or examining the file /usr/include/sys/errno.h.

UNIX: Streaming Tar

1. Move the files

cd src_dir
tar cf - . | (cd dest_dir; tar xvf - )


2. Verify everything got moved

cd src_dir
du -ak . > /tmp/src_dir.info
du -ak . > /tmp/dest_dir.info
diff /tmp/src_dir.info /tmp/dest_dir.info


If everything looks good and the sizes match on the du files you are golden