Wednesday Jun 08, 2011

Quick Local Repository

Solaris 11 Express makes it pretty easy to set up a local copy of the repository. However, the full repository is several gigabytes large, so that in itself can be a deterrent, especially if you're just looking to install a couple of packages.

A common reason folks need access to a local repository is because their system is not connected to the Internet. In this example I will show you how to create a local repository, receive files into it, copy that repository to another machine, install it as a publisher and finally install the software. My real world use case for this blog was my need to install software from an internal Oracle repository to an machine not connected to the Oracle network. However, for this example I'll use the public repository as my example and the Tomcat web server as the software I want to make available to the remote machine.

Step 1: Create a Repository

The first step is to create the repository to host the packages. This repository will then be copied to the remote machine. This is easily accomplished with the pkgrepo command. Here I'm creating a repository off of my home directory:

bleonard@solaris:~$ pkgrepo create ~/repo

This basically creates a directory, repo, with a single file, pkg5.repository:

bleonard@solaris:~$ cat repo/pkg5.repository 
[publisher]
prefix = 

[CONFIGURATION]
version = 4

[repository]
version = 4

Note, there's no command to delete the repository. As it's a file based repository, just delete the directory:

bleonard@solaris:~$ rm -r repo

Step 2: Receive the Packages into the Repository

The next step is to receive the packages into the new repository. For this I will use the pkgrecv command. If the repository you want to receive the packages from is not configured as a publisher, you can also specify that on the command line. In addition, you can use the -r option to recursively grab all of the package's dependencies. Beware, however, that depending on the package, this may end up downloading most of the repository. For this example I'm going to grab the Apache Tomcat server, sans dependencies:

bleonard@solaris:~$ pkgrecv -s http://pkg.oracle.com/solaris/release -d ~/repo web/java-servlet/tomcat web/java-servlet/tomcat/tomcat-examples
Processing packages for publisher solaris ...
Retrieving and evaluating 2 package(s)...                      
PROCESS                                         ITEMS     GET (MB)    SEND (MB)
Completed                                         2/2    10.4/10.4    13.5/13.5

Step 3: Copy the Repository to the Remote Machine

You could use your favorite approach for copying files. In this example, I'm going to use scp:

oracle@solaris:~$ scp -r bleonard@10.0.1.3:repo repo
The authenticity of host '10.0.1.3 (10.0.1.3)' can't be established.
RSA key fingerprint is f7:1d:2c:d7:24:e3:1c:57:53:0f:59:75:31:4a:0f:7d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.1.3' (RSA) to the list of known hosts.
Password: 
ndd: No such file or directory
pkg5.repository      100% |*****************************|    78       00:00    
19bd9e48c1f7ce9a2bb6 100% |*****************************|   541       00:00    
...
catalog.dependency.C 100% |*****************************|  1055       00:00    
6.0.28%2C5.11-0.151. 100% |*****************************| 45641       00:00    
6.0.28%2C5.11-0.151. 100% |*****************************| 71145       00:00    
6.0.20%2C5.11-0.133% 100% |*****************************|   419       00:00    

You can check the status of the new repo:

oracle@solaris:~$ pkgrepo info -s ~/repo
PUBLISHER PACKAGES STATUS           UPDATED
solaris   3        online           2011-06-07T20:38:51.166088Z

Note, searches against the repository will initially fail:

