Operating Running Systems
1. System Boot and Shutdown Procedures
a. Boot, Reboot, and Shutdown
To operate a system efficiently, it’s crucial to know how to manage its state.
- Boot: To start a system.
- Reboot: To restart a system.
- Shutdown: To turn off a system safely.
Example:
# To shut down the system shutdown -h now # To reboot the system shutdown -r now
Summary
- Understanding these commands ensures you can control the system’s power state safely.
Key Points
- Always shut down or reboot a system gracefully to prevent data loss.
- The
-hflag inshutdownmeans halt after shutting down.
Practical Exercise
- Practice safely shutting down and rebooting your system.
2. Booting into Different Targets
Systemd uses ‘targets’ instead of run-levels. Each target corresponds to a specific state.
Example:
# To change to rescue mode (similar to single-user mode) systemctl isolate rescue.target
Summary
- Targets are named configurations for sets of systemd services.
Key Points
- Familiar targets include
multi-user.targetandgraphical.target. - Use
systemctl get-defaultto check the default target.
Practical Exercise
- Identify your current target and change to a multi-user target.
3. Interrupting Boot Process
Sometimes you might need to interrupt the boot process for troubleshooting.
Example: Upon booting, at the GRUB menu, select the kernel entry you wish to edit, press ‘e’, and append init=/bin/bash to the kernel line to gain root shell access.
Summary
- Interrupting the boot process is a powerful tool but should be used cautiously.
Key Points
- This method is mainly for recovery purposes.
- Always ensure you know the implications of interrupting the boot process.
Practical Exercise
- Safely practice interrupting the boot process and entering rescue mode.
4. Managing Processes
a. Identifying CPU/Memory Intensive Processes
Use tools like top or htop to monitor system processes.
b. Killing Processes
If a process isn’t responding, you might need to terminate it.
Example:
# To kill a process with PID 1234 kill -9 1234
Summary
- Efficient system operation requires process management.
Key Points
- Use
ps aux | grep [process_name]to find a process’s PID. - The
-9signal inkillis SIGKILL, which forcefully terminates the process.
Practical Exercise
- Start a long-running process, identify its PID, and then kill it.
5. Adjusting Process Scheduling
The nice and renice commands adjust process priorities.
Example:
# Start a command with a nice value of 5 nice -n 5 [command] # Change the priority of a running process with PID 1234 to 5 renice 5 -p 1234
Summary
- Adjusting priorities ensures critical tasks get adequate resources.
Key Points
- Nice values range from -20 (highest priority) to 19 (lowest).
- Regular users can only assign positive nice values.
Practical Exercise
- Start two CPU-intensive tasks, adjust their priorities, and observe the differences.
6. Managing Tuning Profiles
Use tuned-adm to adjust system tuning profiles.
Example:
# To list available profiles tuned-adm list # To activate a profile tuned-adm profile [profile-name]
Summary
- Tuning profiles optimize the system for specific tasks.
Key Points
- Common profiles include
throughput-performanceandlatency-performance. - The active profile is applied on boot.
Practical Exercise
- Explore available tuning profiles and activate a different one.
7. System Logs and Journals
a. Locating and Interpreting Logs
System logs, usually in /var/log/, provide a history of system events.
Example:
# To view system messages cat /var/log/messages
b. System Journals with systemd
Systemd’s journalctl provides system logs with filtering options.
Example:
# To view the entire system journal journalctl
Summary
- Logs provide insights into system operations and issues.
Key Points
- Logs are crucial for troubleshooting.
- The systemd journal is binary and requires
journalctlto read.
Practical Exercise
- Retrieve logs related to the SSH service using
journalctl.
8. Preserving System Journals
By default, the journal is stored in /run/log/journal/ and is volatile. To make it persistent:
- Create
/var/log/journal/. - Set appropriate permissions.
- Restart the
journaldservice.
Summary
- Making journals persistent aids in long-term troubleshooting.
Key Points
- Persistent journals consume disk space; monitor usage.
- Journals are rotated; old entries are removed.
Practical Exercise
- Convert your journal storage to persistent and check its contents after a reboot.
9. Network Services Management
a. Start, Stop, and Check Network Services
Systemd controls services, including network ones.
Example:
# To start the SSH service systemctl start sshd # To check its status systemctl status sshd
b. Securely Transfer Files Between Systems
scp is a tool for secure file transfer.
Example:
# To copy a file to a remote system scp file.txt user@remote_host:/path/
Summary
- Managing network services is key for system administrators.
Key Points
- Always ensure necessary services are active and unnecessary ones are stopped.
- Use
scpwith caution, especially when transferring sensitive files.
Practical Exercise
- Transfer a file between two systems using
scp.