How to change the output of the uname command in the Solaris OS

by Bernd Schemmer, March 2009

Homepage: http://www.bnsmb.de/

17.04.2012/ bs: The links to sun.com in this article do not work anymore.

Table of contents

Introduction

This article describes a general method to temporary change the output of the uname command in the Solaris OS.
The method described here uses the sloggi kernel module written by Konrad Rieck that works in Solaris 8, Solaris 9, Solaris 10, Solaris Express, OpenSolaris, and other distributions based on that code. sloggi can be used in Solaris for SPARC and Solaris for x86.
In Solaris 10 you can also use dtrace for this purpose but obviously that does not work in previous Solaris releases.

Purpose

Some times it's necessary to temporary change the output of the uname command in Solaris. Examples that comes to mind here are
- install a package created for Solaris version X on Solaris version Y
- test a binary or a script behavior under various Solaris versions or releases

Scope

This article describes how to change the output of the uname command only.

Prerequisites

A machine installed with the Solaris version that is also installed on the target machine on which you want to change the output of the uname command.
An installed C compiler on that machine - either gcc 3.x (or newer) or Sun Studio.

References

sloggi home page  
  http://www.roqe.org/sloggi/
DTrace, April Fools and Solaris 10 Binary Compatibility
  http://blogs.sun.com/angelo/entry/dtrace_helps_with_binary_compatability
Spoofing Solaris version using dtrace
  http://blogs.sun.com/LetTheSunShineIn/entry/spoofing_solaris_version_using_dtrace
 

Update 30.04.2009:

Here is another wiki entry describing how to change the output of uname with mdb:

Changing the value of kernel static strings

Credits

Konrad Rieck - author of sloggi
Keith M Wesolowski and Glenn Brunette for there support to compile sloggi for Solaris x86 64bit

Installation

Sloggi is only available as source so you must first compile it for the target Solaris release. A detailed description on how to do this is on the home page for sloggi but for your convenience I'll add it here also (with the necessary changes for special environments):
First download the source to a local directory

$ wget http://www.roqe.org/sloggi/sloggi-0.1.2.tar.gz
--11:46:18--  http://www.roqe.org/sloggi/sloggi-0.1.2.tar.gz
           => `sloggi-0.1.2.tar.gz'
Resolving www.roqe.org... 80.67.17.168
Connecting to www.roqe.org|80.67.17.168|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8,562 (8.4K) [application/x-tar]

100%[==============================================================================>] 8,562         --.--K/s

11:46:19 (380.89 KB/s) - `sloggi-0.1.2.tar.gz' saved [8562/8562]

Now unpack the tar file

$ gzip -cd sloggi-0.1.2.tar.gz | tar -xf -

Then edit the makefile

$ cd sloggi-0.1.2/src
$ vi Makefile

Depending on the compiler you're using either comment out the statements for gcc

# GCC version 3.x setup
#CC=gcc
#CFLAGS32=-m32
#CFLAGS64=-D_64BIT -m64

and uncomment the statements for Sun Studio

# Sun C Compiler setup
CC=ccCFLAGS32=-xarch=generic
CFLAGS64=-D_64BIT -xarch=generic64

or vice versa.

For Solaris Nevada or OpenSolaris another change is necessary:
Comment the lines

SOL_REL:sh=/usr/bin/uname -r | cut -f2 -d.
SOL_REL+= $(shell /usr/bin/uname -r | cut -f2 -d.)

and add the line

SOL_REL=10

so that it looks like

#SOL_REL:sh=/usr/bin/uname -r | cut -f2 -d.
#SOL_REL+= $(shell /usr/bin/uname -r | cut -f2 -d.)
SOL_REL=10

In general these change are necessary for all Solaris versions where

uname -r

does NOT return 5.8, 5.9 or 5.10.

For compiling sloggi with gcc for x86 with 64 bit two other changes are necessary
Replace the line

CFLAGS64=-D_64BIT -m64

with

CFLAGS64=-D_64BIT -m64 -ffreestanding -mcmodel=kernel -mno-red-zone

And replace all occurrences of

sparcv9

with

amd64

Note: I did not test how to compile sloggi with Sun Studio in Solaris x86 64-bit yet.

Now you can compile sloggi using 

make

E.g. with Sun Studio in Solaris SPARC:

$ make
mkdir sparcv9
cc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -xarch=generic -c -o sloggi.o sloggi.c
cc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -xarch=generic -c -o refcnt.o refcnt.c
cc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -xarch=generic -c -o ujacket.o ujacket.c
cc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -xarch=generic -c -o utils.o utils.c
/usr/ccs/bin/ld -o sloggi -r sloggi.o refcnt.o ujacket.o utils.o
sync
cc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -D_64BIT-xarch=generic64 -c -o sparcv9/sloggi.o sloggi.c
cc: Warning: -xarch=generic64 is deprecated, use -m64 to create 64-bit programs
cc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -D_64BIT -xarch=generic64 -c -o sparcv9/refcnt.o refcnt.c
cc: Warning: -xarch=generic64 is deprecated, use -m64 to create 64-bit programs
cc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -D_64BIT -xarch=generic64 -c -o sparcv9/ujacket.o ujacket.c
cc: Warning: -xarch=generic64 is deprecated, use -m64 to create 64-bit programs
cc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -D_64BIT -xarch=generic64 -c -o sparcv9/utils.o utils.c
cc: Warning: -xarch=generic64 is deprecated, use -m64 to create 64-bit programs
/usr/ccs/bin/ld -o sparcv9/sloggi -r sparcv9/sloggi.o sparcv9/refcnt.o sparcv9/ujacket.o sparcv9/utils.o
sync
cc -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -o slogctl slogctl.c

 
or with gcc in Solaris x86:

