bootc-docs/exec-in-host-mount-namespace/bootc-exec-in-host-mount-namespace-examples-troubleshooting.md
robojerk 526f1c1afd Initial commit: Comprehensive Debian bootc documentation
- Complete documentation for all bootc commands and subcommands
- Debian-specific adaptations and workarounds
- Manual installation methods to bypass bootc reliability issues
- Technical guides with Rust source code analysis
- Flowcharts and external command references
- Hidden command documentation (bootc internals, state, etc.)
- Composefs integration analysis
- Base image creation guides (with and without bootc binary)
- Management scripts and automation
- Comprehensive troubleshooting and examples
2025-09-15 14:02:28 -07:00

13 KiB

bootc exec-in-host-mount-namespace - Examples and Troubleshooting

Overview

This document provides practical examples and troubleshooting guidance for the bootc exec-in-host-mount-namespace system, covering common use cases, error scenarios, and debugging techniques.

Common Use Cases

1. Container Operations

Execute Commands in Host Namespace

#!/bin/bash
# Execute commands in host mount namespace

echo "=== Host Namespace Operations ==="
echo "Date: $(date)"
echo

# List host filesystem
echo "Listing host filesystem:"
bootc exec-in-host-mount-namespace ls /

# Check host system status
echo "Checking host system status:"
bootc exec-in-host-mount-namespace systemctl status

# View host processes
echo "Viewing host processes:"
bootc exec-in-host-mount-namespace ps aux

# Check host storage
echo "Checking host storage:"
bootc exec-in-host-mount-namespace df -h

Mount Operations in Host Namespace

#!/bin/bash
# Mount operations in host namespace

echo "=== Host Mount Operations ==="
echo "Date: $(date)"
echo

# Mount filesystem in host namespace
echo "Mounting filesystem in host namespace:"
bootc exec-in-host-mount-namespace mount /dev/sda1 /mnt

# Check mount points
echo "Checking mount points:"
bootc exec-in-host-mount-namespace mount | grep /mnt

# Unmount filesystem
echo "Unmounting filesystem:"
bootc exec-in-host-mount-namespace umount /mnt

2. Installation Support

Installation Operations

#!/bin/bash
# Installation operations using host namespace

echo "=== Installation Operations ==="
echo "Date: $(date)"
echo

# Create directories in host filesystem
echo "Creating directories in host filesystem:"
bootc exec-in-host-mount-namespace mkdir -p /var/lib/bootc
bootc exec-in-host-mount-namespace mkdir -p /etc/bootc

# Copy files to host filesystem
echo "Copying files to host filesystem:"
bootc exec-in-host-mount-namespace cp /source/config.toml /etc/bootc/

# Set permissions
echo "Setting permissions:"
bootc exec-in-host-mount-namespace chmod 644 /etc/bootc/config.toml
bootc exec-in-host-mount-namespace chown root:root /etc/bootc/config.toml

Bootloader Operations

#!/bin/bash
# Bootloader operations in host namespace

echo "=== Bootloader Operations ==="
echo "Date: $(date)"
echo

# Update GRUB configuration
echo "Updating GRUB configuration:"
bootc exec-in-host-mount-namespace grub-mkconfig -o /boot/grub/grub.cfg

# Install GRUB
echo "Installing GRUB:"
bootc exec-in-host-mount-namespace grub-install /dev/sda

# Update initramfs
echo "Updating initramfs:"
bootc exec-in-host-mount-namespace update-initramfs -u

3. Debugging and Maintenance

System Diagnostics

#!/bin/bash
# System diagnostics using host namespace

echo "=== System Diagnostics ==="
echo "Date: $(date)"
echo

# Check system information
echo "System information:"
bootc exec-in-host-mount-namespace uname -a
bootc exec-in-host-mount-namespace hostname
bootc exec-in-host-mount-namespace lscpu

# Check memory usage
echo "Memory usage:"
bootc exec-in-host-mount-namespace free -h

# Check disk usage
echo "Disk usage:"
bootc exec-in-host-mount-namespace df -h

# Check process information
echo "Process information:"
bootc exec-in-host-mount-namespace ps aux | head -20

Log Analysis

#!/bin/bash
# Log analysis using host namespace

echo "=== Log Analysis ==="
echo "Date: $(date)"
echo

# Check system logs
echo "System logs:"
bootc exec-in-host-mount-namespace journalctl --since "1 hour ago" | head -50

# Check specific service logs
echo "Service logs:"
bootc exec-in-host-mount-namespace journalctl -u bootc-* --since "1 hour ago"

# Check kernel logs
echo "Kernel logs:"
bootc exec-in-host-mount-namespace dmesg | tail -20

4. System Integration

Service Management

#!/bin/bash
# Service management using host namespace

