How to Extract Files from Solaris PKG Without Installation or Modifying Package Database


3 views

When working with Solaris systems, you often need to inspect or use package contents without actually installing them to system directories like /usr. This is particularly important for:

  • Creating self-contained application deployments
  • Maintaining clean separation from OS files
  • Developing portable solutions
  • Debugging package contents

You'll need these Solaris utilities:

pkgtrans
pkginfo
pkgchk

Here's how to extract a Solaris package to a custom directory:

# Create target directory
mkdir -p /our_own_directory/our_own_prefix_specific_for_this_package

# Convert package to directory format
pkgtrans -s /path/to/package.pkg /our_own_directory/our_own_prefix_specific_for_this_package directory_format

# Verify contents
pkginfo -d /our_own_directory/our_own_prefix_specific_for_this_package

For more control over extraction:

# Create a temporary admin file
echo "basedir=/our_own_directory/our_own_prefix_specific_for_this_package" > /tmp/noninst_admin

# Extract without installing
pkgchk -d /path/to/package.pkg -a -n -R /our_own_directory/our_own_prefix_specific_for_this_package

Solaris packages come in different formats. For datastream packages (most common):

pkgtrans /path/to/package.pkg /output/dir all

For SVR4 packages:

pkgadd -d /path/to/package.pkg -R /our_own_directory/our_own_prefix_specific_for_this_package -a /tmp/noninst_admin -n

After extraction, check the package metadata:

pkginfo -l -d /our_own_directory/our_own_prefix_specific_for_this_package
  • The -n flag prevents updating package database
  • Some packages may have installation scripts that expect standard paths
  • Always check dependencies with pkgdepend
  • For complex packages, consider using pkgmogrify to modify paths

Extracting Oracle Solaris Studio to a custom location:

mkdir -p /opt/devtools/solaris_studio_12.6
pkgtrans -s SolarisStudio12.6-solaris-x86.pkg /opt/devtools/solaris_studio_12.6 directory_format

When working with Solaris package files (.pkg), the standard installation procedure modifies system directories and updates the package database. For development environments where you need isolated deployments or want to examine package contents without system-wide changes, this behavior is problematic.

The pkgtrans utility allows extraction of package contents without installation. Here's the basic command structure:


pkgtrans source_pkg.pkg /target/directory all

For your specific case wanting to extract to /our_own_directory/our_own_prefix_specific_for_this_package:


mkdir -p /our_own_directory/our_own_prefix_specific_for_this_package
pkgtrans original.pkg /our_own_directory/our_own_prefix_specific_for_this_package all

If dealing with datastream packages (.pkg.gz or .pkg.Z), first decompress:


gunzip package.pkg.gz
pkgtrans package.pkg /our_target_dir all

For more control over the extraction process:


pkginfo -d package.pkg
# Identify the package instance name from output
pkgcp -d package.pkg PKGINST /our_target_dir all

Since this method bypasses normal installation, be aware that:

  • Dependencies won't be automatically resolved
  • Environment variables may need manual configuration
  • Binary paths might require adjustment

After extraction, verify the contents:


find /our_own_directory/our_own_prefix_specific_for_this_package -type f

Compare against the package manifest if available:


pkginfo -l -d package.pkg | grep PATH

Since we're not using the package database, removal is simply:


rm -rf /our_own_directory/our_own_prefix_specific_for_this_package