Usage Guide - My Linux Environment
Detailed instructions for using the QEMU Alpine Linux environment.
Table of Contents
- Basic Usage
- Alpine Linux Fundamentals
- Package Management
- File System Management
- System Administration
- Networking
- Development Tasks
- Advanced Techniques
- Common Workflows
Basic Usage
Starting the Environment
Windows:
double-click start_linux.bat
Linux/Mac:
./start_linux.shInitial Login
Alpine login: root
Password: [press Enter if no password]First Time Setup
After login, you’re in a fresh Alpine Linux system. Verify:
# Check you're in Alpine
cat /etc/os-release
# Check system time
date
# Check network status
ifconfig
# Check disk space
df -hAlpine Linux Fundamentals
What is Alpine Linux?
Alpine Linux is a minimal Linux distribution optimized for: - Small file size (~5MB core) - Memory efficiency (~128MB minimal) - Security (hardened by default) - Container deployment
Key Differences from Other Linux
| Feature | Alpine | Ubuntu/Debian | CentOS |
|---|---|---|---|
| Init System | OpenRC | systemd | systemd |
| Package Mgr | apk | apt | yum/dnf |
| Libc | musl | glibc | glibc |
| Size | ~5MB | ~1.5GB | ~2GB |
| Use Case | Containers | Desktop | Enterprise |
Alpine Basics
# Check Alpine version
cat /etc/alpine-release
# Check kernel version
uname -r
# Check installed packages
apk info
# Get system information
uname -a
lsb_release -a # (if installed)Package Management
Alpine uses apk (Alpine Package Keeper) for package management.
Common apk Commands
# Update package database
apk update
# Upgrade all packages
apk upgrade
# Search for a package
apk search vim
apk search -r "python" # Regex search
# Install packages
apk add vim
apk add openssh curl wget
# Install specific version
apk add vim@latest
apk add "nodejs<18"
# Remove package
apk del vim
# Remove with dependencies
apk del --purge vim
# List installed packages
apk info
# Get info about specific package
apk info vim
apk info -d openssh # Show description
# Search available packages
apk search # List all
apk search -d "text editor" # Search by description
# Fix package issues
apk fixInstalling Common Development Tools
# Essential build tools
apk add build-base
apk add gcc g++ make
# Version control
apk add git
apk add mercurial
# Text editors
apk add vim
apk add nano
apk add neovim
# Shells
apk add bash bash-doc
apk add zsh
# Python
apk add python3 py3-pip
# Node.js
apk add nodejs npm
# Ruby
apk add ruby ruby-devFile System Management
Directory Structure
# Alpine standard directories
/root # root user home
/home # regular user homes
/etc # configuration files
/var # variable data
/tmp # temporary files
/opt # optional software
/usr/local # user-installed software
/etc/apk # APK package managerFile Operations
# List files
ls # Basic listing
ls -la # Detailed with hidden
ls -lah # Same + human-readable
ls -1 # One file per line
ls -S # Sort by size
ls -t # Sort by time
# File inspection
file /path/to/file # Determine file type
stat /path/to/file # Detailed file info
# Change directory
cd /tmp
cd .. # Parent directory
cd ~ # Home directory
cd - # Previous directory
# Create/Remove
mkdir dirname # Create directory
mkdir -p a/b/c # Create nested
rmdir dirname # Remove empty directory
rm filename # Remove file
rm -rf dirname # Remove recursive
rm -i file # Interactive (confirm)
# Copy/Move
cp file1 file2 # Copy file
cp -r dir1 dir2 # Copy directory
mv file1 file2 # Move/rename
mv dir1 dir2 # Move directory
# View file contents
cat file # Display entire file
more file # Paginated view
less file # Scrollable view
head -n 5 file # First 5 lines
tail -n 5 file # Last 5 lines
tail -f file # Follow file (live)
# Search files
grep pattern file # Search in file
grep -r pattern . # Search recursive
grep -i pattern file # Case insensitive
find . -name "*.txt" # Find by patternPermissions & Ownership
# View permissions
ls -la
# Permission format: rwxrwxrwx (user|group|other)
# r=read(4) w=write(2) x=execute(1)
# Change permissions
chmod 755 file # rwxr-xr-x
chmod 644 file # rw-r--r--
chmod u+x file # Add execute for user
chmod g-w file # Remove write from group
chmod o-rwx file # Remove all from others
# Change ownership
chown user:group file
chown -R user:group dir
# Common combinations
chmod 700 file # Owner only (rwx------)
chmod 755 file # Script/executable (rwxr-xr-x)
chmod 644 file # Regular file (rw-r--r--)System Administration
Process Management
# List running processes
ps # Current shell processes
ps aux # All processes
ps aux | grep pattern # Find specific process
# Process info
top # Interactive process viewer
htop # Enhanced top (if installed)
# Background processes
command & # Run in background
jobs # List background jobs
fg # Bring to foreground
bg # Resume in background
# Kill processes
kill PID # Terminate process
kill -9 PID # Force kill
pkill pattern # Kill by nameSystem Information
# System info
uname -a # All system info
uname -s # Kernel name
uname -r # Kernel release
uname -m # Machine hardware name
# CPU info
nproc # Number of CPUs
cat /proc/cpuinfo # CPU details
# Memory info
free -h # Memory usage
free -m # In megabytes
cat /proc/meminfo # Detailed memory
# Disk usage
df -h # Disk space per filesystem
du -h /path # Directory size
du -sh /path # Total directory size
# Uptime
uptime
cat /proc/uptime
# Load average
cat /proc/loadavgUser Management
# Current user
whoami # Current username
id # User ID info
groups # Group membership
# List users
cat /etc/passwd # All users
# Switch user
su # Switch to root
su - username # Switch to user (with env)
exit # Exit su session
# Become root (if in sudoers)
sudo command
sudo -s # Root shell
# Change password
passwd # Change current password
passwd username # Change user password (as root)Service Management
Alpine uses OpenRC instead of systemd:
# Service operations
rc-service sshd start # Start service
rc-service sshd stop # Stop service
rc-service sshd restart # Restart service
rc-service sshd status # Check status
# Boot services
rc-update add sshd # Enable at boot
rc-update del sshd # Disable at boot
rc-update show # List boot services
# Manual startup
/etc/init.d/sshd start # Direct init script
# List all services
rc-service --listNetworking
Network Configuration
# View network interfaces
ifconfig
ip addr show
ip link show
# View routes
route -n
ip route show
# View DNS
cat /etc/resolv.conf
# View network stats
netstat -an
ss -an # Modern equivalentConnectivity Testing
# Test internet connectivity
ping 8.8.8.8 # Google DNS
ping -c 4 example.com # Limit to 4 packets
# DNS resolution
nslookup example.com
dig example.com
# Get network info
hostname # Current hostname
echo $HOSTNAME # Hostname variable
hostnamectl set-hostname newname # Change hostname (if available)Common Tools
# Download files
wget https://example.com/file.tar.gz
curl https://example.com/file
# Network utilities
apk add net-tools # Add netstat, ifconfig, etc.
apk add curl wget # HTTP clients
apk add openssh-client # SSH client
apk add nmap # Network scannerDevelopment Tasks
Working with Git
# Install git
apk add git
# Configure git
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
# Clone repository
git clone https://github.com/user/repo.git
# Common git tasks
cd repo
git status # Check status
git add . # Stage changes
git commit -m "msg" # Commit
git push # Push to remote
git pull # Pull latest
git log # View history
git branch -a # List branchesPython Development
# Install Python
apk add python3 py3-pip py3-venv
# Create virtual environment
python3 -m venv env
source env/bin/activate
# Install packages
pip install package_name
pip list
# Run Python
python3 script.py
# Interactive Python
python3Node.js Development
# Install Node
apk add nodejs npm
# Check versions
node --version
npm --version
# Create project
mkdir myproject
cd myproject
npm init -y
# Install dependencies
npm install package_name
# Run project
npm startShell Scripting
# Create script
cat > myscript.sh << 'EOF'
#!/bin/sh
echo "Hello, World!"
uname -a
EOF
# Make executable
chmod +x myscript.sh
# Run script
./myscript.sh
# View script
cat myscript.sh
# Edit script
vi myscript.shAdvanced Techniques
SSH Server Setup
# Install openssh
apk add openssh openssh-doc
# Generate keys (first time)
ssh-keygen -A
# Start SSH server
rc-service sshd start
# Enable at boot
rc-update add sshd
# Connect from host
# On your host machine:
# ssh root@127.0.0.1Creating Users
# Add user
adduser username
# Add user (non-interactive)
adduser -D username
# Set password
passwd username
# Add to group
addgroup username groupname
# User info
id username
groups usernameWorking with Archives
# Tar archives
tar -czf archive.tar.gz directory/ # Create compressed
tar -xzf archive.tar.gz # Extract
# Zip files
apk add zip unzip
zip -r archive.zip directory/
unzip archive.zip
# View contents without extracting
tar -tzf archive.tar.gz
unzip -l archive.zipText Processing
# Stream editor
sed 's/old/new/' file # Replace first
sed 's/old/new/g' file # Replace all
sed '1,5d' file # Delete lines 1-5
# Field extraction
awk -F: '{print $1}' /etc/passwd # Print first field
awk '{print NR, $0}' file # Print with line numbers
# Filtering
grep pattern file
grep -v pattern file # Invert match
# Sorting and counting
sort file
sort -n file # Numeric sort
uniq file # Remove duplicates
wc -l file # Count linesScripting Utilities
# Check syntax without running
sh -n script.sh
# Debug mode
sh -x script.sh
# Conditional execution
command1 && command2 # command2 if command1 succeeds
command1 || command2 # command2 if command1 fails
# Piping
command1 | command2 # Pipe output
command1 2>&1 # Redirect stderr to stdout
# Output redirection
command > file # Overwrite
command >> file # Append
command 2> error.log # Redirect errorsCommon Workflows
Workflow 1: System Update
# Update and upgrade
apk update
apk upgrade
# Check what would change
apk upgrade --dry-run
# Full system update
apk update && apk upgradeWorkflow 2: Install Development Stack
# Install essentials
apk add build-base git curl wget
# Install Python
apk add python3 py3-pip
# Create project directory
mkdir -p ~/projects/myapp
cd ~/projects/myapp
# Initialize git
git init
# Create virtual environment
python3 -m venv env
source env/bin/activate
# Install dependencies
pip install flask
echo "Flask is ready!"Workflow 3: Set Up Web Server
# Install web server
apk add nginx
# Start server
rc-service nginx start
# Enable at boot
rc-update add nginx
# Check status
rc-service nginx status
# Configure
vi /etc/nginx/nginx.conf
# Test configuration
nginx -tWorkflow 4: Create Backup
# Create tar backup
tar -czf backup-$(date +%Y%m%d).tar.gz ~/data/
# List backups
ls -lh backup-*.tar.gz
# Verify backup
tar -tzf backup-20250101.tar.gz | head
# Restore from backup
tar -xzf backup-20250101.tar.gzWorkflow 5: System Maintenance
# Check disk usage
df -h
# Clean package cache
apk cache clean
# Remove unused packages
apk autoremove
# Check for updates
apk update
# Upgrade all packages
apk upgrade
# Check file system
fsck /dev/hda1 # Requires reboot
# System shutdown
shutdown -h now # Halt
shutdown -r now # RebootKeyboard Shortcuts
QEMU Console Shortcuts
Ctrl+A then c - QEMU monitor prompt
Ctrl+A then d - Detach
Ctrl+A then h - Help
Ctrl+A then x - Force exit QEMU
Alpine Shell Shortcuts
Ctrl+C - Interrupt process
Ctrl+Z - Suspend process
Ctrl+D - Send EOF (exit)
Ctrl+L - Clear screen
Ctrl+U - Clear line
Ctrl+A - Start of line
Ctrl+E - End of line
Troubleshooting Usage
“Command not found”
# Package might not be installed
apk search command_name
# Install it
apk add package_name
# Or check if it's in PATH
which command_name
echo $PATH“Permission denied”
# Make file executable
chmod +x file
# Or run with elevated privileges
su -“Disk full”
# Check disk usage
df -h
# Find large files
find / -size +100M
# Clean cache
apk cache clean“Out of memory”
# Check memory
free -h
# Close other processes
ps aux
kill PID
# Check running processes
topNext Steps
- Complete the SETUP.md instructions
- Try the workflows in “Common Workflows” section
- Install tools you need with
apk add - Read ARCHITECTURE.md for technical details
- Visit Alpine Linux documentation: https://wiki.alpinelinux.org/
Last Updated: July 30, 2025