# Storage Architecture

**Strategy:** 256GB onboard eMMC for boot/root/data. SD card and M.2 for expansion.

---

## Design Principles

1. **Simplicity:** eMMC boots out of the box, faster and more reliable than SD
2. **Speed:** eMMC ~300 MB/s read — comparable to a SATA SSD
3. **Capacity:** 256GB onboard is plenty for OS + apps + projects + media
4. **Flexibility:** MicroSD and M.2 slots available for expansion
5. **Cost:** Included with SBC — no separate purchase needed

---

## Layer 1: Boot/Root (eMMC)

The Orange Pi 3B boots from its onboard 256GB eMMC by default. This is the primary storage:

### eMMC Performance

| Attribute | Value |
|-----------|-------|
| Capacity | 256GB |
| Interface | eMMC 5.1 |
| Sequential read | ~300 MB/s |
| Sequential write | ~200 MB/s |
| Reliability | Significantly better than SD cards |

### Partition Layout (Suggested)

```
/dev/mmcblk1 (eMMC, 256GB)
├── /dev/mmcblk1p1  → /boot (fat32, ~500MB)
├── /dev/mmcblk1p2  → / (ext4, ~80GB)
├── /dev/mmcblk1p3  → /home (ext4, ~170GB)
└── (remaining for swap or data)
```

Or simpler:

```
/dev/mmcblk1p1  → /boot (fat32, ~500MB)
/dev/mmcblk1p2  → / (ext4, all remaining)
    /home       → subdirectory, not separate partition
```

256GB is large enough that separate partitions are optional. A single root partition with everything under it works fine.

### Boot Configuration

Default OPi3B boots from eMMC when populated. No configuration needed.

---

## Layer 2: Expansion (MicroSD + M.2)

### MicroSD

| Attribute | Value |
|-----------|-------|
| Slot | Standard push-push |
| Max capacity | Up to 512GB |
| Use | Backup, media library, test OS images |

No need for endurance-rated card — the SD slot is now secondary storage, not primary boot.

### M.2 M-key

| Interface | Speed | Notes |
|-----------|-------|-------|
| PCIe 2.0 x1 | ~300 MB/s | Slightly slower than eMMC |
| SATA III | ~550 MB/s | Faster than eMMC (if SATA SSD) |

Can add NVMe or SATA SSD for bulk storage if 256GB eMMC fills up. M.2 slot shares bandwidth with USB 3.0 — both use the same PCIe controller.

---

## Layer 3: Data Storage (USB)

Optional external storage for:
- Large media libraries
- Project archives
- System backups

### Options

| Option | Speed | Cost | Notes |
|--------|-------|------|-------|
| USB 3.0 SATA enclosure | ~400 MB/s | $10-15 | Reuse 2.5" drives |
| USB 3.0 NVMe enclosure | ~400 MB/s | $8-15 | Compact |
| USB flash drive (fast) | 200-400 MB/s | $15-25 | Kingston, Samsung BAR |

### Mount Strategy

```bash
# /etc/fstab (optional USB storage)
UUID=<ssd-uuid> /mnt/data    ext4    defaults,noatime    0  2
/mnt/data/projects /home/jez/projects  none    bind    0  0
/mnt/data/media   /home/jez/media     none    bind    0  0
```

---

## Storage Layout

```
┌─────────────────────────────────────┐
│  eMMC (/dev/mmcblk1)               │
│  256GB onboard                      │
│  ├── /boot     (fat32, 500MB)      │
│  ├── /         (ext4, ~80GB)       │
│  └── /home     (ext4, ~175GB)      │
│      OS + apps + projects + media  │
└─────────────────────────────────────┘

┌─────────────────────────────────────┐
│  MicroSD (/dev/mmcblk0)            │
│  Optional expansion                 │
│  ├── OS images / boot tests         │
│  └── Media library / backups        │
└─────────────────────────────────────┘

┌─────────────────────────────────────┐
│  USB SSD (/dev/sda)                │
│  Optional — only if eMMC fills up   │
│  ├── /mnt/data/projects             │
│  ├── /mnt/data/media                │
│  └── /mnt/data/backup               │
└─────────────────────────────────────┘
```

---

## Backup Strategy

### eMMC Imaging

```bash
# Backup entire eMMC to USB drive
sudo dd if=/dev/mmcblk1 of=/mnt/data/cyberdeck-emmc-backup.img bs=4M status=progress

# Restore
sudo dd if=/mnt/data/cyberdeck-emmc-backup.img of=/dev/mmcblk1 bs=4M status=progress
```

### Data Backup

- Timeshift for system snapshots
- rsync to external drive
- Cloud sync for critical files

---

## Performance Expectations

| Operation | eMMC | MicroSD | USB SSD |
|-----------|------|---------|---------|
| Boot time | ~5-8s | ~10-15s | ~5-8s |
| App launch | 0.5-1s | 1-3s | 0.5-1s |
| File read (1GB) | ~3-4s | ~40-90s | ~3-5s |
| Reliability | Excellent | Poor (wear) | Good |

eMMC is the clear winner for boot and everyday use. SD card and USB storage are optional extras.

---

## Cost Summary

| Item | Low | High | Status |
|------|-----|------|--------|
| 256GB eMMC | $0 | $0 | **Included with SBC** |
| MicroSD (optional) | $0 | $15 | Only if needed |
| USB enclosure (optional) | $0 | $15 | Only if eMMC fills up |
| **Total** | **$0** | **$30** | |