menios icon indicating copy to clipboard operation
menios copied to clipboard

Organize filesystem hierarchy following Unix FHS conventions

Open pbalduino opened this issue 3 months ago • 0 comments

Summary

Establish a proper filesystem hierarchy standard (FHS) for meniOS, separating user executables, system binaries, and other directories following Unix conventions.

Current State

  • All executables currently live in /bin
  • No distinction between user programs, system utilities, and administrative tools
  • As the OS grows, this flat structure becomes harder to maintain
  • Package installation and system organization will become problematic

Proposed Directory Structure

Essential System Binaries

  • /bin - Essential user command binaries (used by all users)

    • Examples: sh, cat, echo, ls, ps, kill
    • Available in single-user mode
    • Required for basic system operation
  • /sbin - Essential system binaries (system administration)

    • Examples: init, mount, fsck, reboot
    • Typically require root privileges
    • Critical for system boot and recovery

User Programs

  • /usr/bin - User command binaries (non-essential)

    • Examples: grep, xargs, env, utilities
    • Most user programs go here
    • Not needed for system boot/recovery
  • /usr/sbin - Non-essential system administration binaries

    • Examples: package managers, network daemons
    • System tools not needed for boot

Local Additions

  • /usr/local/bin - Locally compiled/installed user programs

    • User-compiled software
    • Third-party applications
    • TCC/GCC compiled programs
  • /usr/local/sbin - Locally installed system administration programs

Other Important Directories

  • /lib - Essential shared libraries and kernel modules
  • /usr/lib - Libraries for /usr/bin and /usr/sbin
  • /etc - System-wide configuration files
  • /home - User home directories
  • /tmp - Temporary files (already exists as tmpfs)
  • /var - Variable data (logs, caches, runtime data)
    • /var/log - Log files
    • /var/tmp - Temporary files that persist across reboots
    • /var/run or /run - Runtime variable data (PID files, sockets)
  • /opt - Optional/add-on application packages
  • /usr/share - Architecture-independent data
    • /usr/share/doc - Documentation
    • /usr/share/man - Manual pages
    • /usr/share/zoneinfo - Timezone database (for #299)

Migration Strategy

Phase 1: Create Directory Structure

  • Create all standard directories at boot
  • Update init to create the full hierarchy
  • Ensure proper permissions on each directory

Phase 2: Categorize Existing Binaries

Current /bin contents to categorize:

  • Essential /bin: cat, echo, env, true, false, ps, kill, sh (mosh)
  • Move to /usr/bin: grep (#234), xargs (#235), mem (#243)
  • Move to /sbin: init (if not already separate)
  • Move to /usr/sbin: System utilities as they're developed

Phase 3: Update Build System

  • Modify userland/Makefile to install to correct directories
  • Update INSTALL_DIR paths for each binary
  • Add installation rules for /usr/bin, /sbin, /usr/sbin

Phase 4: Update PATH Environment

  • Default PATH should include: /bin:/usr/bin:/usr/local/bin
  • Root PATH should add: /sbin:/usr/sbin:/usr/local/sbin
  • Update shell initialization in init (#180)

Phase 5: Documentation

  • Document the filesystem hierarchy in docs/architecture/
  • Update build documentation with installation paths
  • Create guidelines for where new programs should be installed

Benefits

  • Organization: Clear separation of concerns
  • Security: Distinguish privileged system tools
  • Standards: Follow Unix conventions for familiarity
  • Scalability: Easier to manage as OS grows
  • Package Management: Foundation for future package manager (#259)
  • Native Compilation: Clear installation paths for locally compiled software (#190, #191)

Implementation Considerations

  • Backward compatibility: maintain symlinks during transition?
  • Shell PATH updates needed
  • Build system changes required
  • Documentation updates

Dependencies

  • No hard dependencies, but benefits:
    • #180 (Environment seeding in init) ✅ - can update PATH
    • #259 (Package management database) - will use this structure
    • #190/#191 (TCC/binutils) - will install to /usr/local/bin

Priority

Medium - Important for long-term maintainability, but not blocking current work

Related Standards

  • Filesystem Hierarchy Standard (FHS 3.0)
  • POSIX directory structure
  • Common Unix conventions (BSD, Linux, etc.)

pbalduino avatar Oct 19 '25 16:10 pbalduino