# Particle-OS Production Deployment Guide

## Overview

This guide provides comprehensive instructions for deploying Particle-OS in production environments. Particle-OS is now ready for production deployment with all core components validated and working together.

## Prerequisites

### System Requirements
- **Hardware**: x86_64 architecture with UEFI support
- **Memory**: Minimum 4GB RAM, recommended 8GB+
- **Storage**: Minimum 20GB disk space, recommended 50GB+
- **Network**: Internet connectivity for package updates
- **Boot**: UEFI firmware with secure boot support (optional)

### Software Requirements
- **Base System**: Debian 13+ (Trixie) or compatible
- **Container Runtime**: Podman or Docker
- **Virtualization**: QEMU/KVM for testing (optional)

## Deployment Options

### 1. Container-Based Deployment (Recommended)

#### Quick Start
```bash
# Pull the latest Particle-OS container
podman pull git.raines.xyz/robojerk/particle-os/simple-cli:latest

# Run Particle-OS in container
podman run -it --rm simple-cli:latest bash

# Verify tools are working
apt-ostree --version
bootupctl --version
bootc --version
ostree --version
```

#### Production Container Deployment
```bash
# Create persistent container
podman run -d --name particle-os-prod \
  --restart unless-stopped \
  -v /host/var:/var:rslave \
  -v /host/etc:/etc:rslave \
  simple-cli:latest

# Access production container
podman exec -it particle-os-prod bash
```

### 2. Variant-Specific Deployment

#### Gaming Variant (Euclase)
```bash
# Pull gaming variant
podman pull git.raines.xyz/robojerk/particle-os/euclase:latest

# Run with gaming tools
podman run -it --rm \
  --device /dev/dri \
  --device /dev/snd \
  euclase:latest bash
```

#### Server Variant (Bosom)
```bash
# Pull server variant
podman pull git.raines.xyz/robojerk/particle-os/bosom:latest

# Run with server configuration
podman run -d --name particle-os-server \
  --restart unless-stopped \
  -p 80:80 -p 443:443 \
  bosom:latest
```

#### Development Variant (Apex)
```bash
# Pull development variant
podman pull git.raines.xyz/robojerk/particle-os/apex:latest

# Run with development tools
podman run -it --rm \
  -v $(pwd):/workspace \
  apex:latest bash
```

#### Minimal Variant (Corona)
```bash
# Pull minimal variant
podman pull git.raines.xyz/robojerk/particle-os/corona:latest

# Run with minimal footprint
podman run -it --rm corona:latest bash
```

## Production Configuration

### 1. System Configuration

#### OSTree Configuration
```bash
# Configure OSTree repository
ostree remote add particle-os https://git.raines.xyz/robojerk/particle-os/ostree.git

# List available deployments
ostree remote list-refs particle-os

# Deploy specific version
ostree remote refs particle-os | head -1 | xargs ostree pull particle-os
```

#### Bootloader Configuration
```bash
# Check bootloader status
bootupctl status

# Update bootloader components
bootupctl update

# Verify bootloader health
bootupctl validate
```

### 2. Package Management

#### Atomic Package Updates
```bash
# Check available updates
apt-ostree upgrade --dry-run

# Perform atomic update
apt-ostree upgrade

# Verify update success
apt-ostree status

# Rollback if needed
ostree admin rollback
```

#### Package Installation
```bash
# Install packages atomically
apt-ostree install package-name

# Remove packages atomically
apt-ostree remove package-name

# Search available packages
apt-ostree search search-term
```

### 3. Container Management

#### Bootc Configuration
```bash
# Check container status
bootc status

# Update container image
bootc upgrade

# Rollback container
bootc rollback

# Verify deployment
bootc verify
```

## Monitoring and Maintenance

### 1. System Health Monitoring

#### Health Checks
```bash
# Check system status
apt-ostree status
ostree status
bootupctl status
bootc status

# Monitor resource usage
free -h
df -h
ps aux | head -20
```

#### Log Monitoring
```bash
# Check system logs
journalctl -u ostree
journalctl -u bootupd
journalctl -u bootc

# Monitor real-time logs
journalctl -f
```

### 2. Update Management

