mirror of
https://github.com/johndoe6345789/SparkOS.git
synced 2026-04-24 13:34:56 +00:00
Merge pull request #2 from johndoe6345789/copilot/update-docker-image-to-busybox
Replace bash with busybox for minimal image footprint
This commit is contained in:
@@ -26,7 +26,7 @@ Follows the Filesystem Hierarchy Standard (FHS):
|
||||
|
||||
```
|
||||
/
|
||||
├── bin/ Essential user binaries (bash, ls, cp, etc.)
|
||||
├── bin/ Essential user binaries (busybox with symlinks)
|
||||
├── sbin/ System binaries (init, mount, etc.)
|
||||
├── etc/ System configuration files
|
||||
├── proc/ Kernel process information (virtual)
|
||||
@@ -71,7 +71,7 @@ Init System (/sbin/init) [PID 1]
|
||||
↓
|
||||
Mount filesystems
|
||||
↓
|
||||
Spawn bash shell
|
||||
Spawn busybox sh shell
|
||||
↓
|
||||
User interaction
|
||||
```
|
||||
@@ -91,11 +91,12 @@ User interaction
|
||||
- **Portability**: Works on any Linux system
|
||||
- **Reliability**: No missing library issues
|
||||
|
||||
### Why Bash?
|
||||
### Why Busybox?
|
||||
|
||||
- **Familiar**: Most users know bash
|
||||
- **Powerful**: Full scripting capabilities
|
||||
- **Standard**: Available on virtually all Linux systems
|
||||
- **Minimal**: Single binary provides dozens of utilities
|
||||
- **Small footprint**: Typically <1MB for full feature set
|
||||
- **Efficient**: Less memory and storage overhead than full GNU coreutils
|
||||
- **Standard**: De facto standard for embedded Linux systems
|
||||
|
||||
## Future Architecture
|
||||
|
||||
@@ -132,7 +133,7 @@ User interaction
|
||||
## Performance
|
||||
|
||||
- Fast boot time (seconds, not minutes)
|
||||
- Low memory footprint (~100MB base system)
|
||||
- Low memory footprint (~50MB base system with busybox)
|
||||
- No unnecessary background services
|
||||
- Efficient init system
|
||||
|
||||
|
||||
@@ -39,7 +39,8 @@ SparkOS aims to be:
|
||||
- Comment complex logic
|
||||
|
||||
- **Shell Scripts**: Follow Google Shell Style Guide
|
||||
- Use `#!/bin/bash` shebang
|
||||
- For runtime scripts (inside rootfs): Use `#!/bin/sh` for POSIX-compliant scripts (busybox compatibility)
|
||||
- For build scripts (host system): Can use `#!/bin/bash` when bash-specific features are needed
|
||||
- Quote variables
|
||||
- Use meaningful variable names
|
||||
|
||||
|
||||
24
README.md
24
README.md
@@ -2,7 +2,7 @@
|
||||
|
||||
A minimal Linux distribution designed for simplicity and portability. SparkOS features:
|
||||
|
||||
- **Minimal footprint**: Barebones Linux system with bash shell
|
||||
- **Minimal footprint**: Barebones Linux system with busybox shell
|
||||
- **Portable**: dd-able disk image for USB flash drives
|
||||
- **Custom init**: Lightweight C init system
|
||||
- **Future-ready**: Designed to support Qt6/QML GUI and Wayland
|
||||
@@ -12,7 +12,7 @@ A minimal Linux distribution designed for simplicity and portability. SparkOS fe
|
||||
|
||||
The current MVP provides:
|
||||
- ✅ Custom init system written in C
|
||||
- ✅ Working bash shell environment
|
||||
- ✅ Working busybox shell environment
|
||||
- ✅ dd-able AMD64 image creation scripts
|
||||
- ✅ Minimal root filesystem structure
|
||||
- ✅ Build system (Makefile)
|
||||
@@ -99,7 +99,7 @@ SparkOS/
|
||||
|
||||
SparkOS uses a custom init system (`/sbin/init`) that:
|
||||
- Mounts essential filesystems (proc, sys, dev, tmp)
|
||||
- Spawns a bash login shell
|
||||
- Spawns a busybox sh login shell
|
||||
- Handles process reaping
|
||||
- Respawns shell on exit
|
||||
|
||||
@@ -138,14 +138,18 @@ make help
|
||||
To create a fully functional system, you need to populate the rootfs with binaries:
|
||||
|
||||
```bash
|
||||
# Example: Add bash (statically linked is best)
|
||||
cp /bin/bash rootfs/bin/
|
||||
# Example: Add busybox (statically linked is best)
|
||||
cp /bin/busybox rootfs/bin/
|
||||
|
||||
# Example: Add essential utilities
|
||||
cp /bin/{ls,cat,mkdir,rm,cp,mount} rootfs/bin/
|
||||
# Create busybox symlinks for common utilities
|
||||
cd rootfs/bin
|
||||
for cmd in sh ls cat mkdir rm cp mount umount chmod chown ln; do
|
||||
ln -sf busybox $cmd
|
||||
done
|
||||
cd ../..
|
||||
|
||||
# Copy required libraries if not static
|
||||
ldd rootfs/bin/bash # Check dependencies
|
||||
# If using dynamically linked busybox, copy required libraries
|
||||
ldd rootfs/bin/busybox # Check dependencies
|
||||
# Copy libraries to rootfs/lib or rootfs/lib64
|
||||
```
|
||||
|
||||
@@ -184,7 +188,7 @@ To create a fully bootable system, you'll also need:
|
||||
- Bootloader installation (handled by scripts)
|
||||
A single binary on top of Linux / Wayland that manages the OS, C++ CLI and Qt6/QML Full screen GUI. Android like design but more desktop orientated. A distribution that can be dd'ed to a USB flash drive. Root elevation powered by sudo. This project will need to set up a barebones distro (doesn't really need to be based on another, to keep things clean)
|
||||
|
||||
MVP is just a to get to a bash prompt with sudo support. Install minimum on system, maybe even use busybox.
|
||||
MVP is just a to get to a shell prompt with sudo support. Install minimum on system using busybox for minimal footprint.
|
||||
|
||||
We should try to build the system with github actions if possible.
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ BOOTLOADER=syslinux
|
||||
INIT=sparkos-init
|
||||
|
||||
# Default shell
|
||||
SHELL=/bin/bash
|
||||
SHELL=/bin/sh
|
||||
|
||||
# Compiler flags
|
||||
CFLAGS=-Wall -O2 -static
|
||||
|
||||
@@ -14,5 +14,5 @@ Directory Structure:
|
||||
/home - User home directories
|
||||
|
||||
Note: This is a minimal system. You'll need to populate /bin and /usr/bin
|
||||
with actual binaries (bash, coreutils, etc.) from a proper Linux system
|
||||
with actual binaries (busybox, etc.) from a proper Linux system
|
||||
or by cross-compiling.
|
||||
|
||||
@@ -1 +1 @@
|
||||
root:x:0:0:root:/root:/bin/bash
|
||||
root:x:0:0:root:/root:/bin/sh
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
# SparkOS Root Bash Configuration
|
||||
# SparkOS Root Shell Configuration
|
||||
|
||||
# Set prompt
|
||||
PS1='SparkOS:\w# '
|
||||
|
||||
# Aliases
|
||||
alias ls='ls --color=auto'
|
||||
alias ll='ls -lah'
|
||||
alias ..='cd ..'
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
# Quick build script for SparkOS development
|
||||
# Note: This script runs on the host system and uses bash for ${BASH_SOURCE}
|
||||
# The target system uses busybox sh instead.
|
||||
|
||||
set -e
|
||||
|
||||
@@ -28,9 +30,10 @@ echo ""
|
||||
echo "Build complete!"
|
||||
echo ""
|
||||
echo "Next steps to create a full bootable system:"
|
||||
echo " 1. Populate rootfs/bin with bash and essential utilities"
|
||||
echo " (cp /bin/bash rootfs/bin/, etc.)"
|
||||
echo " 2. Copy required libraries to rootfs/usr/lib and rootfs/lib"
|
||||
echo " 1. Copy busybox to rootfs/bin/"
|
||||
echo " (cp /bin/busybox rootfs/bin/)"
|
||||
echo " 2. Create symlinks in rootfs/bin for common utilities"
|
||||
echo " (cd rootfs/bin && for cmd in sh ls cat mkdir rm cp mount; do ln -sf busybox \$cmd; done)"
|
||||
echo " 3. Add a Linux kernel to rootfs/boot/vmlinuz"
|
||||
echo " 4. Run: sudo make image"
|
||||
echo ""
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#!/bin/bash
|
||||
# SparkOS Image Creation Script
|
||||
# Creates a bootable dd-able disk image
|
||||
# Note: This script runs on the host system and uses bash for ${BASH_SOURCE}
|
||||
# The target system uses busybox sh instead.
|
||||
|
||||
set -e
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#!/bin/bash
|
||||
# SparkOS Setup Script
|
||||
# Sets up a minimal rootfs with bash and essential utilities
|
||||
# Sets up a minimal rootfs with busybox and essential utilities
|
||||
# Note: This script runs on the host system and uses bash for ${BASH_SOURCE}
|
||||
# The target system uses busybox sh instead.
|
||||
|
||||
set -e
|
||||
|
||||
@@ -37,7 +39,7 @@ EOF
|
||||
|
||||
# /etc/passwd
|
||||
cat > "$ROOTFS_DIR/etc/passwd" << 'EOF'
|
||||
root:x:0:0:root:/root:/bin/bash
|
||||
root:x:0:0:root:/root:/bin/sh
|
||||
EOF
|
||||
|
||||
# /etc/group
|
||||
@@ -69,15 +71,14 @@ echo "Type 'help' for available commands"
|
||||
echo ""
|
||||
EOF
|
||||
|
||||
# Create .bashrc for root
|
||||
cat > "$ROOTFS_DIR/root/.bashrc" << 'EOF'
|
||||
# SparkOS Root Bash Configuration
|
||||
# Create .profile for root (busybox uses .profile instead of .bashrc)
|
||||
cat > "$ROOTFS_DIR/root/.profile" << 'EOF'
|
||||
# SparkOS Root Shell Configuration
|
||||
|
||||
# Set prompt
|
||||
PS1='SparkOS:\w# '
|
||||
|
||||
# Aliases
|
||||
alias ls='ls --color=auto'
|
||||
alias ll='ls -lah'
|
||||
alias ..='cd ..'
|
||||
|
||||
@@ -131,7 +132,7 @@ Directory Structure:
|
||||
/home - User home directories
|
||||
|
||||
Note: This is a minimal system. You'll need to populate /bin and /usr/bin
|
||||
with actual binaries (bash, coreutils, etc.) from a proper Linux system
|
||||
with actual binaries (busybox, etc.) from a proper Linux system
|
||||
or by cross-compiling.
|
||||
EOF
|
||||
|
||||
@@ -141,8 +142,8 @@ echo ""
|
||||
echo "Next steps:"
|
||||
echo " 1. Build init: make init"
|
||||
echo " 2. Install init: make install"
|
||||
echo " 3. Copy bash and essential binaries to rootfs/bin/"
|
||||
echo " 3. Copy busybox to rootfs/bin/ and create symlinks"
|
||||
echo " 4. Create bootable image: sudo make image"
|
||||
echo ""
|
||||
echo "Note: You'll need to populate the rootfs with actual binaries"
|
||||
echo "Note: You'll need to populate the rootfs with busybox binary"
|
||||
echo " before creating a bootable image."
|
||||
|
||||
@@ -29,7 +29,7 @@ static void spawn_shell() {
|
||||
|
||||
if (pid == 0) {
|
||||
// Child process - exec shell
|
||||
char *argv[] = {"/bin/bash", "--login", NULL};
|
||||
char *argv[] = {"/bin/sh", "-l", NULL};
|
||||
char *envp[] = {
|
||||
"HOME=/root",
|
||||
"PATH=/bin:/sbin:/usr/bin:/usr/sbin",
|
||||
@@ -38,11 +38,7 @@ static void spawn_shell() {
|
||||
NULL
|
||||
};
|
||||
|
||||
execve("/bin/bash", argv, envp);
|
||||
|
||||
// If bash fails, try sh
|
||||
char *sh_argv[] = {"/bin/sh", NULL};
|
||||
execve("/bin/sh", sh_argv, envp);
|
||||
execve("/bin/sh", argv, envp);
|
||||
|
||||
perror("failed to exec shell");
|
||||
exit(1);
|
||||
|
||||
Reference in New Issue
Block a user