echo "=== Service Management ==="
echo "Date: $(date)"
echo

# Check service status
echo "Service status:"
bootc exec-in-host-mount-namespace systemctl status bootc-*

# Start services
echo "Starting services:"
bootc exec-in-host-mount-namespace systemctl start bootc-*

# Enable services
echo "Enabling services:"
bootc exec-in-host-mount-namespace systemctl enable bootc-*

# Reload systemd
echo "Reloading systemd:"
bootc exec-in-host-mount-namespace systemctl daemon-reload

Network Operations

#!/bin/bash
# Network operations using host namespace

echo "=== Network Operations ==="
echo "Date: $(date)"
echo

# Check network interfaces
echo "Network interfaces:"
bootc exec-in-host-mount-namespace ip addr show

# Check network connections
echo "Network connections:"
bootc exec-in-host-mount-namespace netstat -tuln

# Test network connectivity
echo "Network connectivity:"
bootc exec-in-host-mount-namespace ping -c 3 8.8.8.8

Troubleshooting Guide

1. Common Error Scenarios

Missing Command Error

Error: Missing command

Cause: No command provided to execute

Solution:

# Provide a command
bootc exec-in-host-mount-namespace ls /

# Or use a shell
bootc exec-in-host-mount-namespace /bin/bash

Prevention:

# Check if command is provided
if [ $# -eq 0 ]; then
    echo "Error: No command provided"
    exit 1
fi

# Execute command
bootc exec-in-host-mount-namespace "$@"

Namespace Access Error

Error: open pid1 mountns: No such file or directory

Cause: Cannot access host mount namespace

Solution:

# Check if /proc/1/ns/mnt exists
ls -la /proc/1/ns/mnt

# Check if running as root
whoami

# Run as root
sudo bootc exec-in-host-mount-namespace ls /

Prevention:

# Check namespace availability
if [ ! -e /proc/1/ns/mnt ]; then
    echo "Error: Host mount namespace not available"
    exit 1
fi

# Check privileges
if [ "$EUID" -ne 0 ]; then
    echo "Error: Must run as root"
    exit 1
fi

setns Error

Error: setns: Operation not permitted

Cause: Insufficient privileges for namespace switching

Solution:

# Run as root
sudo bootc exec-in-host-mount-namespace ls /

# Check capabilities
getcap /usr/bin/bootc

# Add capabilities if needed
setcap cap_sys_admin+ep /usr/bin/bootc

Prevention:

# Check privileges
if [ "$EUID" -ne 0 ]; then
    echo "Error: Must run as root for namespace operations"
    exit 1
fi

Command Not Found Error

Error: exec: command not found

Cause: Command not found in host namespace

Solution:

# Use full path
bootc exec-in-host-mount-namespace /bin/ls /

# Check command availability
bootc exec-in-host-mount-namespace which ls

# Use absolute path
bootc exec-in-host-mount-namespace /usr/bin/ls /

Prevention:

# Check command availability first
if ! bootc exec-in-host-mount-namespace which "$1" > /dev/null 2>&1; then
    echo "Error: Command not found: $1"
    exit 1
fi

2. Debugging Techniques

Enable Debug Logging

# Set debug log level
export RUST_LOG=debug

# Run command with debug output
bootc exec-in-host-mount-namespace ls /

# Check debug logs
journalctl -u bootc-* --since "1 hour ago" | grep DEBUG

Verbose Output

# Enable verbose output
bootc exec-in-host-mount-namespace -v ls /

# Check verbose logs
journalctl -u bootc-* --since "1 hour ago" | grep -v INFO

System Information

# Gather system information
uname -a
lsb_release -a
systemctl --version
bootc --version

# Check system configuration
cat /etc/os-release
cat /proc/version
cat /proc/cpuinfo | head -20

Namespace Diagnostics

# Check namespace information
ls -la /proc/1/ns/
ls -la /proc/self/ns/

# Check namespace differences
diff /proc/1/ns/mnt /proc/self/ns/mnt

# Check namespace capabilities
cat /proc/self/status | grep Ns

3. Recovery Procedures

Namespace Recovery

#!/bin/bash
# Namespace recovery script

echo "=== Namespace Recovery ==="
echo "Date: $(date)"
echo

# Check namespace availability
echo "Checking namespace availability..."
if [ ! -e /proc/1/ns/mnt ]; then
    echo "ERROR: Host mount namespace not available"
    exit 1
fi

# Check privileges
echo "Checking privileges..."
if [ "$EUID" -ne 0 ]; then
    echo "ERROR: Must run as root"
    exit 1
fi

# Test namespace access
echo "Testing namespace access..."
if ! bootc exec-in-host-mount-namespace ls / > /dev/null 2>&1; then
    echo "ERROR: Cannot access host namespace"
    exit 1
fi

echo "Namespace recovery successful"

Command Recovery

#!/bin/bash
# Command recovery script

echo "=== Command Recovery ==="
echo "Date: $(date)"
echo

# Check command availability
echo "Checking command availability..."
if ! bootc exec-in-host-mount-namespace which "$1" > /dev/null 2>&1; then
    echo "ERROR: Command not found: $1"
    echo "Available commands:"
    bootc exec-in-host-mount-namespace ls /bin
    exit 1
fi

# Test command execution
echo "Testing command execution..."
if ! bootc exec-in-host-mount-namespace "$1" --help > /dev/null 2>&1; then
    echo "WARNING: Command may not work as expected"
fi

echo "Command recovery successful"

4. Performance Analysis

Execution Performance

#!/bin/bash
# Execution performance analysis

echo "=== Execution Performance Analysis ==="
echo "Date: $(date)"
echo

# Time command execution
echo "Timing command execution..."
time bootc exec-in-host-mount-namespace ls /

# Check resource usage
echo "Resource usage:"
ps aux | grep bootc | awk '{sum+=$6} END {print sum/1024 " MB"}'

# Check system load
echo "System load:"
uptime

Namespace Performance

#!/bin/bash
# Namespace performance analysis

echo "=== Namespace Performance Analysis ==="
echo "Date: $(date)"
echo

# Time namespace operations
echo "Timing namespace operations..."
time bootc exec-in-host-mount-namespace uname -a

# Check namespace overhead
echo "Namespace overhead:"
time bootc exec-in-host-mount-namespace /bin/true
time /bin/true

# Check system performance
echo "System performance:"
bootc exec-in-host-mount-namespace top -bn1 | head -20

5. Monitoring and Alerting

Health Check Script

#!/bin/bash
# Health check script

HEALTH_STATUS=0

echo "=== Exec-in-Host-Mount-Namespace Health Check ==="
echo "Date: $(date)"
echo

# Check namespace availability
echo "Checking namespace availability..."
if [ ! -e /proc/1/ns/mnt ]; then
    echo "ERROR: Host mount namespace not available"
    HEALTH_STATUS=1
fi

# Check privileges
echo "Checking privileges..."
if [ "$EUID" -ne 0 ]; then
    echo "ERROR: Must run as root"
    HEALTH_STATUS=1
fi

# Test namespace access
echo "Testing namespace access..."
if ! bootc exec-in-host-mount-namespace ls / > /dev/null 2>&1; then
    echo "ERROR: Cannot access host namespace"
    HEALTH_STATUS=1
fi

# Test command execution
echo "Testing command execution..."
if ! bootc exec-in-host-mount-namespace /bin/true > /dev/null 2>&1; then
    echo "ERROR: Command execution failed"
    HEALTH_STATUS=1
fi

# Report health status
if [ $HEALTH_STATUS -eq 0 ]; then
    echo "Health check passed"
else
    echo "Health check failed"
fi

exit $HEALTH_STATUS

Alerting Script

#!/bin/bash
# Alerting script

# Send alert to monitoring system
send_alert() {
    local severity=$1
    local message=$2
    
    curl -X POST "https://monitoring.example.com/alerts" \
        -H "Content-Type: application/json" \
        -d "{
            \"service\": \"bootc-exec-in-host-mount-namespace\",
            \"severity\": \"$severity\",
            \"message\": \"$message\",
            \"timestamp\": \"$(date -Iseconds)\"
        }"
}

