Added link to kernel.org - Moves bash into Ch.2 - fixed codeblocks Ch.3

This commit is contained in:
ganome 2024-09-04 11:56:52 -06:00
parent 9fffd6aa28
commit 859e8c3603
Signed by untrusted user who does not match committer: Ganome
GPG Key ID: 944DE53336D81B83
6 changed files with 127 additions and 259 deletions

View File

@ -51,4 +51,7 @@ The process of building the kernel from source code after configuration. Kernel
### 11. Kernel Development Model:
The Linux kernel follows an open-source development model. Linus Torvalds oversees the project, with numerous contributors worldwide.
### 12. External Sources:
[Linux Kernel](https://kernel.org)
Understanding these aspects of the Linux kernel provides a solid foundation for kernel configuration. It helps in making informed decisions about which components to include or exclude based on your system's requirements.

View File

@ -7,48 +7,32 @@ Yum (Yellowdog Updater Modified) is the primary package management tool for Red
### 2. Basic Yum Commands
- Searching for packages:
```
yum search keyword
```
`yum search keyword`
- Getting information about a package:
```
yum info package_name
```
`yum info package_name`
- Installing a package:
```
sudo yum install package_name
```
`sudo yum install package_name`
- Removing a package:
```
sudo yum remove package_name
```
`sudo yum remove package_name`
- Updating all packages:
```
sudo yum update
```
`sudo yum update`
- Updating a specific package:
```
sudo yum update package_name
```
`sudo yum update package_name`
### 3. Working with Repositories
Yum uses repositories to fetch package information and the packages themselves.
- Listing enabled repositories:
```
yum repolist
```
`yum repolist`
- Listing all repositories (including disabled):
```
yum repolist all
```
`yum repolist all`
- Adding a new repository:
Create a .repo file in /etc/yum.repos.d/ with the following structure:
@ -62,100 +46,68 @@ gpgcheck=1
gpgkey=http://repository.url/RPM-GPG-KEY
```
- Enabling/disabling a repository:
```
sudo yum-config-manager --enable repository_id
sudo yum-config-manager --disable repository_id
```
- Enabling/disabling a repository:
- `sudo yum-config-manager --enable repository_id`
- `sudo yum-config-manager --disable repository_id`
### 4. Managing Package Groups
Yum can install predefined groups of packages.
- Listing available groups:
```
yum group list
```
`yum group list`
- Getting info about a group:
```
yum group info "group_name"
```
`yum group info "group_name"`
- Installing a group:
```
sudo yum group install "group_name"
```
`sudo yum group install "group_name"`
- Removing a group:
```
sudo yum group remove "group_name"
```
`sudo yum group remove "group_name"`
### 5. Yum Cache Management
Yum maintains a cache to speed up operations.
- Cleaning all cached packages and metadata:
```
sudo yum clean all
```
`sudo yum clean all`
- Cleaning only cached packages:
```
sudo yum clean packages
```
`sudo yum clean packages`
- Cleaning only cached metadata:
```
sudo yum clean metadata
```
`sudo yum clean metadata`
### 6. Advanced Yum Features
- Downloading a package without installing:
```
yumdownloader package_name
```
`yumdownloader package_name`
- Installing a local RPM package with Yum (to resolve dependencies):
```
sudo yum localinstall package_name.rpm
```
`sudo yum localinstall package_name.rpm`
- Checking for available updates:
```
yum check-update
```
`yum check-update`
- Listing installed packages:
```
yum list installed
```
`yum list installed`
- Listing available packages:
```
yum list available
```
`yum list available`
### 7. Yum History
Yum keeps a history of transactions, allowing you to undo or redo actions.
- Viewing Yum history:
```
yum history list
```
`yum history list`
- Undoing a transaction:
```
sudo yum history undo transaction_id
```
`sudo yum history undo transaction_id`
- Redoing a transaction:
```
sudo yum history redo transaction_id
```
`sudo yum history redo transaction_id`
### 8. Yum Configuration
@ -176,30 +128,20 @@ Yum's functionality can be extended with plugins. Some useful plugins include:
- yum-plugin-versionlock: Locks specified packages to a particular version
To install a plugin:
```
sudo yum install plugin_name
```
`sudo yum install plugin_name`
### 10. Troubleshooting
If you encounter issues with Yum, try these steps:
- Clear the Yum cache:
```
sudo yum clean all
```
`sudo yum clean all`
- Rebuild the Yum cache:
```
sudo yum makecache
```
`sudo yum makecache`
- Check for conflicting transactions:
```
sudo yum-complete-transaction --cleanup-only
```
`sudo yum-complete-transaction --cleanup-only`
- Verify the package database:
```
sudo yum check
```
`sudo yum check`

View File

@ -8,9 +8,7 @@
Before installing or upgrading packages, it's important to update your local package lists:
```bash
sudo apt-get update
```
`sudo apt-get update`
This command synchronizes your package lists with the repositories.
@ -18,73 +16,53 @@ This command synchronizes your package lists with the repositories.
To upgrade all installed packages to their latest versions:
```bash
sudo apt-get upgrade
```
`sudo apt-get upgrade`
For a more aggressive upgrade that might remove obsolete packages:
```bash
sudo apt-get dist-upgrade
```
`sudo apt-get dist-upgrade`
### 4. Installing Packages
To install a new package:
```bash
sudo apt-get install package_name
```
`sudo apt-get install package_name`
You can install multiple packages at once:
```bash
sudo apt-get install package1 package2 package3
```
`sudo apt-get install package1 package2 package3`
### 5. Removing Packages
To remove a package:
```bash
sudo apt-get remove package_name
```
`sudo apt-get remove package_name`
To remove the package along with its configuration files:
```bash
sudo apt-get purge package_name
```
`sudo apt-get purge package_name`
### 6. Searching for Packages
To search for a package:
```bash
apt-cache search keyword
```
`apt-cache search keyword`
### 7. Displaying Package Information
To show detailed information about a package:
```bash
apt-cache show package_name
```
`apt-cache show package_name`
### 8. Cleaning Up
To remove unnecessary packages:
```bash
sudo apt-get autoremove
```
`sudo apt-get autoremove`
To clear out the local repository of retrieved package files:
```bash
sudo apt-get clean
```
`sudo apt-get clean`
### 9. Handling Dependencies
@ -98,23 +76,17 @@ Package sources are defined in `/etc/apt/sources.list` and in files under `/etc/
To prevent a package from being automatically upgraded:
```bash
sudo apt-mark hold package_name
```
`sudo apt-mark hold package_name`
To remove the hold:
```bash
sudo apt-mark unhold package_name
```
`sudo apt-mark unhold package_name`
### 12. Simulating Operations
You can simulate operations without actually performing them using the `-s` flag:
```bash
sudo apt-get -s install package_name
```
`sudo apt-get -s install package_name`
This is useful for seeing what would happen without making any changes.

View File

@ -1,193 +1,148 @@
# Process Monitoring and Management in Linux
### 1. Viewing Running Processes
## 1. Viewing Running Processes
Let's start with the basic commands to view running processes:
- ps - Process Status
### ps - Process Status
The 'ps' command provides a snapshot of current processes.
Basic usage:
```
ps
```
`ps
Common options:
- `ps aux`: Shows all processes for all users
- `ps -ef`: Similar to aux, but in a different format
- `ps lax`: Provides more detailed information
- `-aux`: Shows all processes for all users
- `-ef`: Similar to aux, but in a different format
- `-lax`: Provides more detailed information
- top - Table of Processes
### top - Table of Processes
'top' provides a real-time, dynamic view of running processes.
Basic usage:
```
top
```
`top`
In top, you can use:
- 'q' to quit
- 'k' to kill a process (you'll be prompted for the PID)
- 'r' to renice (change priority) of a process
- htop - Interactive Process Viewer
### htop - Interactive Process Viewer
'htop' is an improved version of 'top' with a more user-friendly interface.
Install it (if not already installed):
```
sudo apt install htop # For Debian/Ubuntu
sudo yum install htop # For CentOS/RHEL
```
- `sudo apt install htop` # For Debian/Ubuntu
- `sudo yum install htop` # For CentOS/RHEL
Run it:
```
htop
```
`htop`
### 2. Process Management
## 2. Process Management
- kill - Terminate a Process
### kill - Terminate a Process
The 'kill' command sends a signal to a process, by default the TERM signal.
Basic usage:
```
kill PID
```
`kill PID`
Common signals:
- SIGTERM (15): Graceful termination
- SIGKILL (9): Forceful termination
Example:
```
kill -9 1234
```
`kill -9 1234`
- killall - Kill Processes by Name
### killall - Kill Processes by Name
'killall' allows you to kill all processes with a given name.
Example:
```
killall firefox
```
`killall firefox`
- pkill - Kill Processes Based on Name and Other Attributes
### pkill - Kill Processes Based on Name and Other Attributes
'pkill' is more flexible than killall, allowing you to kill processes based on various attributes.
Example:
```
pkill -u username firefox
```
`pkill -u username firefox`
- nice and renice - Adjust Process Priority
### nice and renice - Adjust Process Priority
'nice' starts a process with a specified priority, while 'renice' changes the priority of a running process.
Nice values range from -20 (highest priority) to 19 (lowest priority).
Example:
```
nice -n 10 command # Start 'command' with lower priority
renice -n 5 -p PID # Change priority of running process
```
- `nice -n 10 command` # Start 'command' with lower priority
- `renice -n 5 -p PID` # Change priority of running process
### 3. Background and Foreground Processes
## 3. Background and Foreground Processes
- Start a process in the background:
```
command &
```
### Start a process in the background:
`command &`
- Move a running process to the background:
### Move a running process to the background:
Press Ctrl+Z
- Bring a background process to the foreground:
```
fg %job_number
```
### Bring a background process to the foreground:
`fg %job_number`
- List background jobs:
```
jobs
```
### List background jobs:
`jobs`
### 4. Advanced Monitoring Tools
## 4. Advanced Monitoring Tools
- iotop - I/O Monitoring
### iotop - I/O Monitoring
'iotop' shows I/O usage by processes.
Install:
```
sudo apt install iotop # For Debian/Ubuntu
sudo yum install iotop # For CentOS/RHEL
```
- `sudo apt install iotop # For Debian/Ubuntu`
- `sudo yum install iotop # For CentOS/RHEL`
Run:
```
sudo iotop
```
`sudo iotop`
- nethogs - Network Monitoring
### nethogs - Network Monitoring
'nethogs' shows network usage by process.
Install:
```
sudo apt install nethogs # For Debian/Ubuntu
sudo yum install nethogs # For CentOS/RHEL
```
- `sudo apt install nethogs` # For Debian/Ubuntu
- `sudo yum install nethogs` # For CentOS/RHEL
Run:
```
sudo nethogs
```
`sudo nethogs`
- lsof - List Open Files
### lsof - List Open Files
'lsof' lists open files and the processes using them.
Example (list all network connections):
```
sudo lsof -i
```
`sudo lsof -i`
### 5. System Monitoring
## 5. System Monitoring
- free - Display Amount of Free and Used Memory
```
free -h # -h for human-readable format
```
### free - Display Amount of Free and Used Memory
`free -h` # -h for human-readable format
- vmstat - Report Virtual Memory Statistics
```
vmstat 1 # Report every second
```
### vmstat - Report Virtual Memory Statistics
`vmstat 1` # Report every second
- iostat - Report CPU Statistics and I/O Statistics
```
iostat 1 # Report every second
```
### iostat - Report CPU Statistics and I/O Statistics
`iostat 1` # Report every second
### 6. Process Tracking and Analysis
## 6. Process Tracking and Analysis
- strace - Trace System Calls and Signals
### strace - Trace System Calls and Signals
'strace' is useful for diagnosing problems with processes.
Example:
```
strace command
```
`strace command`
- ltrace - Library Call Tracer
### ltrace - Library Call Tracer
'ltrace' is similar to strace but for library calls.
Example:
```
ltrace command
```
`ltrace command`
### 7. Continuous Monitoring with watch
## 7. Continuous Monitoring with watch
The 'watch' command allows you to run any command periodically, showing output in fullscreen.
Example (update process list every 2 seconds):
```
watch -n 2 'ps aux | sort -nrk 3,3 | head -n 5'
```
Example (update process list every 2 seconds and look at top 5 lines of output):
- `watch -n 2 'ps aux | sort -nrk 3,3 | head -n 5'`

View File

@ -1,10 +1,10 @@
# Understanding and Using SystemD
### 1. Introduction to systemd
## 1. Introduction to systemd
systemd is an init system and system manager that has become the standard for many Linux distributions. It was designed to overcome limitations in the traditional SysV init system, providing faster boot times, dependency-based service control, and a unified interface for managing system services.
### 2. Core Concepts
## 2. Core Concepts
- Units: The basic building blocks of systemd. Units can represent services, devices, mount points, and more.
- Dependencies: systemd manages relationships between units, ensuring they start in the correct order.
@ -12,7 +12,7 @@ systemd is an init system and system manager that has become the standard for ma
- Sockets: Allow for service activation on demand.
- Timers: Provide cron-like functionality for scheduling tasks.
### 3. Unit Files
## 3. Unit Files
Unit files are configuration files that define how systemd should manage a unit. They are typically located in /etc/systemd/system/ or /usr/lib/systemd/system/.
@ -31,23 +31,22 @@ Restart=always
WantedBy=multi-user.target
```
### 4. Basic systemd Commands
## 4. Basic systemd Commands
- systemctl: The main command for interacting with systemd
- journalctl: Used for viewing logs
- systemd-analyze: Analyzes system boot-up performance
Common systemctl commands:
```
systemctl start service-name
systemctl stop service-name
systemctl restart service-name
systemctl status service-name
systemctl enable service-name
systemctl disable service-name
```
- `systemctl start service-name`
- `systemctl stop service-name`
- `systemctl restart service-name`
- `systemctl status service-name`
- `systemctl enable service-name`
- `systemctl disable service-name`
### 5. Managing Services
## 5. Managing Services
To create a new service:
1. Create a unit file in /etc/systemd/system/ (e.g., myservice.service)
@ -55,7 +54,7 @@ To create a new service:
3. Reload the systemd manager: `systemctl daemon-reload`
4. Start and enable the service: `systemctl start myservice && systemctl enable myservice`
### 6. System Boot and Target Units
## 6. System Boot and Target Units
systemd uses target units to manage the boot process. Key targets include:
- poweroff.target
@ -64,11 +63,9 @@ systemd uses target units to manage the boot process. Key targets include:
- graphical.target
To change the default target:
```
systemctl set-default graphical.target
```
`systemctl set-default graphical.target`
### 7. Logging with journald
## 7. Logging with journald
journald is systemd's logging system. Key features:
- Collects messages from the kernel, services, and applications
@ -76,13 +73,12 @@ journald is systemd's logging system. Key features:
- Supports structured logging
Basic journalctl usage:
```
journalctl -u service-name # View logs for a specific service
journalctl -f # Follow new log entries
journalctl --since "1 hour ago" # View recent logs
```
- `journalctl -u service-name` # View logs for a specific service
- `journalctl -f` # Follow new log entries
- `journalctl --since "1 hour ago"` # View recent logs
### 8. Advanced Features
## 8. Advanced Features
- Socket Activation: Services start on-demand when a client connects to their socket.
- Resource Control: Limit CPU, memory, and other resources for services.
@ -96,7 +92,7 @@ CPUQuota=20%
MemoryLimit=100M
```
### 9. Troubleshooting
## 9. Troubleshooting
- Check service status: `systemctl status service-name`
- View recent logs: `journalctl -u service-name -n 50 --no-pager`