# make
mkdir amd64
gcc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -m32 -ffreestanding  -mno-red-zone -c -o sloggi.o sloggi.c
gcc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -m32 -ffreestanding  -mno-red-zone -c -o refcnt.o refcnt.c
gcc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -m32 -ffreestanding  -mno-red-zone -c -o ujacket.o ujacket.c
gcc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -m32 -ffreestanding  -mno-red-zone -c -o utils.o utils.c
/usr/ccs/bin/ld -o sloggi -r sloggi.o refcnt.o ujacket.o utils.o
sync
gcc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -D_64BIT -m64 -ffreestanding -mcmodel=kernel -mno-red-zone -c -o amd64/sloggi.o sloggi.c
gcc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -D_64BIT -m64 -ffreestanding -mcmodel=kernel -mno-red-zone -c -o amd64/refcnt.o refcnt.c
gcc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -D_64BIT -m64 -ffreestanding -mcmodel=kernel -mno-red-zone -c -o amd64/ujacket.o ujacket.c
gcc -D_KERNEL -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -D_64BIT -m64 -ffreestanding -mcmodel=kernel -mno-red-zone -c -o amd64/utils.o utils.c
/usr/ccs/bin/ld -o amd64/sloggi -r amd64/sloggi.o amd64/refcnt.o amd64/ujacket.o amd64/utils.o
sync
gcc -DSVR4 -DSOL2 -DVERSION=\"0.1.2\" -DSOL_REL=10 -o slogctl slogctl.c


To install sloggi on the machine where you did compile it use:

make install

To install sloggi on another machine copy

./sloggi

to

/usr/kernel/misc

and (for SPARC machines)

./sparcv9/sloggi

to

/usr/kernel/misc/sparcv9

or (for x86 machines)

./amd64/sloggi

to

/usr/kernel/misc/amd64

Copy also

./slogctl

to

/usr/sbin

If installing sloggi manual ensure that you copy the 32 bit modules to the directory /usr/kernel/misc and the 64 bit modules to the directory /usr/kernel/misc/sparv9 (for SPARC) or /usr/kernel/misc/amd64 (for x86).

Use "file <kernelname>" to check whether a module is a 32 bit module or a 64 bit module, e.g.

# file sloggi amd64/sloggi
sloggi:         ELF 32-bit LSB relocatable 80386 Version 1
amd64/sloggi:   ELF 64-bit LSB relocatable AMD64 Version 1

$ file sloggi sparcv9/sloggi
sloggi:         ELF 32-bit MSB relocatable SPARC32PLUS Version 1, V8+ Required
sparcv9/sloggi: ELF 64-bit MSB relocatable SPARCV9 Version 1

Usage

To load the new module either reboot the machine or issue

# on 32 bit machines (either SPARC or x86)
#
$ modload /usr/kernel/misc/sloggi

# on 64 bit SPARC machines
#
$ modload /usr/kernel/misc/sparcv9/sloggi

# on 64 bit x86 machines
#
$ modload /usr/kernel/misc/amd64/sloggi

Check that the module is loaded with

$ modinfo | grep sloggi
293 7b6482f0   22d8   -   1  sloggi (Sloggi v0.1.2)

Now you can use the command slogctl to change the output of the uname command, e.g.

$ slogctl -h
Usage: slogctl [-hV] [-s sysname] [-r release] [-v version] [-m machine]
Options:   -s sysname   Set the name of the operating system.
                [Default: SunOS]
           -r release   Set the operating system release level.
                [Usually: 5.8, 5.9, ...]
           -v version   Set the the operating system version.
                [Default: Generic]
           -m machine   Set the machine hardware name (class).
                [Usually: sun4m, sun4u, i86pc, ...]
           -h           Print this help screen.
           -V           Print version information.
No options restore the original uname() setup

$ uname -a
SunOS sol9 5.11 snv_107 sun4u sparc SUNW,Sun-Blade-1000

$ slogctl -r 5.10
SunOS sol9 5.10 snv_107 sun4u

$ uname -a
SunOS sol9 5.10 snv_107 sun4u sparc SUNW,Sun-Blade-1000

Note that sloggi changes are global - the changes are also visible in zones,e.g.

# in the global zone
#
$ uname -a
SunOS sol9 5.10 snv_107 sun4u sparc SUNW,Sun-Blade-1000

$ slogctl -r 5.8
SunOS sol9 5.8 snv_107 sun4u

# in a non-global zone
#
$ zonenamesunstudio12

$ uname -a
SunOS sol9 5.8 snv_107 sun4u sparc SUNW,Sun-Blade-1000

Uninstallation

To uninstall sloggi on the machine on which it was compiled do a

make uninstall

To uninstall sloggi on a machine on which it was installed manually do

# change uname output to the default values
#
$ slogctl

# unload the module
#
$ modinfo | grep sloggi
293 7b6a22d8   22d8   -   1  sloggi (Sloggi v0.1.2)

$ modunload -i 293

# check the result
#
$ modinfo | grep sloggi

# and remove the modules
#
find /usr/kernel -name sloggi -exec rm {} \;

Troubleshooting

Important hint:
The sloggi module is a version dependent kernel module! Never install the sloggi module compiled for a specific Solaris version in another Solaris version because this will likely crash your system!