# Gitea 110  Server Hard Disk Expansion Guide

## Current Situation
- **Server**: 192.168.0.110 (Gateway)
- **Current Disk**: 1TB (/dev/sda) - 100% Full
- **Filesystem**: LVM (Logical Volume Manager)
- **Root Volume**: `/dev/mapper/ubuntu--vg-ubuntu--lv` (998G)

## Immediate Actions Required

### 1. Emergency Space Cleanup (Temporary Fix)

#### Clean Harbor Logs (263MB)
```bash
# Connect to server
ssh wooo@192.168.0.110

# Clean Harbor logs (requires sudo)
sudo truncate -s 0 /var/log/harbor/proxy.log
sudo truncate -s 0 /var/log/harbor/portal.log

# Clean system logs older than 7 days
sudo find /var/log -name "*.log" -mtime +7 -exec truncate -s 0 {} \;
sudo journalctl --vacuum-time=7d

# Check freed space
df -h /
```

#### Clean Docker Resources
```bash
# Clean Docker unused resources
docker system prune -a -f
docker volume prune -f

# Clean old containers and images
docker container prune -f
docker image prune -a -f
```

### 2. Permanent Solution: Disk Expansion

#### Option A: Expand Existing Disk (Virtual Environment)
If this is a VM, you can expand the existing virtual disk:

1. **Shutdown VM and Expand Disk** (in hypervisor):
   - Expand `/dev/sda` from 1TB to 2TB
   - Start VM

2. **Expand Partition**:
```bash
# Use fdisk to expand partition sda3
sudo fdisk /dev/sda
# Delete partition 3, recreate with larger size
# Use same start sector, extend to end

# Reboot or reload partition table
sudo partprobe /dev/sda
```

3. **Expand LVM**:
```bash
# Expand physical volume
sudo pvresize /dev/sda3

# Expand logical volume
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

# Resize filesystem
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
```

#### Option B: Add New Disk (Physical/Cloud)
Add a new disk and extend LVM:

1. **Add New Disk**:
   - Physical: Install new HDD/SSD
   - Cloud: Attach new volume
   - VM: Add new virtual disk

2. **Initialize New Disk** (assuming new disk is `/dev/sdb`):
```bash
# Create partition
sudo fdisk /dev/sdb
# Create primary partition using entire disk
# Set type to Linux LVM (8e)

# Create physical volume
sudo pvcreate /dev/sdb1

# Add to volume group
sudo vgextend ubuntu-vg /dev/sdb1

# Extend logical volume
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

# Resize filesystem
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
```

### 3. Verification Steps

After expansion:
```bash
# Check disk space
df -h /

# Check LVM status
sudo pvs
sudo lvs
sudo vgs

# Verify filesystem
sudo fsck -f /dev/mapper/ubuntu--vg-ubuntu--lv
```

## Recommendations

### Short-term (Today)
1. **Clean Harbor logs** - Free up ~263MB immediately
2. **Clean Docker resources** - Free up additional space
3. **Test Git push** after cleanup

### Medium-term (This Week)
1. **Expand disk to 2TB** - Recommended minimum
2. **Set up log rotation** - Prevent future fill-ups
3. **Monitor disk usage** - Set up alerts at 80%

### Long-term (Next Month)
1. **Implement automated cleanup scripts**
2. **Move large data to external storage**
3. **Consider separate storage for Docker/Gitea data**

## Emergency Commands

If Git push still fails after cleanup:
```bash
# Force cleanup and restart services
sudo systemctl restart gitea
sudo docker system prune -a -f --volumes

# Check Gitea status
sudo systemctl status gitea
```

## Monitoring Setup

Add disk monitoring to prevent future issues:
```bash
# Create disk monitor script
cat > /home/wooo/disk_monitor.sh << 'EOF'
#!/bin/bash
USAGE=$(df / | tail -1 | awk '{print $5}' | sed 's/%//')
if [ $USAGE -gt 80 ]; then
    echo "WARNING: Disk usage is ${USAGE}%" | logger -t disk_monitor
    # Send alert to Telegram
    curl -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \
         -d "chat_id=$TELEGRAM_CHAT_ID&text=Disk usage on 110 is ${USAGE}%"
fi
EOF

chmod +x /home/wooo/disk_monitor.sh
echo "0 */6 * * * /home/wooo/disk_monitor.sh" | crontab -
```

## Contact Information

For hardware/disk expansion:
- **Virtual Environment**: Contact VM admin
- **Physical Server**: Contact datacenter admin
- **Cloud Environment**: Use cloud provider console

## Safety Notes

- Always backup data before disk operations
- Test commands in non-production environment first
- Have rollback plan ready
- Monitor system during expansion process