oracle@solaris:~$ pkg search -s file:///home/oracle/repo tomcat
pkg: Some repositories failed to respond appropriately:
solaris:
file protocol error: code: 11 reason: Search temporarily unavailable.
Repository URL: 'file:///home/oracle/repo'. (happened 4 times

This can be corrected by refreshing the index:

oracle@solaris:~$ pkgrepo refresh -s ~/repo
Repository refresh initiated.

oracle@solaris:~$ pkg search -s file:///home/oracle/repo tomcat
INDEX           ACTION VALUE                                               PACKAGE
description     set    Tomcat Servlet/JSP Container                        pkg:/web/java-servlet/tomcat@6.0.28-0.151.0.1
description     set    Tomcat Servlet/JSP Container - example applications pkg:/web/java-servlet/tomcat/tomcat-examples@6.0.28-0.151.0.1
pkg.description set    Tomcat Servlet/JSP Container                        pkg:/web/java-servlet/tomcat@6.0.28-0.151.0.1
pkg.description set    Tomcat Servlet/JSP Container - example applications pkg:/web/java-servlet/tomcat/tomcat-examples@6.0.28-0.151.0.1
pkg.summary     set    Tomcat Servlet/JSP Container                        pkg:/web/java-servlet/tomcat@6.0.28-0.151.0.1
pkg.summary     set    Tomcat Servlet/JSP Container - example applications pkg:/web/java-servlet/tomcat/tomcat-examples@6.0.28-0.151.0.1
pkg.fmri        set    solaris/web/java-servlet/tomcat                     pkg:/web/java-servlet/tomcat@6.0.28-0.151.0.1

To see all the packages in the repository:

oracle@solaris:~$ pkg search -p -s file:///home/oracle/repo '*'
PACKAGE                                                       PUBLISHER
pkg:/SUNWtcat-examples@6.0.20-0.133                           solaris
pkg:/web/java-servlet/tomcat/tomcat-examples@6.0.28-0.151.0.1 solaris
pkg:/web/java-servlet/tomcat@6.0.28-0.151.0.1                 solaris

Step 4: Add the Repository as a Publisher

Since the packages are from the default 'solaris' repository, we're just going to add a new origin to the existing configured repository. We'll then remove the default origin of http://pkg.oracle.com/solaris/release (since theoretically we can't connect to it anyway). If the packages were from a new or unconfigured repository, you would use the -p option instead:

oracle@solaris:~$ sudo pkg set-publisher -g file:///home/oracle/repo solaris

oracle@solaris:~$ sudo pkg set-publisher -G http://pkg.oracle.com/solaris/release/ solaris

oracle@solaris:~$ pkg publisher
PUBLISHER                             TYPE     STATUS   URI
solaris                  (preferred)  origin   online   file:///home/oracle/repo/

Step 5: Install Software

oracle@solaris:~$ sudo pkg install tomcat tomcat-examples
Password: 
               Packages to install:     2
           Create boot environment:    No
               Services to restart:     1
DOWNLOAD                                  PKGS       FILES    XFER (MB)
Completed                                  2/2     475/475      5.8/5.8

PHASE                                        ACTIONS
Install Phase                                610/610 

PHASE                                          ITEMS
Package State Update Phase                       2/2 
Image State Update Phase                         2/2 

In this particular case, we'll start the Tomcat server:

oracle@solaris:~$ sudo svcadm enable tomcat6


Friday Dec 03, 2010

File Based Repo

It was always possible to mount an ISO and use it as the package repository, but you also had to configure and run a local package server. With Solaris 11 Express, it is now possible to serve the packages directly from the local repository files, bypassing the server.

Step 1: Download the Repository Image

The repository image comes in two 2 GB chunks and they're available on the Solaris 11 Express Downloads page. After downloading parts A & B, unzip and concatenate them as follows:

bleonard@solaris:~$ cd Download/
bleonard@solaris:~/Download$ unzip sol-11-exp-201011-repo-full-iso-a.zip 
Archive:  sol-11-exp-201011-repo-full-iso-a.zip
  inflating: sol-11-exp-201011-repo-full.iso-a  
bleonard@solaris:~/Download$ unzip sol-11-exp-201011-repo-full-iso-b.zip 
Archive:  sol-11-exp-201011-repo-full-iso-b.zip
  inflating: sol-11-exp-201011-repo-full.iso-b  
bleonard@solaris:~/Download$ cat sol-11-exp-201011-repo-full.iso-a sol-11-exp-201011-repo-full.iso-b > sol-repo-full.iso

Note, I kept the ISO name generic, as this allows me to upgrade to a newer version of the repository by simply replacing the underlying ISO.

Step 2: Mount the Repository Image

Create a directory at which to mount the ISO:

 bleonard@solaris:~$ sudo mkdir /repo

Mount the ISO to the /repo directory:

bleonard@solaris:~$ sudo mount -F hsfs ~/Download/sol-repo-full.iso /repo

Step 3: Make the Mount Persistent

The mount will not survive a reboot. You have a couple of approaches to make it persist:

The Quick and Dirty Way

Add the following file to /etc/rc3.d:

# cat /etc/rc3.d/S99mountiso
#!/bin/sh
#
mount -F hsfs /export/home/bleonard/Download/sol-repo-full.iso /repo 

The SMF Way

Save the following repo.xml SMF manifest to /var/svc/manifest/system/filesystem, which defines a new service, repo.

Install the repo service:

bleonard@opensolaris:~$ svccfg import /var/svc/manifest/system/filesystem/repo.xml

Start the repo service:

bleonard@opensolaris:~$ svcadm enable repo 
bleonard@opensolaris:~$ svcs -l repo
fmri         svc:/system/filesystem/repo:default
name         Solaris ISO repository mounter
enabled      true
state        online
next_state   none
state_time   Mon Oct 11 09:40:07 2010
logfile      /var/svc/log/system-filesystem-repo:default.log
restarter    svc:/system/svc/restarter:default
dependency   require_all/none svc:/system/filesystem/local (online)

Step 4: Add the Local Repository as a Publisher

This is the new part in that a publisher can now point to a local file, bypassing the need to set up a local package server.

You can either set up the local file as a mirror or on its own. Use the following syntax to set it up as a mirror:

bleonard@solaris:~$ sudo pkg set-publisher -m file:///repo/repo/ -P solaris
bleonard@solaris:~$ pkg publisher
PUBLISHER                             TYPE     STATUS   URI
solaris                  (preferred)  origin   online   http://pkg.oracle.com/solaris/release/
solaris                  (preferred)  mirror   online   file:///repo/repo/

To remove the mirror:

bleonard@solaris:~$ sudo pkg set-publisher -M file:///repo/repo/ solaris

To set it up on its own:

bleonard@solaris:~$ sudo pkg set-publisher -G http://pkg.oracle.com/solaris/release -g file:///repo/repo/ -P solaris
bleonard@solaris:~$ pkg publisher
PUBLISHER                             TYPE     STATUS   URI
solaris                  (preferred)  origin   online   file:///repo/repo/

In the above we're removing the default remote repository and replacing it with the new local repository. You can see the status of the repository as follows:

bleonard@solaris:~$ pkgrepo info -s /repo/repo
PUBLISHER PACKAGES STATUS           UPDATED
solaris   3941     online           2010-11-11T00:04:39.171739Z

At this point, the repository is ready for use.

However, one minor limitation is that the repository doesn't include a search index (this was done to reduce the initial size of the repository):

bleonard@solaris:~$ pkg search hex
pkg: Some repositories failed to respond appropriately:
solaris:
file protocol error: code: 11 reason: Search temporarily unavailable.
Repository URL: 'file:///repo/repo'. (happened 4 times)

And since the ISO is mounted directly (and therefore, read-only), one can't be built. If you happen to extract the ISO, a search index could be build with the following command:

sudo pkgrepo -s /repo/repo refresh

Conclusion

I like this approach because when a new repository becomes available, I simply need to replace the ISO file and I'm all set. For further details, including how to set up a local repository server, see the article How To Copy an Oracle Solaris 11 Express Software Package Repository.

Friday Jul 31, 2009

Local Repository Mirror

In my previous entry I wrote about creating a portable version of the repository using a USB stick. That option is great for taking the repository on the road; however, a more practical use of this repository image to many of you may be setting up a local mirror. In this situation, you get the best of both words - fast access to the repository with continued access to updates as they become available.

[Read More]

Repo on a Stick

A snapshot of the OpenSolaris release repository has been made available for download as an ISO image, where it can be mounted directly or transfered to a USB stick. This will certainly come in handy if you plan to travel somewhere with limited network access but would like access to the repository. In this entry I'll review setting up a USB stick, which gives you a portable repository.[Read More]
About

The Observatory is a blog for users of Oracle Solaris. Tune in here for tips, tricks and more as we explore the Solaris operating system from Oracle.

Connect with Oracle Solaris:


Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
20
21
22
23
24
25
26
27
28
29
30
   
       
Today