#### Automated Updates
```bash
# Create update script
cat > /usr/local/bin/particle-os-update << 'EOF'
#!/bin/bash
echo "Starting Particle-OS update..."
apt-ostree upgrade --dry-run
if [ $? -eq 0 ]; then
    echo "Update available, proceeding..."
    apt-ostree upgrade
    bootupctl update
    echo "Update completed successfully"
else
    echo "No updates available"
fi
EOF

chmod +x /usr/local/bin/particle-os-update

# Schedule automated updates
echo "0 2 * * * /usr/local/bin/particle-os-update" | crontab -
```

#### Manual Update Process
```bash
# 1. Check current status
apt-ostree status
ostree status

# 2. Check for updates
apt-ostree upgrade --dry-run

# 3. Perform update
apt-ostree upgrade

# 4. Update bootloader
bootupctl update

# 5. Verify update
apt-ostree status
ostree status

# 6. Reboot if needed
systemctl reboot
```

## Troubleshooting

### Common Issues

#### OSTree Errors
```bash
# Reset OSTree repository
ostree remote remove particle-os
ostree remote add particle-os https://git.raines.xyz/robojerk/particle-os/ostree.git

# Clear OSTree cache
ostree admin cleanup
```

#### Bootloader Issues
```bash
# Reset bootloader
bootupctl reset

# Reinstall bootloader
bootupctl install
```

#### Container Issues
```bash
# Reset container state
bootc reset

# Reinstall container
bootc install
```

### Recovery Procedures

#### System Recovery
```bash
# Boot into recovery mode
ostree admin rollback

# Reset to factory defaults
ostree admin reset

# Emergency shell access
systemctl emergency
```

#### Data Recovery
```bash
# Mount OSTree deployment
ostree admin mount deployment-id /mnt

# Access files
ls -la /mnt

# Copy data
cp -r /mnt/path/to/data /recovery/
```

## Security Considerations

### 1. Access Control
- Use SSH keys instead of passwords
- Implement firewall rules
- Restrict container privileges
- Monitor system access

### 2. Update Security
- Verify package signatures
- Use secure update channels
- Implement update rollback procedures
- Monitor for security updates

### 3. Container Security
- Run containers with minimal privileges
- Use read-only root filesystems
- Implement resource limits
- Monitor container behavior

## Performance Optimization

### 1. System Tuning
```bash
# Optimize OSTree performance
ostree config set core.min-free-space-percent 5

# Optimize bootloader
bootupctl config set update-check-interval 3600

# Optimize container performance
bootc config set max-concurrent-downloads 3
```

### 2. Resource Management
```bash
# Set memory limits
systemctl set-property user.slice MemoryMax=2G

# Set CPU limits
systemctl set-property user.slice CPUQuota=200%

# Monitor resource usage
systemd-cgtop
```

## Backup and Disaster Recovery

### 1. Backup Strategy
```bash
# Backup OSTree repository
ostree admin backup

# Backup system configuration
tar -czf /backup/config-$(date +%Y%m%d).tar.gz /etc

# Backup user data
tar -czf /backup/data-$(date +%Y%m%d).tar.gz /home
```

### 2. Recovery Procedures
```bash
# Restore from backup
ostree admin restore backup-id

# Restore configuration
tar -xzf /backup/config-YYYYMMDD.tar.gz -C /

# Restore user data
tar -xzf /backup/data-YYYYMMDD.tar.gz -C /
```

## Support and Community

### 1. Getting Help
- **Documentation**: Check this guide and project README
- **Issues**: Report issues on project repository
- **Community**: Join Particle-OS community discussions
- **Support**: Contact project maintainers

### 2. Contributing
- **Testing**: Test new features and report bugs
- **Documentation**: Improve guides and documentation
- **Development**: Contribute code and improvements
- **Feedback**: Provide feedback on features and usability

## Conclusion

Particle-OS is now ready for production deployment with all core components validated and working together. This guide provides comprehensive instructions for deploying, configuring, and maintaining Particle-OS in production environments.

**Key Benefits of Particle-OS:**
- **Atomic Updates**: Reliable, rollback-capable system updates
- **Container Integration**: Modern container deployment workflows
- **Debian Compatibility**: Full compatibility with Debian 13+ ecosystem
- **Clean Architecture**: Efficient inheritance from Debian Atomic foundation
- **Comprehensive Testing**: All components validated and working together

**Next Steps:**
1. Choose deployment variant based on your needs
2. Follow deployment instructions for your chosen method
3. Configure production settings and monitoring
4. Implement backup and recovery procedures
5. Join the Particle-OS community for support and updates

**Welcome to Particle-OS Production!** 🚀
