Pages

Solaris Runlevels

In Solaris, run levels define the operational state of the system. A run level determines which services are running, which users can log in, whether networking is active, and how the system behaves overall.

Run levels are managed by the init process (PID 1), which is the first user-space process started by the kernel. Every other process on the system is directly or indirectly a child of init.

Understanding run levels is important for:
  • System maintenance
  • Troubleshooting
  • Safe shutdown and reboot
  • Controlled service startup
  • Disaster recovery
What Is a Run Level?
A run level is a predefined system mode that determines:
  • Which services are started
  • Which daemons are stopped
  • Whether networking is enabled
  • Whether multiple users can log in
When the system changes run levels, init executes scripts located in specific directories:
/etc/rc0.d/
/etc/rc1.d/
/etc/rc2.d/
/etc/rc3.d/
/etc/rcS.d/
Each directory contains scripts that start (S) or kill (K) services 
in a specific sequence.

The Role of init (PID 1)
The init process is responsible for:
  • Reading /etc/inittab
  • Determining the default run level
  • Executing system initialization scripts
  • Managing transitions between run levels
  • Restarting critical system processes if needed
To see the default run level, check:
cat /etc/inittab
Example entry:
id:3:initdefault:
This means the system boots into run level 3 by default.

Solaris Run Levels Explained in Detail
Run Level 0 — Halt
Run level 0 completely shuts down the system.
What happens internally:
  • All user processes receive SIGTERM
  • After a timeout, remaining processes receive SIGKILL
  • Filesystems are unmounted
  • Swap is disabled
  • System enters firmware/OBP state (on SPARC)
  • Power can be turned off safely
Command:
init 0
Equivalent command:
shutdown -i0 -g0 -y
Use case:
Planned shutdown
Hardware maintenance

Run Level 1 — Single-User Mode
Run level 1 provides a minimal system environment.
Characteristics:
  • Only root login is allowed
  • Networking is disabled
  • Most services are stopped
  • Root filesystem is mounted
  • Other filesystems may not be mounted
This mode is used for:
  • Repairing filesystems (fsck)
  • Resetting passwords
  • Kernel troubleshooting
  • Fixing configuration errors
To enter from boot:
boot -s
To switch from multi-user:
init 1

In this mode, only essential system processes run. No remote logins are allowed.

Run Level 2 — Multi-User Mode (Without Network Services)
Run level 2 allows:
  • Multiple users to log in
  • Local console access
  • Most system services
However:
  • Network services like NFS and some daemons may not be started
  • Remote logins might not be available
Internally, scripts in:
/etc/rc2.d/

are executed.

Typical services started in run level 2:
  • Device management
  • Filesystem mounting
  • Basic system logging
  • Printing services
Command:
init 2

This run level is rarely used in modern production systems but can be useful in isolated environments.

Run Level 3 — Full Multi-User Mode (With Networking)
This is the normal operational mode.
Characteristics:
  • Multiple users
  • Full networking
  • All major services active
  • Remote access enabled
When entering run level 3, scripts in:
/etc/rc3.d/

are executed.

Typical services started:
  • NFS server/client
  • SSH daemon
  • Sendmail
  • RPC services
  • Web servers (if configured)
  • Application services
Command:
init 3

Most Solaris servers and workstations run in level 3.

Run Levels 4 and 5 — Reserved / Custom
By default, Solaris does not use run levels 4 and 5.
They are reserved for custom configurations.
Administrators can define:
  • Special maintenance states
  • Application-specific modes
  • Testing environments
To implement custom behavior, place scripts in:
/etc/rc4.d/
/etc/rc5.d/

These levels are rarely used in standard installations.

Run Level 6 — Reboot
Run level 6 performs a clean shutdown and automatic reboot.
Internally:
  • Stops services
  • Unmounts filesystems
  • Terminates processes
  • Reinitializes hardware
  • Returns to firmware briefly
  • Boots again
Command:
init 6
Equivalent:
reboot
shutdown -i6 -g0 -y
Used for:
  • Kernel updates
  • System patches
  • Configuration changes requiring restart
How Run-Level Scripts Work
Each run-level directory contains symbolic links to scripts in:
/etc/init.d/
Naming format:
S##name   → Start script
K##name   → Kill script
Example:
/etc/rc3.d/S15nfs.server
/etc/rc3.d/K20sendmail
Execution order:
  • Scripts execute in numeric order
  • Lower numbers execute first
  • Ensures dependency handling
When moving from level 3 to level 1:
  • All K scripts in rc1.d are executed
  • Necessary S scripts for level 1 are executed
This controlled sequencing ensures clean transitions.

Checking Current Run Level
To check current and previous run levels:
who -r
Output example:
.       run-level 3  Feb 12 10:15     3    0
Meaning:
Current level: 3
Previous level: 0
You can also use:
uptime

To confirm system state.

Run Levels and SMF (Service Management Facility)
Modern Solaris versions rely heavily on SMF.
Even though traditional run levels exist, service startup is mainly controlled by:
svc.startd
SMF provides:
  • Dependency-based startup
  • Automatic restart of failed services
  • Service state tracking
  • Fault management integration
To check service state:
svcs
To check failures:
svcs -xv
To enable/disable services:
svcadm enable <service>
svcadm disable <service>
In modern Solaris, run levels trigger milestone services in SMF rather than directly running only rc scripts.

Run Levels and Solaris Zones
Solaris Zones (containers) introduce isolation.
Important points:
  • Run levels apply only to the global zone.
  • Non-global zones do not use traditional run levels.
Zones are managed using:
  • zoneadm
  • zlogin
Each non-global zone has its own service management, but it does not transition through classic run levels like the global zone.
To check zone state:
zoneadm list -cv
Zone states:
  • configured
  • installed
  • ready
  • running
  • shutting_down
  • down
Zones operate independently of the system’s run level logic.

Safe Run Level Transition Example
Example: Switching from multi-user (3) to single-user (1)
init 1
Sequence:
  • Users are notified
  • Network services stop
  • Multi-user services stop
  • System drops to root console
Returning to normal mode:
init 3

Services restart in proper order.

Practical Administrative Use Cases
Filesystem Repair
init 1
fsck /dev/rdsk/c0t0d0s0
Network Troubleshooting
Switch to run level 2 to disable network-related services.
Emergency Recovery
Boot into single-user mode:
boot -s

Summary Table
Run LevelDescriptionTypical Use
0HaltShutdown
1Single-userMaintenance
2Multi-user (no full network)Limited operation
3Full multi-userNormal operation
4CustomAdmin-defined
5CustomAdmin-defined
6RebootRestart

Run levels provide controlled system state management in Solaris. They ensure:
  • Clean service startup
  • Safe shutdown
  • Controlled maintenance access
  • Predictable behavior during system transitions
Although modern Solaris systems rely heavily on SMF, understanding traditional run levels remains important for system administration, troubleshooting, and legacy environment support.

No comments:

Post a Comment