# Check system health
if ! /usr/local/bin/bootc-exec-in-host-mount-namespace-health-check.sh; then
    send_alert "critical" "Exec-in-host-mount-namespace system health check failed"
fi

# Check namespace availability
if [ ! -e /proc/1/ns/mnt ]; then
    send_alert "critical" "Host mount namespace not available"
fi

# Check command execution
if ! bootc exec-in-host-mount-namespace /bin/true > /dev/null 2>&1; then
    send_alert "warning" "Command execution in host namespace failed"
fi

Best Practices

1. Usage Guidelines

  • Internal Use: This is an internal command, not for direct user use
  • Container Context: Use within container environments
  • Host Access: Use when host mount namespace access is needed
  • Debugging: Use for debugging and maintenance operations

2. Security Considerations

  • Privilege Requirements: Ensure appropriate privileges
  • Namespace Access: Verify namespace access permissions
  • Command Validation: Validate commands before execution
  • Error Handling: Implement proper error handling

3. Performance Optimization

  • Minimal Overhead: Use only when necessary
  • Efficient Execution: Use direct system calls
  • Resource Management: Manage resources appropriately
  • Error Recovery: Implement proper error recovery

This comprehensive examples and troubleshooting guide provides practical solutions for common issues and advanced debugging techniques for the bootc exec-in-host-mount-namespace system.