25
.easyqemu.conf
Archivo normal
25
.easyqemu.conf
Archivo normal
@@ -0,0 +1,25 @@
|
||||
# EasyQEMU Configuration File
|
||||
# This file contains default settings for EasyQEMU
|
||||
|
||||
# Home directory for EasyQEMU data
|
||||
EASYQEMU_HOME="$HOME/.easyqemu"
|
||||
|
||||
# Default VM settings
|
||||
DEFAULT_MEMORY="2048"
|
||||
DEFAULT_CPUS="2"
|
||||
DEFAULT_DISK_SIZE="20G"
|
||||
DEFAULT_DISK_FORMAT="qcow2"
|
||||
DEFAULT_NETWORK="user"
|
||||
DEFAULT_DISPLAY="gtk"
|
||||
DEFAULT_BOOT="cd"
|
||||
|
||||
# QEMU binary paths (auto-detected if not set)
|
||||
QEMU_SYSTEM_X86_64=""
|
||||
QEMU_IMG=""
|
||||
|
||||
# Enable KVM acceleration by default
|
||||
ENABLE_KVM="true"
|
||||
|
||||
# Logging
|
||||
LOG_LEVEL="info" # debug, info, warning, error
|
||||
LOG_FILE="$EASYQEMU_HOME/easyqemu.log"
|
||||
42
.gitignore
vendido
Archivo normal
42
.gitignore
vendido
Archivo normal
@@ -0,0 +1,42 @@
|
||||
# EasyQEMU .gitignore
|
||||
|
||||
# EasyQEMU data directory
|
||||
.easyqemu/
|
||||
|
||||
# Test files
|
||||
test_*.qcow2
|
||||
test_*.raw
|
||||
test_*.vmdk
|
||||
test_*.vdi
|
||||
test_*.vhdx
|
||||
*.iso
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
# Temporary files
|
||||
*.tmp
|
||||
*.bak
|
||||
*~
|
||||
|
||||
# OS files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
desktop.ini
|
||||
|
||||
# Editor files
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# Compiled files
|
||||
*.o
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Archives
|
||||
*.tar.gz
|
||||
*.zip
|
||||
*.7z
|
||||
82
CHANGELOG.md
Archivo normal
82
CHANGELOG.md
Archivo normal
@@ -0,0 +1,82 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to EasyQEMU will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [1.0.0] - 2026-01-07
|
||||
|
||||
### Added
|
||||
- Initial release of EasyQEMU
|
||||
- VM Management:
|
||||
- Create, list, start, delete, modify virtual machines
|
||||
- Automatic disk creation
|
||||
- Support for custom VM configurations (memory, CPUs, disk size)
|
||||
- ISO/CDROM mounting support
|
||||
- Multiple network modes (user, bridge, tap)
|
||||
- Multiple display options (gtk, sdl, vnc, none)
|
||||
- Boot device selection (CD, HDD)
|
||||
- Volume Management:
|
||||
- Create volumes in multiple formats (qcow2, raw, vmdk, vdi, vhdx)
|
||||
- List volumes with size information
|
||||
- Convert between formats
|
||||
- Import/export volumes
|
||||
- Volume information display
|
||||
- Snapshot Management:
|
||||
- Create snapshots of VM disks
|
||||
- List all snapshots for a VM
|
||||
- Apply/restore snapshots
|
||||
- Delete snapshots
|
||||
- Repository System:
|
||||
- Save VM configurations and disks to repository
|
||||
- Load VMs from repository (create clones)
|
||||
- List repository entries
|
||||
- Delete repository entries
|
||||
- Docker-like VM management
|
||||
- Features:
|
||||
- Colored terminal output
|
||||
- JSON configuration storage
|
||||
- Automatic KVM acceleration
|
||||
- Comprehensive error handling
|
||||
- Help system
|
||||
- Documentation:
|
||||
- Comprehensive README with examples
|
||||
- Installation script
|
||||
- Usage examples
|
||||
- Contributing guidelines
|
||||
- MIT License
|
||||
|
||||
### Technical Details
|
||||
- Written in Bash 4.0+
|
||||
- Uses QEMU/KVM for virtualization
|
||||
- Stores data in ~/.easyqemu directory
|
||||
- JSON-based configuration files
|
||||
- Modular function design
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Planned
|
||||
- Windows VM support with UEFI boot
|
||||
- Web-based UI
|
||||
- Remote VM management
|
||||
- Cloud-init integration
|
||||
- Network configuration wizard
|
||||
- Resource monitoring
|
||||
- Automated backups
|
||||
- VM templates library
|
||||
- Progress bars for long operations
|
||||
- Better error messages and recovery
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
### Version Numbering
|
||||
- MAJOR: Incompatible API changes
|
||||
- MINOR: New functionality (backwards-compatible)
|
||||
- PATCH: Bug fixes (backwards-compatible)
|
||||
|
||||
### Support
|
||||
For issues, feature requests, or questions, please visit:
|
||||
https://github.com/yourusername/easyqemu/issues
|
||||
244
CONTRIBUTING.md
Archivo normal
244
CONTRIBUTING.md
Archivo normal
@@ -0,0 +1,244 @@
|
||||
# Contributing to EasyQEMU
|
||||
|
||||
Thank you for your interest in contributing to EasyQEMU! This document provides guidelines for contributing to the project.
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
- Be respectful and inclusive
|
||||
- Welcome newcomers and help them get started
|
||||
- Focus on constructive feedback
|
||||
- Respect differing viewpoints and experiences
|
||||
|
||||
## How to Contribute
|
||||
|
||||
### Reporting Bugs
|
||||
|
||||
If you find a bug, please create an issue with:
|
||||
|
||||
1. **Description**: Clear description of the bug
|
||||
2. **Steps to Reproduce**: Detailed steps to reproduce the issue
|
||||
3. **Expected Behavior**: What you expected to happen
|
||||
4. **Actual Behavior**: What actually happened
|
||||
5. **Environment**:
|
||||
- OS and version
|
||||
- QEMU version (`qemu-system-x86_64 --version`)
|
||||
- EasyQEMU version (`easyqemu version`)
|
||||
6. **Logs**: Relevant error messages or logs
|
||||
|
||||
### Suggesting Features
|
||||
|
||||
Feature suggestions are welcome! Please create an issue with:
|
||||
|
||||
1. **Use Case**: Why is this feature needed?
|
||||
2. **Proposed Solution**: How should it work?
|
||||
3. **Alternatives**: What alternatives have you considered?
|
||||
4. **Examples**: Example commands or usage
|
||||
|
||||
### Pull Requests
|
||||
|
||||
1. **Fork the Repository**
|
||||
```bash
|
||||
git clone https://github.com/yourusername/easyqemu.git
|
||||
cd easyqemu
|
||||
```
|
||||
|
||||
2. **Create a Branch**
|
||||
```bash
|
||||
git checkout -b feature/your-feature-name
|
||||
# or
|
||||
git checkout -b fix/your-bug-fix
|
||||
```
|
||||
|
||||
3. **Make Your Changes**
|
||||
- Follow the coding style (see below)
|
||||
- Test your changes thoroughly
|
||||
- Update documentation if needed
|
||||
|
||||
4. **Test Your Changes**
|
||||
```bash
|
||||
# Test basic functionality
|
||||
./easyqemu vm create --name test
|
||||
./easyqemu vm list
|
||||
./easyqemu vm delete test -f
|
||||
|
||||
# Test new features
|
||||
# Add specific tests for your changes
|
||||
```
|
||||
|
||||
5. **Commit Your Changes**
|
||||
```bash
|
||||
git add .
|
||||
git commit -m "feat: add new feature" # or "fix: resolve bug"
|
||||
```
|
||||
|
||||
Commit message format:
|
||||
- `feat:` for new features
|
||||
- `fix:` for bug fixes
|
||||
- `docs:` for documentation changes
|
||||
- `style:` for formatting changes
|
||||
- `refactor:` for code refactoring
|
||||
- `test:` for test additions
|
||||
- `chore:` for maintenance tasks
|
||||
|
||||
6. **Push and Create PR**
|
||||
```bash
|
||||
git push origin feature/your-feature-name
|
||||
```
|
||||
|
||||
Then create a Pull Request on GitHub with:
|
||||
- Clear title and description
|
||||
- Reference to related issues
|
||||
- Screenshots/examples if applicable
|
||||
|
||||
## Coding Style
|
||||
|
||||
### Bash Style Guide
|
||||
|
||||
1. **Indentation**: 4 spaces (no tabs)
|
||||
|
||||
2. **Function Names**: Use snake_case
|
||||
```bash
|
||||
vm_create() {
|
||||
# ...
|
||||
}
|
||||
```
|
||||
|
||||
3. **Variable Names**: Use UPPER_CASE for constants, snake_case for variables
|
||||
```bash
|
||||
DEFAULT_MEMORY="2048"
|
||||
local vm_id="test"
|
||||
```
|
||||
|
||||
4. **Comments**: Use comments for complex logic
|
||||
```bash
|
||||
# Parse command line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
# ...
|
||||
done
|
||||
```
|
||||
|
||||
5. **Error Handling**: Always check for errors
|
||||
```bash
|
||||
[[ -z "$vm_id" ]] && fatal "VM ID is required"
|
||||
```
|
||||
|
||||
6. **Quoting**: Always quote variables
|
||||
```bash
|
||||
echo "$variable" # Good
|
||||
echo $variable # Bad
|
||||
```
|
||||
|
||||
7. **Command Substitution**: Use `$(command)` instead of backticks
|
||||
```bash
|
||||
local result=$(some_command) # Good
|
||||
local result=`some_command` # Bad
|
||||
```
|
||||
|
||||
### Documentation
|
||||
|
||||
- Update README.md for new features
|
||||
- Add examples to EXAMPLES.sh
|
||||
- Include inline comments for complex code
|
||||
- Update help text in the main script
|
||||
|
||||
### Testing
|
||||
|
||||
Before submitting:
|
||||
|
||||
1. **Syntax Check**
|
||||
```bash
|
||||
bash -n easyqemu
|
||||
```
|
||||
|
||||
2. **ShellCheck** (if available)
|
||||
```bash
|
||||
shellcheck easyqemu
|
||||
```
|
||||
|
||||
3. **Functional Tests**
|
||||
- Test VM operations (create, start, delete)
|
||||
- Test volume operations
|
||||
- Test snapshot operations
|
||||
- Test repository operations
|
||||
|
||||
4. **Edge Cases**
|
||||
- Missing parameters
|
||||
- Invalid inputs
|
||||
- Non-existent VMs/volumes
|
||||
- Permission issues
|
||||
|
||||
## Areas for Contribution
|
||||
|
||||
### High Priority
|
||||
|
||||
- [ ] Windows VM support (UEFI boot)
|
||||
- [ ] Better error messages
|
||||
- [ ] Progress bars for long operations
|
||||
- [ ] Configuration wizard
|
||||
- [ ] Automated tests
|
||||
|
||||
### Medium Priority
|
||||
|
||||
- [ ] Web UI
|
||||
- [ ] Remote VM management
|
||||
- [ ] Cloud-init support
|
||||
- [ ] Network configuration wizard
|
||||
- [ ] Resource monitoring
|
||||
|
||||
### Low Priority
|
||||
|
||||
- [ ] Plugin system
|
||||
- [ ] VM templates library
|
||||
- [ ] Backup automation
|
||||
- [ ] Integration with cloud providers
|
||||
|
||||
## Development Setup
|
||||
|
||||
1. **Install QEMU**
|
||||
```bash
|
||||
# Debian/Ubuntu
|
||||
sudo apt-get install qemu-system-x86 qemu-utils shellcheck
|
||||
|
||||
# Fedora/RHEL
|
||||
sudo dnf install qemu-kvm qemu-img ShellCheck
|
||||
```
|
||||
|
||||
2. **Clone Repository**
|
||||
```bash
|
||||
git clone https://github.com/yourusername/easyqemu.git
|
||||
cd easyqemu
|
||||
```
|
||||
|
||||
3. **Make Executable**
|
||||
```bash
|
||||
chmod +x easyqemu
|
||||
```
|
||||
|
||||
4. **Test**
|
||||
```bash
|
||||
./easyqemu help
|
||||
./easyqemu version
|
||||
```
|
||||
|
||||
## Release Process
|
||||
|
||||
For maintainers:
|
||||
|
||||
1. Update version in script
|
||||
2. Update CHANGELOG.md
|
||||
3. Create git tag
|
||||
4. Create GitHub release
|
||||
|
||||
## Questions?
|
||||
|
||||
- Create an issue for questions
|
||||
- Check existing issues and documentation
|
||||
- Be patient and respectful
|
||||
|
||||
## License
|
||||
|
||||
By contributing, you agree that your contributions will be licensed under the MIT License.
|
||||
|
||||
---
|
||||
|
||||
Thank you for contributing to EasyQEMU! 🚀
|
||||
144
EXAMPLES.sh
Archivo ejecutable
144
EXAMPLES.sh
Archivo ejecutable
@@ -0,0 +1,144 @@
|
||||
#!/bin/bash
|
||||
|
||||
##############################################################################
|
||||
# EasyQEMU Examples - Common usage scenarios
|
||||
##############################################################################
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
echo_example() {
|
||||
echo -e "${BLUE}Example: $1${NC}"
|
||||
echo -e "${GREEN}$2${NC}"
|
||||
echo ""
|
||||
}
|
||||
|
||||
cat << 'EOF'
|
||||
╔═══════════════════════════════════════════════════════════════╗
|
||||
║ EasyQEMU - Usage Examples ║
|
||||
╚═══════════════════════════════════════════════════════════════╝
|
||||
|
||||
EOF
|
||||
|
||||
echo_example "1. Create a basic VM" \
|
||||
"./easyqemu vm create --name myvm"
|
||||
|
||||
echo_example "2. Create a VM with custom specs" \
|
||||
"./easyqemu vm create --name ubuntu --memory 4096 --cpus 4 --disk-size 50G"
|
||||
|
||||
echo_example "3. Create a VM with ISO" \
|
||||
"./easyqemu vm create --name installer --cdrom /path/to/ubuntu.iso --boot cd"
|
||||
|
||||
echo_example "4. List all VMs" \
|
||||
"./easyqemu vm list"
|
||||
|
||||
echo_example "5. Start a VM" \
|
||||
"./easyqemu vm start <vm_id>"
|
||||
|
||||
echo_example "6. Show VM information" \
|
||||
"./easyqemu vm info <vm_id>"
|
||||
|
||||
echo_example "7. Modify VM settings" \
|
||||
"./easyqemu vm modify <vm_id> --memory 8192 --cpus 8"
|
||||
|
||||
echo_example "8. Create a volume" \
|
||||
"./easyqemu volume create --name data --size 100G --format qcow2"
|
||||
|
||||
echo_example "9. List volumes" \
|
||||
"./easyqemu volume list"
|
||||
|
||||
echo_example "10. Convert volume format (qcow2 to raw)" \
|
||||
"./easyqemu volume convert --source disk.qcow2 --target disk.raw --format raw"
|
||||
|
||||
echo_example "11. Convert to VMDK (VMware format)" \
|
||||
"./easyqemu volume convert --source disk.qcow2 --target disk.vmdk --format vmdk"
|
||||
|
||||
echo_example "12. Import existing disk" \
|
||||
"./easyqemu volume import /path/to/disk.qcow2 imported-disk.qcow2"
|
||||
|
||||
echo_example "13. Export volume" \
|
||||
"./easyqemu volume export mydisk.qcow2 /backup/mydisk.qcow2"
|
||||
|
||||
echo_example "14. Create snapshot" \
|
||||
"./easyqemu snapshot create <vm_id> before_upgrade"
|
||||
|
||||
echo_example "15. List snapshots" \
|
||||
"./easyqemu snapshot list <vm_id>"
|
||||
|
||||
echo_example "16. Restore snapshot" \
|
||||
"./easyqemu snapshot apply <vm_id> before_upgrade"
|
||||
|
||||
echo_example "17. Delete snapshot" \
|
||||
"./easyqemu snapshot delete <vm_id> before_upgrade"
|
||||
|
||||
echo_example "18. Save VM to repository" \
|
||||
"./easyqemu repo save <vm_id> my_template"
|
||||
|
||||
echo_example "19. Load VM from repository" \
|
||||
"./easyqemu repo load my_template new_vm_name"
|
||||
|
||||
echo_example "20. List repository entries" \
|
||||
"./easyqemu repo list"
|
||||
|
||||
echo_example "21. Delete VM" \
|
||||
"./easyqemu vm delete <vm_id>"
|
||||
|
||||
echo_example "22. Delete VM (force, no confirmation)" \
|
||||
"./easyqemu vm delete <vm_id> -f"
|
||||
|
||||
echo_example "23. Get volume information" \
|
||||
"./easyqemu volume info ~/.easyqemu/volumes/disk.qcow2"
|
||||
|
||||
echo_example "24. Delete volume" \
|
||||
"./easyqemu volume delete mydisk.qcow2"
|
||||
|
||||
echo_example "25. Show help" \
|
||||
"./easyqemu help"
|
||||
|
||||
cat << 'EOF'
|
||||
|
||||
╔═══════════════════════════════════════════════════════════════╗
|
||||
║ Common Workflows ║
|
||||
╚═══════════════════════════════════════════════════════════════╝
|
||||
|
||||
WORKFLOW 1: Create and Install Ubuntu
|
||||
--------------------------------------
|
||||
1. ./easyqemu vm create --name ubuntu --memory 4096 --cpus 4 --disk-size 50G --cdrom ubuntu.iso
|
||||
2. ./easyqemu vm list (note the VM ID)
|
||||
3. ./easyqemu vm start ubuntu_<timestamp>
|
||||
4. Install OS in the VM
|
||||
5. ./easyqemu vm modify ubuntu_<timestamp> --boot hd --cdrom ""
|
||||
6. ./easyqemu vm start ubuntu_<timestamp>
|
||||
|
||||
WORKFLOW 2: Snapshot Before Major Changes
|
||||
-----------------------------------------
|
||||
1. ./easyqemu snapshot create <vm_id> before_changes
|
||||
2. Make your changes in the VM
|
||||
3. If successful: Keep it
|
||||
4. If failed: ./easyqemu snapshot apply <vm_id> before_changes
|
||||
|
||||
WORKFLOW 3: Create Base VM Template
|
||||
-----------------------------------
|
||||
1. Create and configure a base VM
|
||||
2. ./easyqemu repo save <vm_id> base_template
|
||||
3. Create multiple VMs from template:
|
||||
./easyqemu repo load base_template vm1
|
||||
./easyqemu repo load base_template vm2
|
||||
./easyqemu repo load base_template vm3
|
||||
|
||||
WORKFLOW 4: Convert Disk for VirtualBox
|
||||
---------------------------------------
|
||||
1. ./easyqemu volume convert --source ~/.easyqemu/volumes/myvm.qcow2 --target myvm.vdi --format vdi
|
||||
2. Import myvm.vdi into VirtualBox
|
||||
|
||||
WORKFLOW 5: Migrate VM to Another System
|
||||
----------------------------------------
|
||||
1. ./easyqemu repo save <vm_id> my_vm
|
||||
2. tar -czf my_vm.tar.gz -C ~/.easyqemu/repository my_vm
|
||||
3. Transfer my_vm.tar.gz to other system
|
||||
4. tar -xzf my_vm.tar.gz -C ~/.easyqemu/repository
|
||||
5. ./easyqemu repo load my_vm
|
||||
|
||||
EOF
|
||||
21
LICENSE
Archivo normal
21
LICENSE
Archivo normal
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 EasyQEMU Project
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
181
PROJECT.md
Archivo normal
181
PROJECT.md
Archivo normal
@@ -0,0 +1,181 @@
|
||||
# EasyQEMU Project Structure
|
||||
|
||||
```
|
||||
easyqemu/
|
||||
│
|
||||
├── easyqemu # Main executable script
|
||||
├── install.sh # Installation script
|
||||
├── test.sh # Automated test suite
|
||||
├── EXAMPLES.sh # Usage examples with colored output
|
||||
│
|
||||
├── README.md # Comprehensive documentation
|
||||
├── QUICKSTART.md # Quick start guide
|
||||
├── CONTRIBUTING.md # Contribution guidelines
|
||||
├── CHANGELOG.md # Version history and changes
|
||||
├── LICENSE # MIT License
|
||||
│
|
||||
├── .easyqemu.conf # Default configuration template
|
||||
└── .gitignore # Git ignore rules
|
||||
|
||||
Runtime Directory Structure (~/.easyqemu/):
|
||||
├── vms/ # VM runtime data
|
||||
├── volumes/ # Disk images (.qcow2, .raw, etc.)
|
||||
├── configs/ # VM configurations (JSON files)
|
||||
├── repository/ # Saved VMs (like Docker images)
|
||||
├── locks/ # Lock files for running VMs
|
||||
└── easyqemu.log # Log file
|
||||
```
|
||||
|
||||
## Features Overview
|
||||
|
||||
### ✅ VM Management
|
||||
- Create, start, stop, delete virtual machines
|
||||
- Modify VM configurations (memory, CPUs, display, network)
|
||||
- List all VMs with details
|
||||
- Show detailed VM information
|
||||
- Support for multiple display modes (GTK, SDL, VNC, headless)
|
||||
- Network configuration (user, bridge, tap)
|
||||
- Boot device selection (CD, HDD)
|
||||
|
||||
### ✅ Volume Management
|
||||
- Create volumes in multiple formats:
|
||||
- qcow2 (QEMU Copy-On-Write)
|
||||
- raw (Raw disk image)
|
||||
- vmdk (VMware)
|
||||
- vdi (VirtualBox)
|
||||
- vhdx (Hyper-V)
|
||||
- Convert between formats
|
||||
- Import/export volumes
|
||||
- List volumes with size information
|
||||
- Show detailed volume information
|
||||
|
||||
### ✅ Snapshot Management
|
||||
- Create disk snapshots
|
||||
- List all snapshots for a VM
|
||||
- Apply/restore snapshots
|
||||
- Delete snapshots
|
||||
- Timestamp-based snapshot names
|
||||
|
||||
### ✅ Repository System
|
||||
- Save VMs to repository (like Docker images)
|
||||
- Load VMs from repository (create clones)
|
||||
- List repository entries
|
||||
- Delete repository entries
|
||||
- Includes disk and configuration
|
||||
|
||||
### ✅ User Experience
|
||||
- Colored terminal output
|
||||
- Clear error messages
|
||||
- Interactive confirmations for destructive operations
|
||||
- Force flags for scripting (-f, --force)
|
||||
- Comprehensive help system
|
||||
- Example commands and workflows
|
||||
|
||||
### ✅ Technical Features
|
||||
- JSON-based configuration storage
|
||||
- Automatic KVM acceleration detection
|
||||
- Modular Bash function design
|
||||
- Comprehensive error handling
|
||||
- Directory structure initialization
|
||||
- Version management
|
||||
|
||||
## Command Summary
|
||||
|
||||
| Category | Command | Description |
|
||||
|----------|---------|-------------|
|
||||
| **VM** | `vm create` | Create a new VM |
|
||||
| | `vm list` | List all VMs |
|
||||
| | `vm start` | Start a VM |
|
||||
| | `vm info` | Show VM details |
|
||||
| | `vm modify` | Modify VM configuration |
|
||||
| | `vm delete` | Delete a VM |
|
||||
| **Volume** | `volume create` | Create a new volume |
|
||||
| | `volume list` | List all volumes |
|
||||
| | `volume info` | Show volume details |
|
||||
| | `volume convert` | Convert format |
|
||||
| | `volume import` | Import external volume |
|
||||
| | `volume export` | Export volume |
|
||||
| | `volume delete` | Delete a volume |
|
||||
| **Snapshot** | `snapshot create` | Create snapshot |
|
||||
| | `snapshot list` | List snapshots |
|
||||
| | `snapshot apply` | Restore snapshot |
|
||||
| | `snapshot delete` | Delete snapshot |
|
||||
| **Repository** | `repo save` | Save VM to repo |
|
||||
| | `repo load` | Load VM from repo |
|
||||
| | `repo list` | List saved VMs |
|
||||
| | `repo delete` | Delete saved VM |
|
||||
| **Other** | `version` | Show version |
|
||||
| | `help` | Show help |
|
||||
|
||||
## Testing Status
|
||||
|
||||
✅ All 18 automated tests pass:
|
||||
1. Help command
|
||||
2. Version command
|
||||
3. Create VM
|
||||
4. List VMs
|
||||
5. VM Info
|
||||
6. Modify VM
|
||||
7. Create volume
|
||||
8. List volumes
|
||||
9. Volume info
|
||||
10. Convert volume
|
||||
11. Create snapshot
|
||||
12. List snapshots
|
||||
13. Delete snapshot
|
||||
14. Save to repository
|
||||
15. List repository
|
||||
16. Load from repository
|
||||
17. Delete volume
|
||||
18. Delete VM
|
||||
|
||||
## Requirements
|
||||
|
||||
- **QEMU/KVM**: qemu-system-x86_64, qemu-img
|
||||
- **Bash**: 4.0 or later
|
||||
- **OS**: Linux (tested on Debian-based systems)
|
||||
|
||||
## Installation Methods
|
||||
|
||||
1. **System-wide**: `/usr/local/bin/easyqemu` (requires sudo)
|
||||
2. **User-only**: `~/.local/bin/easyqemu`
|
||||
3. **Portable**: Run from current directory `./easyqemu`
|
||||
|
||||
## Usage Examples
|
||||
|
||||
```bash
|
||||
# Create and start a VM
|
||||
easyqemu vm create --name ubuntu --memory 4096 --cpus 4 --disk-size 50G
|
||||
easyqemu vm start ubuntu_<timestamp>
|
||||
|
||||
# Create a snapshot before updates
|
||||
easyqemu snapshot create <vm_id> before_update
|
||||
|
||||
# Clone a VM
|
||||
easyqemu repo save <vm_id> my_template
|
||||
easyqemu repo load my_template cloned_vm
|
||||
|
||||
# Convert disk format
|
||||
easyqemu volume convert --source disk.qcow2 --target disk.vmdk --format vmdk
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
- **README.md**: Full documentation with examples
|
||||
- **QUICKSTART.md**: Get started in 5 minutes
|
||||
- **EXAMPLES.sh**: Interactive examples with colored output
|
||||
- **CONTRIBUTING.md**: How to contribute
|
||||
- **CHANGELOG.md**: Version history
|
||||
|
||||
## License
|
||||
|
||||
MIT License - Free to use, modify, and distribute
|
||||
|
||||
## Project Goals
|
||||
|
||||
Make QEMU/KVM virtual machine management as easy as Docker container management, with an intuitive command-line interface and repository system for managing VM templates.
|
||||
|
||||
---
|
||||
|
||||
**Status**: ✅ Production Ready v1.0.0
|
||||
**Last Updated**: 2026-01-07
|
||||
236
QUICKSTART.md
Archivo normal
236
QUICKSTART.md
Archivo normal
@@ -0,0 +1,236 @@
|
||||
# EasyQEMU Quick Start Guide
|
||||
|
||||
Get started with EasyQEMU in 5 minutes!
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# 1. Clone or download EasyQEMU
|
||||
git clone https://github.com/yourusername/easyqemu.git
|
||||
cd easyqemu
|
||||
|
||||
# 2. Run the installer
|
||||
./install.sh
|
||||
|
||||
# 3. Verify installation
|
||||
easyqemu version
|
||||
```
|
||||
|
||||
## Your First VM
|
||||
|
||||
### Step 1: Create a VM
|
||||
|
||||
```bash
|
||||
# Create a simple VM with default settings
|
||||
easyqemu vm create --name myvm
|
||||
|
||||
# Or with custom settings
|
||||
easyqemu vm create \
|
||||
--name ubuntu \
|
||||
--memory 4096 \
|
||||
--cpus 4 \
|
||||
--disk-size 50G
|
||||
```
|
||||
|
||||
### Step 2: List Your VMs
|
||||
|
||||
```bash
|
||||
easyqemu vm list
|
||||
```
|
||||
|
||||
You'll see output like:
|
||||
```
|
||||
VM ID NAME CREATED MEMORY CPUS
|
||||
--------------------------------------------------------------------------------
|
||||
ubuntu_1704672000 ubuntu 2026-01-07 4096M 4
|
||||
```
|
||||
|
||||
### Step 3: Start Your VM
|
||||
|
||||
```bash
|
||||
# Use the VM ID from the list command
|
||||
easyqemu vm start ubuntu_1704672000
|
||||
```
|
||||
|
||||
## Installing an OS
|
||||
|
||||
### Download an ISO
|
||||
|
||||
```bash
|
||||
# Example: Download Ubuntu
|
||||
wget https://releases.ubuntu.com/22.04/ubuntu-22.04.3-desktop-amd64.iso
|
||||
```
|
||||
|
||||
### Create VM with ISO
|
||||
|
||||
```bash
|
||||
easyqemu vm create \
|
||||
--name ubuntu \
|
||||
--memory 4096 \
|
||||
--cpus 4 \
|
||||
--disk-size 50G \
|
||||
--cdrom ubuntu-22.04.3-desktop-amd64.iso \
|
||||
--boot cd
|
||||
```
|
||||
|
||||
### Start and Install
|
||||
|
||||
```bash
|
||||
# Get the VM ID
|
||||
easyqemu vm list
|
||||
|
||||
# Start the VM
|
||||
easyqemu vm start ubuntu_<timestamp>
|
||||
|
||||
# Install the OS in the VM window
|
||||
# After installation, modify to boot from disk:
|
||||
easyqemu vm modify ubuntu_<timestamp> --boot hd --cdrom ""
|
||||
|
||||
# Start again
|
||||
easyqemu vm start ubuntu_<timestamp>
|
||||
```
|
||||
|
||||
## Common Tasks
|
||||
|
||||
### Create a Snapshot
|
||||
|
||||
```bash
|
||||
# Before making changes
|
||||
easyqemu snapshot create <vm_id> before_update
|
||||
|
||||
# If something goes wrong, restore:
|
||||
easyqemu snapshot apply <vm_id> before_update
|
||||
```
|
||||
|
||||
### Clone a VM
|
||||
|
||||
```bash
|
||||
# Save to repository
|
||||
easyqemu repo save <vm_id> my_template
|
||||
|
||||
# Create a clone
|
||||
easyqemu repo load my_template cloned_vm
|
||||
```
|
||||
|
||||
### Convert Disk Format
|
||||
|
||||
```bash
|
||||
# Convert to VMware format
|
||||
easyqemu volume convert \
|
||||
--source ~/.easyqemu/volumes/myvm.qcow2 \
|
||||
--target myvm.vmdk \
|
||||
--format vmdk
|
||||
```
|
||||
|
||||
### Backup a VM
|
||||
|
||||
```bash
|
||||
# Export the disk
|
||||
easyqemu volume export myvm.qcow2 /backup/myvm.qcow2
|
||||
|
||||
# Or save to repository
|
||||
easyqemu repo save <vm_id> backup_$(date +%Y%m%d)
|
||||
```
|
||||
|
||||
## Tips & Tricks
|
||||
|
||||
### 1. Use Descriptive Names
|
||||
|
||||
```bash
|
||||
easyqemu vm create --name dev-ubuntu-server
|
||||
easyqemu vm create --name test-fedora-desktop
|
||||
```
|
||||
|
||||
### 2. Create Base Templates
|
||||
|
||||
```bash
|
||||
# Create and configure a base VM
|
||||
easyqemu vm create --name base-ubuntu --memory 2048
|
||||
|
||||
# After setup, save as template
|
||||
easyqemu repo save base-ubuntu_<id> base-ubuntu-template
|
||||
|
||||
# Create multiple instances
|
||||
easyqemu repo load base-ubuntu-template web-server-1
|
||||
easyqemu repo load base-ubuntu-template web-server-2
|
||||
easyqemu repo load base-ubuntu-template db-server
|
||||
```
|
||||
|
||||
### 3. Regular Snapshots
|
||||
|
||||
```bash
|
||||
# Before system updates
|
||||
easyqemu snapshot create <vm_id> pre_update_$(date +%Y%m%d)
|
||||
|
||||
# Before major changes
|
||||
easyqemu snapshot create <vm_id> before_config_change
|
||||
```
|
||||
|
||||
### 4. List Everything
|
||||
|
||||
```bash
|
||||
easyqemu vm list # All VMs
|
||||
easyqemu volume list # All volumes
|
||||
easyqemu repo list # All saved VMs
|
||||
easyqemu snapshot list <vm_id> # VM snapshots
|
||||
```
|
||||
|
||||
### 5. Use -f for Scripts
|
||||
|
||||
```bash
|
||||
# Delete without confirmation (useful in scripts)
|
||||
easyqemu vm delete <vm_id> -f
|
||||
easyqemu volume delete disk.qcow2 -f
|
||||
```
|
||||
|
||||
## Keyboard Shortcuts in VM
|
||||
|
||||
- **Ctrl+Alt+G**: Release mouse cursor
|
||||
- **Ctrl+Alt+F**: Toggle fullscreen
|
||||
- **Ctrl+Alt+Q**: Quit VM (with confirmation)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### VM Won't Start
|
||||
|
||||
```bash
|
||||
# Check VM configuration
|
||||
easyqemu vm info <vm_id>
|
||||
|
||||
# Check disk exists
|
||||
ls -lh ~/.easyqemu/volumes/
|
||||
```
|
||||
|
||||
### Permission Denied
|
||||
|
||||
```bash
|
||||
# Add yourself to kvm group
|
||||
sudo usermod -a -G kvm $USER
|
||||
|
||||
# Log out and log back in
|
||||
```
|
||||
|
||||
### No Display
|
||||
|
||||
```bash
|
||||
# Try different display option
|
||||
easyqemu vm modify <vm_id> --display sdl
|
||||
```
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. **Read the full documentation**: `cat README.md`
|
||||
2. **See more examples**: `./EXAMPLES.sh`
|
||||
3. **Get help**: `easyqemu help`
|
||||
4. **Join the community**: (add your community links)
|
||||
|
||||
## Need Help?
|
||||
|
||||
- Run `easyqemu help` for command reference
|
||||
- Check `README.md` for detailed documentation
|
||||
- Create an issue on GitHub
|
||||
- Check existing issues for solutions
|
||||
|
||||
---
|
||||
|
||||
Happy virtualizing! 🚀
|
||||
323
README.es.md
Archivo normal
323
README.es.md
Archivo normal
@@ -0,0 +1,323 @@
|
||||
# EasyQEMU - Resumen en Español
|
||||
|
||||
## ¿Qué es EasyQEMU?
|
||||
|
||||
**EasyQEMU** es una herramienta completa de línea de comandos para gestionar máquinas virtuales QEMU de forma intuitiva. Proporciona una interfaz similar a Docker para crear, gestionar y organizar VMs con características como snapshots, gestión de volúmenes y un sistema de repositorio.
|
||||
|
||||
## Características Principales
|
||||
|
||||
### ✅ Gestión de Máquinas Virtuales
|
||||
- Crear, iniciar, detener, modificar y eliminar VMs
|
||||
- Soporte para KVM (aceleración por hardware)
|
||||
- Múltiples modos de pantalla (GTK, SDL, VNC, sin pantalla)
|
||||
- Configuración de red (user, bridge, tap)
|
||||
- Arranque desde CD/DVD o disco duro
|
||||
|
||||
### ✅ Gestión de Volúmenes
|
||||
- Crear volúmenes en múltiples formatos:
|
||||
- **qcow2** (formato nativo de QEMU)
|
||||
- **raw** (imagen de disco raw)
|
||||
- **vmdk** (VMware)
|
||||
- **vdi** (VirtualBox)
|
||||
- **vhdx** (Hyper-V)
|
||||
- Convertir entre formatos
|
||||
- Importar/exportar volúmenes
|
||||
- Información detallada de volúmenes
|
||||
|
||||
### ✅ Gestión de Snapshots
|
||||
- Crear instantáneas del disco
|
||||
- Listar todos los snapshots de una VM
|
||||
- Aplicar/restaurar snapshots
|
||||
- Eliminar snapshots
|
||||
|
||||
### ✅ Sistema de Repositorio
|
||||
- Guardar VMs en el repositorio (como imágenes Docker)
|
||||
- Cargar VMs desde el repositorio (crear clones)
|
||||
- Listar entradas del repositorio
|
||||
- Sistema similar a Docker para VMs
|
||||
|
||||
## Instalación Rápida
|
||||
|
||||
```bash
|
||||
# 1. Hacer el script ejecutable
|
||||
chmod +x easyqemu
|
||||
|
||||
# 2. Ejecutar el instalador
|
||||
./install.sh
|
||||
|
||||
# 3. Verificar instalación
|
||||
easyqemu version
|
||||
```
|
||||
|
||||
## Uso Básico
|
||||
|
||||
### Crear una VM
|
||||
|
||||
```bash
|
||||
# VM básica con valores por defecto
|
||||
easyqemu vm create --name mi-vm
|
||||
|
||||
# VM personalizada
|
||||
easyqemu vm create \
|
||||
--name ubuntu-server \
|
||||
--memory 4096 \
|
||||
--cpus 4 \
|
||||
--disk-size 50G \
|
||||
--cdrom /ruta/al/ubuntu.iso
|
||||
```
|
||||
|
||||
### Listar VMs
|
||||
|
||||
```bash
|
||||
easyqemu vm list
|
||||
```
|
||||
|
||||
### Iniciar una VM
|
||||
|
||||
```bash
|
||||
easyqemu vm start ubuntu-server_<timestamp>
|
||||
```
|
||||
|
||||
### Crear un Snapshot
|
||||
|
||||
```bash
|
||||
# Antes de hacer cambios importantes
|
||||
easyqemu snapshot create <vm_id> antes_actualizar
|
||||
|
||||
# Si algo sale mal, restaurar:
|
||||
easyqemu snapshot apply <vm_id> antes_actualizar
|
||||
```
|
||||
|
||||
### Clonar una VM
|
||||
|
||||
```bash
|
||||
# Guardar en repositorio
|
||||
easyqemu repo save <vm_id> mi-plantilla
|
||||
|
||||
# Crear un clon
|
||||
easyqemu repo load mi-plantilla vm-clonada
|
||||
```
|
||||
|
||||
### Convertir Formato de Disco
|
||||
|
||||
```bash
|
||||
# Convertir a formato VMware
|
||||
easyqemu volume convert \
|
||||
--source ~/.easyqemu/volumes/disk.qcow2 \
|
||||
--target disk.vmdk \
|
||||
--format vmdk
|
||||
|
||||
# Convertir a VirtualBox
|
||||
easyqemu volume convert \
|
||||
--source disk.qcow2 \
|
||||
--target disk.vdi \
|
||||
--format vdi
|
||||
```
|
||||
|
||||
## Estructura de Archivos Creados
|
||||
|
||||
```
|
||||
easyqemu/
|
||||
├── easyqemu - Script principal (26KB)
|
||||
├── install.sh - Script de instalación
|
||||
├── test.sh - Suite de pruebas automatizadas
|
||||
├── EXAMPLES.sh - Ejemplos de uso
|
||||
│
|
||||
├── README.md - Documentación completa en inglés
|
||||
├── README.es.md - Este archivo (resumen en español)
|
||||
├── QUICKSTART.md - Guía de inicio rápido
|
||||
├── CONTRIBUTING.md - Guía de contribución
|
||||
├── CHANGELOG.md - Historial de versiones
|
||||
├── PROJECT.md - Resumen del proyecto
|
||||
├── LICENSE - Licencia MIT
|
||||
│
|
||||
├── .easyqemu.conf - Plantilla de configuración
|
||||
└── .gitignore - Reglas de Git
|
||||
```
|
||||
|
||||
## Todos los Comandos Disponibles
|
||||
|
||||
| Categoría | Comando | Descripción |
|
||||
|-----------|---------|-------------|
|
||||
| **VM** | `vm create` | Crear una nueva VM |
|
||||
| | `vm list` | Listar todas las VMs |
|
||||
| | `vm start` | Iniciar una VM |
|
||||
| | `vm info` | Mostrar información de la VM |
|
||||
| | `vm modify` | Modificar configuración |
|
||||
| | `vm delete` | Eliminar una VM |
|
||||
| **Volumen** | `volume create` | Crear un volumen |
|
||||
| | `volume list` | Listar volúmenes |
|
||||
| | `volume info` | Info del volumen |
|
||||
| | `volume convert` | Convertir formato |
|
||||
| | `volume import` | Importar volumen |
|
||||
| | `volume export` | Exportar volumen |
|
||||
| | `volume delete` | Eliminar volumen |
|
||||
| **Snapshot** | `snapshot create` | Crear snapshot |
|
||||
| | `snapshot list` | Listar snapshots |
|
||||
| | `snapshot apply` | Restaurar snapshot |
|
||||
| | `snapshot delete` | Eliminar snapshot |
|
||||
| **Repositorio** | `repo save` | Guardar VM |
|
||||
| | `repo load` | Cargar VM |
|
||||
| | `repo list` | Listar VMs guardadas |
|
||||
| | `repo delete` | Eliminar VM guardada |
|
||||
|
||||
## Ejemplos Prácticos
|
||||
|
||||
### Ejemplo 1: Instalar Ubuntu
|
||||
|
||||
```bash
|
||||
# 1. Descargar ISO
|
||||
wget https://releases.ubuntu.com/22.04/ubuntu-22.04.3-desktop-amd64.iso
|
||||
|
||||
# 2. Crear VM con ISO
|
||||
easyqemu vm create \
|
||||
--name ubuntu-desktop \
|
||||
--memory 4096 \
|
||||
--cpus 4 \
|
||||
--disk-size 50G \
|
||||
--cdrom ubuntu-22.04.3-desktop-amd64.iso
|
||||
|
||||
# 3. Iniciar e instalar
|
||||
easyqemu vm start ubuntu-desktop_<timestamp>
|
||||
|
||||
# 4. Después de instalar, arrancar desde disco
|
||||
easyqemu vm modify ubuntu-desktop_<timestamp> --boot hd --cdrom ""
|
||||
```
|
||||
|
||||
### Ejemplo 2: Crear Plantilla Base
|
||||
|
||||
```bash
|
||||
# 1. Crear y configurar VM base
|
||||
easyqemu vm create --name base-server --memory 2048
|
||||
|
||||
# 2. Guardar como plantilla
|
||||
easyqemu repo save base-server_<id> plantilla-servidor
|
||||
|
||||
# 3. Crear múltiples instancias
|
||||
easyqemu repo load plantilla-servidor web-server-1
|
||||
easyqemu repo load plantilla-servidor web-server-2
|
||||
easyqemu repo load plantilla-servidor db-server
|
||||
```
|
||||
|
||||
### Ejemplo 3: Migrar a VMware
|
||||
|
||||
```bash
|
||||
# Convertir disco a formato VMware
|
||||
easyqemu volume convert \
|
||||
--source ~/.easyqemu/volumes/mi-vm.qcow2 \
|
||||
--target mi-vm.vmdk \
|
||||
--format vmdk
|
||||
|
||||
# Ahora puedes importar mi-vm.vmdk en VMware
|
||||
```
|
||||
|
||||
## Pruebas
|
||||
|
||||
El proyecto incluye una suite de pruebas automatizadas:
|
||||
|
||||
```bash
|
||||
./test.sh
|
||||
```
|
||||
|
||||
**Resultado**: ✅ 18/18 pruebas pasadas
|
||||
|
||||
## Estructura de Datos
|
||||
|
||||
EasyQEMU almacena todos los datos en `~/.easyqemu/`:
|
||||
|
||||
```
|
||||
~/.easyqemu/
|
||||
├── vms/ # Datos de ejecución de VMs
|
||||
├── volumes/ # Imágenes de disco
|
||||
├── configs/ # Configuraciones de VMs (JSON)
|
||||
├── repository/ # VMs guardadas
|
||||
├── locks/ # Archivos de bloqueo
|
||||
└── easyqemu.log # Archivo de log
|
||||
```
|
||||
|
||||
## Requisitos
|
||||
|
||||
- **QEMU/KVM**: qemu-system-x86_64, qemu-img
|
||||
- **Bash**: 4.0 o superior
|
||||
- **OS**: Linux (probado en sistemas basados en Debian)
|
||||
|
||||
### Instalar QEMU en Debian/Ubuntu
|
||||
|
||||
```bash
|
||||
sudo apt-get install qemu-system-x86 qemu-utils
|
||||
```
|
||||
|
||||
### Instalar QEMU en Fedora/RHEL
|
||||
|
||||
```bash
|
||||
sudo dnf install qemu-kvm qemu-img
|
||||
```
|
||||
|
||||
### Instalar QEMU en Arch Linux
|
||||
|
||||
```bash
|
||||
sudo pacman -S qemu
|
||||
```
|
||||
|
||||
## Ayuda y Documentación
|
||||
|
||||
```bash
|
||||
# Ver ayuda
|
||||
easyqemu help
|
||||
|
||||
# Ver ejemplos
|
||||
./EXAMPLES.sh
|
||||
|
||||
# Leer documentación completa (inglés)
|
||||
cat README.md
|
||||
|
||||
# Guía de inicio rápido
|
||||
cat QUICKSTART.md
|
||||
```
|
||||
|
||||
## Características Técnicas
|
||||
|
||||
- **Lenguaje**: Bash 4.0+
|
||||
- **Tamaño**: ~26KB (script principal)
|
||||
- **Configuración**: JSON
|
||||
- **Aceleración**: KVM automático
|
||||
- **Formatos**: qcow2, raw, vmdk, vdi, vhdx
|
||||
- **Display**: GTK, SDL, VNC, sin pantalla
|
||||
- **Red**: user, bridge, tap
|
||||
|
||||
## Licencia
|
||||
|
||||
MIT License - Libre para usar, modificar y distribuir
|
||||
|
||||
## Estado del Proyecto
|
||||
|
||||
✅ **Versión**: 1.0.0
|
||||
✅ **Estado**: Listo para producción
|
||||
✅ **Pruebas**: 18/18 pasadas
|
||||
✅ **Documentación**: Completa
|
||||
✅ **Fecha**: 7 de enero de 2026
|
||||
|
||||
## Próximas Características
|
||||
|
||||
- Soporte para VMs Windows (UEFI boot)
|
||||
- Interfaz web
|
||||
- Gestión remota de VMs
|
||||
- Integración con cloud-init
|
||||
- Wizard de configuración de red
|
||||
- Monitoreo de recursos
|
||||
- Sistema de backups automáticos
|
||||
- Biblioteca de plantillas de VMs
|
||||
|
||||
## Contribuir
|
||||
|
||||
Lee [CONTRIBUTING.md](CONTRIBUTING.md) para información sobre cómo contribuir al proyecto.
|
||||
|
||||
## Soporte
|
||||
|
||||
- Crear un issue en GitHub
|
||||
- Revisar la documentación
|
||||
- Ejecutar `./test.sh` para diagnosticar problemas
|
||||
|
||||
---
|
||||
|
||||
**EasyQEMU** - ¡Gestión de QEMU simplificada! 🚀
|
||||
529
README.md
Archivo normal
529
README.md
Archivo normal
@@ -0,0 +1,529 @@
|
||||
# EasyQEMU
|
||||
|
||||
**EasyQEMU** is an intuitive command-line tool for managing QEMU virtual machines. It provides a Docker-like interface for creating, managing, and organizing VMs with features like snapshots, volume management, and a repository system.
|
||||
|
||||
## Features
|
||||
|
||||
- 🚀 **Easy VM Management**: Create, start, stop, modify, and delete virtual machines
|
||||
- 💾 **Volume Management**: Create, convert, import, and export disk images
|
||||
- 📸 **Snapshot Support**: Create and restore VM snapshots
|
||||
- 📦 **Repository System**: Save and load VM configurations (like Docker images)
|
||||
- 🔄 **Format Conversion**: Support for multiple disk formats (qcow2, raw, vmdk, vdi, vhdx)
|
||||
- ⚡ **KVM Acceleration**: Automatic KVM support for better performance
|
||||
- 🎨 **Intuitive Interface**: Simple, memorable commands
|
||||
|
||||
## Requirements
|
||||
|
||||
- QEMU/KVM installed
|
||||
- `qemu-system-x86_64`
|
||||
- `qemu-img`
|
||||
- Bash 4.0+
|
||||
- Linux operating system
|
||||
|
||||
### Installation on Debian/Ubuntu
|
||||
|
||||
```bash
|
||||
sudo apt-get install qemu-system-x86 qemu-utils
|
||||
```
|
||||
|
||||
### Installation on Fedora/RHEL
|
||||
|
||||
```bash
|
||||
sudo dnf install qemu-kvm qemu-img
|
||||
```
|
||||
|
||||
### Installation on Arch Linux
|
||||
|
||||
```bash
|
||||
sudo pacman -S qemu
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
1. Clone or download the repository
|
||||
2. Make the script executable:
|
||||
```bash
|
||||
chmod +x easyqemu
|
||||
```
|
||||
3. (Optional) Add to PATH:
|
||||
```bash
|
||||
sudo ln -s $(pwd)/easyqemu /usr/local/bin/easyqemu
|
||||
```
|
||||
Or add the directory to your PATH in `~/.bashrc`:
|
||||
```bash
|
||||
export PATH="$PATH:/path/to/easyqemu"
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Create your first VM
|
||||
|
||||
```bash
|
||||
# Create a VM with default settings (2GB RAM, 2 CPUs, 20GB disk)
|
||||
easyqemu vm create --name myvm
|
||||
|
||||
# Create a VM with custom settings
|
||||
easyqemu vm create --name ubuntu \
|
||||
--memory 4096 \
|
||||
--cpus 4 \
|
||||
--disk-size 50G \
|
||||
--cdrom /path/to/ubuntu.iso
|
||||
```
|
||||
|
||||
### Start the VM
|
||||
|
||||
```bash
|
||||
# List all VMs to get the VM ID
|
||||
easyqemu vm list
|
||||
|
||||
# Start the VM using its ID
|
||||
easyqemu vm start myvm_1704672000
|
||||
```
|
||||
|
||||
### Manage VMs
|
||||
|
||||
```bash
|
||||
# List all VMs
|
||||
easyqemu vm list
|
||||
|
||||
# Show VM information
|
||||
easyqemu vm info myvm_1704672000
|
||||
|
||||
# Modify VM settings
|
||||
easyqemu vm modify myvm_1704672000 --memory 8192 --cpus 8
|
||||
|
||||
# Delete a VM
|
||||
easyqemu vm delete myvm_1704672000
|
||||
```
|
||||
|
||||
## Commands
|
||||
|
||||
### VM Management
|
||||
|
||||
#### Create VM
|
||||
```bash
|
||||
easyqemu vm create [OPTIONS]
|
||||
|
||||
Options:
|
||||
--name NAME VM name (required)
|
||||
--memory MB Memory in MB (default: 2048)
|
||||
--cpus N Number of CPUs (default: 2)
|
||||
--disk PATH Path to existing disk
|
||||
--disk-size SIZE Size for new disk (default: 20G)
|
||||
--cdrom PATH Path to ISO file
|
||||
--network TYPE Network type (default: user)
|
||||
--display TYPE Display type: gtk, sdl, none (default: gtk)
|
||||
--boot DEVICE Boot device: cd, hd (default: cd)
|
||||
```
|
||||
|
||||
#### List VMs
|
||||
```bash
|
||||
easyqemu vm list
|
||||
```
|
||||
|
||||
#### Start VM
|
||||
```bash
|
||||
easyqemu vm start <vm_id>
|
||||
```
|
||||
|
||||
#### Show VM Info
|
||||
```bash
|
||||
easyqemu vm info <vm_id>
|
||||
```
|
||||
|
||||
#### Modify VM
|
||||
```bash
|
||||
easyqemu vm modify <vm_id> [OPTIONS]
|
||||
|
||||
Options:
|
||||
--name NAME New VM name
|
||||
--memory MB Memory in MB
|
||||
--cpus N Number of CPUs
|
||||
--cdrom PATH Path to ISO file
|
||||
--network TYPE Network type
|
||||
--display TYPE Display type
|
||||
--boot DEVICE Boot device
|
||||
```
|
||||
|
||||
#### Delete VM
|
||||
```bash
|
||||
easyqemu vm delete <vm_id> [-f|--force]
|
||||
```
|
||||
|
||||
### Volume Management
|
||||
|
||||
#### Create Volume
|
||||
```bash
|
||||
easyqemu volume create --name NAME --size SIZE [--format FORMAT]
|
||||
|
||||
Options:
|
||||
--name NAME Volume name (required)
|
||||
--size SIZE Volume size (e.g., 10G, 500M)
|
||||
--format FORMAT Format: qcow2, raw, vmdk, vdi, vhdx (default: qcow2)
|
||||
```
|
||||
|
||||
#### List Volumes
|
||||
```bash
|
||||
easyqemu volume list
|
||||
```
|
||||
|
||||
#### Show Volume Info
|
||||
```bash
|
||||
easyqemu volume info <path>
|
||||
```
|
||||
|
||||
#### Convert Volume
|
||||
```bash
|
||||
easyqemu volume convert --source PATH --target PATH --format FORMAT
|
||||
|
||||
Options:
|
||||
--source PATH Source volume path (required)
|
||||
--target PATH Target volume path (required)
|
||||
--format FORMAT Target format (required)
|
||||
```
|
||||
|
||||
Example:
|
||||
```bash
|
||||
# Convert raw to qcow2
|
||||
easyqemu volume convert --source disk.raw --target disk.qcow2 --format qcow2
|
||||
|
||||
# Convert qcow2 to vmdk (for VMware)
|
||||
easyqemu volume convert --source disk.qcow2 --target disk.vmdk --format vmdk
|
||||
```
|
||||
|
||||
#### Import Volume
|
||||
```bash
|
||||
easyqemu volume import <source_path> [name]
|
||||
```
|
||||
|
||||
#### Export Volume
|
||||
```bash
|
||||
easyqemu volume export <volume_name> <target_path>
|
||||
```
|
||||
|
||||
#### Delete Volume
|
||||
```bash
|
||||
easyqemu volume delete <volume_name> [-f|--force]
|
||||
```
|
||||
|
||||
### Snapshot Management
|
||||
|
||||
#### Create Snapshot
|
||||
```bash
|
||||
easyqemu snapshot create <vm_id> [snapshot_name]
|
||||
```
|
||||
|
||||
If no snapshot name is provided, it will be auto-generated with a timestamp.
|
||||
|
||||
#### List Snapshots
|
||||
```bash
|
||||
easyqemu snapshot list <vm_id>
|
||||
```
|
||||
|
||||
#### Apply Snapshot
|
||||
```bash
|
||||
easyqemu snapshot apply <vm_id> <snapshot_name>
|
||||
```
|
||||
|
||||
#### Delete Snapshot
|
||||
```bash
|
||||
easyqemu snapshot delete <vm_id> <snapshot_name>
|
||||
```
|
||||
|
||||
### Repository Management
|
||||
|
||||
The repository system allows you to save VM configurations and disks for later use, similar to Docker images.
|
||||
|
||||
#### Save VM to Repository
|
||||
```bash
|
||||
easyqemu repo save <vm_id> [repo_name]
|
||||
```
|
||||
|
||||
#### Load VM from Repository
|
||||
```bash
|
||||
easyqemu repo load <repo_name> [new_name]
|
||||
```
|
||||
|
||||
This creates a new VM instance from the saved configuration.
|
||||
|
||||
#### List Repository Entries
|
||||
```bash
|
||||
easyqemu repo list
|
||||
```
|
||||
|
||||
#### Delete Repository Entry
|
||||
```bash
|
||||
easyqemu repo delete <repo_name> [-f|--force]
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Example 1: Create and Run Ubuntu VM
|
||||
|
||||
```bash
|
||||
# Download Ubuntu ISO (example)
|
||||
wget https://releases.ubuntu.com/22.04/ubuntu-22.04.3-desktop-amd64.iso
|
||||
|
||||
# Create VM
|
||||
easyqemu vm create \
|
||||
--name ubuntu-desktop \
|
||||
--memory 4096 \
|
||||
--cpus 4 \
|
||||
--disk-size 50G \
|
||||
--cdrom ubuntu-22.04.3-desktop-amd64.iso
|
||||
|
||||
# List VMs to get the ID
|
||||
easyqemu vm list
|
||||
|
||||
# Start the VM
|
||||
easyqemu vm start ubuntu-desktop_1704672000
|
||||
|
||||
# After installation, modify to boot from hard disk
|
||||
easyqemu vm modify ubuntu-desktop_1704672000 --boot hd --cdrom ""
|
||||
```
|
||||
|
||||
### Example 2: Create a Snapshot Before Updates
|
||||
|
||||
```bash
|
||||
# Create a snapshot before system updates
|
||||
easyqemu snapshot create myvm_1704672000 before_update
|
||||
|
||||
# Start VM and perform updates
|
||||
easyqemu vm start myvm_1704672000
|
||||
|
||||
# If something goes wrong, restore the snapshot
|
||||
easyqemu snapshot apply myvm_1704672000 before_update
|
||||
```
|
||||
|
||||
### Example 3: Save and Clone a VM
|
||||
|
||||
```bash
|
||||
# Save VM to repository
|
||||
easyqemu repo save myvm_1704672000 my_base_vm
|
||||
|
||||
# Load it with a new name (creates a clone)
|
||||
easyqemu repo load my_base_vm cloned_vm
|
||||
|
||||
# List to see the new VM
|
||||
easyqemu vm list
|
||||
```
|
||||
|
||||
### Example 4: Convert Disk Formats
|
||||
|
||||
```bash
|
||||
# Convert qcow2 to raw
|
||||
easyqemu volume convert \
|
||||
--source ~/.easyqemu/volumes/myvm.qcow2 \
|
||||
--target ~/myvm.raw \
|
||||
--format raw
|
||||
|
||||
# Convert to VMDK for VMware
|
||||
easyqemu volume convert \
|
||||
--source ~/.easyqemu/volumes/myvm.qcow2 \
|
||||
--target ~/myvm.vmdk \
|
||||
--format vmdk
|
||||
|
||||
# Convert to VDI for VirtualBox
|
||||
easyqemu volume convert \
|
||||
--source ~/.easyqemu/volumes/myvm.qcow2 \
|
||||
--target ~/myvm.vdi \
|
||||
--format vdi
|
||||
```
|
||||
|
||||
### Example 5: Import Existing Disk
|
||||
|
||||
```bash
|
||||
# Import an existing disk
|
||||
easyqemu volume import /path/to/existing-disk.qcow2 imported-disk.qcow2
|
||||
|
||||
# Create a VM using the imported disk
|
||||
easyqemu vm create \
|
||||
--name imported-vm \
|
||||
--disk ~/.easyqemu/volumes/imported-disk.qcow2 \
|
||||
--boot hd
|
||||
```
|
||||
|
||||
## Directory Structure
|
||||
|
||||
EasyQEMU stores all data in `~/.easyqemu/`:
|
||||
|
||||
```
|
||||
~/.easyqemu/
|
||||
├── vms/ # VM runtime data
|
||||
├── volumes/ # Disk images
|
||||
├── configs/ # VM configurations (JSON)
|
||||
├── repository/ # Saved VMs
|
||||
├── locks/ # Lock files for running VMs
|
||||
└── easyqemu.log # Log file
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
EasyQEMU can be configured via environment variables or by editing `~/.easyqemu/config`:
|
||||
|
||||
```bash
|
||||
# Custom home directory
|
||||
export EASYQEMU_HOME="/path/to/custom/location"
|
||||
|
||||
# Default settings
|
||||
export DEFAULT_MEMORY="4096"
|
||||
export DEFAULT_CPUS="4"
|
||||
export DEFAULT_DISK_SIZE="50G"
|
||||
```
|
||||
|
||||
## Network Modes
|
||||
|
||||
EasyQEMU supports different network modes:
|
||||
|
||||
- **user**: Default, user-mode networking (NAT)
|
||||
- **bridge**: Bridge networking (requires setup)
|
||||
- **tap**: TAP device networking
|
||||
|
||||
Example with bridge:
|
||||
```bash
|
||||
easyqemu vm create --name myvm --network bridge,br0
|
||||
```
|
||||
|
||||
## Display Options
|
||||
|
||||
- **gtk**: GTK window (default, best for desktop)
|
||||
- **sdl**: SDL window
|
||||
- **vnc**: VNC server (headless)
|
||||
- **none**: No display (serial console only)
|
||||
|
||||
Example with VNC:
|
||||
```bash
|
||||
easyqemu vm create --name myvm --display vnc=:1
|
||||
```
|
||||
|
||||
## Advanced Features
|
||||
|
||||
### Custom QEMU Arguments
|
||||
|
||||
You can pass additional QEMU arguments when creating a VM:
|
||||
|
||||
```bash
|
||||
easyqemu vm create \
|
||||
--name myvm \
|
||||
--memory 4096 \
|
||||
-- \
|
||||
-vga qxl \
|
||||
-device usb-tablet
|
||||
```
|
||||
|
||||
### USB Passthrough
|
||||
|
||||
```bash
|
||||
easyqemu vm create \
|
||||
--name myvm \
|
||||
-- \
|
||||
-usb \
|
||||
-device usb-host,vendorid=0x1234,productid=0x5678
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### KVM Not Available
|
||||
|
||||
If you see errors about KVM:
|
||||
|
||||
1. Check if KVM is enabled:
|
||||
```bash
|
||||
lsmod | grep kvm
|
||||
```
|
||||
|
||||
2. Check if your CPU supports virtualization:
|
||||
```bash
|
||||
egrep -c '(vmx|svm)' /proc/cpuinfo
|
||||
```
|
||||
|
||||
3. Add your user to the kvm group:
|
||||
```bash
|
||||
sudo usermod -a -G kvm $USER
|
||||
```
|
||||
|
||||
### Permission Denied
|
||||
|
||||
If you get permission errors:
|
||||
|
||||
```bash
|
||||
sudo chmod 666 /dev/kvm
|
||||
```
|
||||
|
||||
Or add yourself to the kvm group (recommended):
|
||||
|
||||
```bash
|
||||
sudo usermod -a -G kvm $USER
|
||||
# Log out and log back in
|
||||
```
|
||||
|
||||
### VM Won't Start
|
||||
|
||||
1. Check if the disk exists:
|
||||
```bash
|
||||
easyqemu vm info <vm_id>
|
||||
```
|
||||
|
||||
2. Check disk integrity:
|
||||
```bash
|
||||
easyqemu volume info <disk_path>
|
||||
```
|
||||
|
||||
3. Check available memory:
|
||||
```bash
|
||||
free -h
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Please feel free to submit issues or pull requests.
|
||||
|
||||
## License
|
||||
|
||||
MIT License - See LICENSE file for details
|
||||
|
||||
## Credits
|
||||
|
||||
EasyQEMU is built on top of QEMU/KVM and provides a user-friendly interface for common VM management tasks.
|
||||
|
||||
## Roadmap
|
||||
|
||||
- [ ] Support for Windows VMs (UEFI boot)
|
||||
- [ ] Web UI dashboard
|
||||
- [ ] Remote VM management
|
||||
- [ ] Automated ISO downloads
|
||||
- [ ] Cloud-init integration
|
||||
- [ ] Network configuration wizard
|
||||
- [ ] Resource monitoring
|
||||
- [ ] Backup and restore
|
||||
- [ ] VM templates library
|
||||
|
||||
## FAQ
|
||||
|
||||
**Q: Can I use existing QEMU disk images?**
|
||||
A: Yes! Use `easyqemu volume import` to import existing disks.
|
||||
|
||||
**Q: How do I access a VM without a display?**
|
||||
A: Use `--display none` and connect via SSH or serial console.
|
||||
|
||||
**Q: Can I run multiple VMs simultaneously?**
|
||||
A: Yes, just start multiple VMs with different IDs.
|
||||
|
||||
**Q: How do I increase disk size?**
|
||||
A: Use `qemu-img resize` directly:
|
||||
```bash
|
||||
qemu-img resize disk.qcow2 +10G
|
||||
```
|
||||
|
||||
**Q: Can I use this for production?**
|
||||
A: EasyQEMU is designed for development and testing. For production, consider enterprise solutions like libvirt/virt-manager.
|
||||
|
||||
## See Also
|
||||
|
||||
- [QEMU Documentation](https://www.qemu.org/documentation/)
|
||||
- [KVM Documentation](https://www.linux-kvm.org/)
|
||||
- [libvirt](https://libvirt.org/) - Alternative VM management
|
||||
|
||||
---
|
||||
|
||||
**EasyQEMU** - Making QEMU management easy! 🚀
|
||||
958
easyqemu
Archivo ejecutable
958
easyqemu
Archivo ejecutable
@@ -0,0 +1,958 @@
|
||||
#!/bin/bash
|
||||
|
||||
##############################################################################
|
||||
# EasyQEMU - Intuitive QEMU Virtual Machine Management Tool
|
||||
#
|
||||
# A comprehensive tool for managing QEMU virtual machines with features like:
|
||||
# - VM creation, modification, deletion
|
||||
# - Volume management (create, import, export, convert)
|
||||
# - Snapshot management
|
||||
# - Repository system for VMs and volumes (Docker-like registry)
|
||||
# - Support for multiple disk formats (raw, qcow2, vmdk, vdi, vhdx)
|
||||
#
|
||||
# Author: EasyQEMU Project
|
||||
# License: MIT
|
||||
##############################################################################
|
||||
|
||||
set -e
|
||||
|
||||
# Version
|
||||
VERSION="1.0.0"
|
||||
|
||||
# Default paths
|
||||
EASYQEMU_HOME="${EASYQEMU_HOME:-$HOME/.easyqemu}"
|
||||
EASYQEMU_VMS="$EASYQEMU_HOME/vms"
|
||||
EASYQEMU_VOLUMES="$EASYQEMU_HOME/volumes"
|
||||
EASYQEMU_CONFIGS="$EASYQEMU_HOME/configs"
|
||||
EASYQEMU_REPO="$EASYQEMU_HOME/repository"
|
||||
EASYQEMU_LOCKS="$EASYQEMU_HOME/locks"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
MAGENTA='\033[0;35m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
##############################################################################
|
||||
# Utility Functions
|
||||
##############################################################################
|
||||
|
||||
info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1" >&2
|
||||
}
|
||||
|
||||
fatal() {
|
||||
error "$1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Initialize EasyQEMU directories
|
||||
init_dirs() {
|
||||
mkdir -p "$EASYQEMU_HOME"
|
||||
mkdir -p "$EASYQEMU_VMS"
|
||||
mkdir -p "$EASYQEMU_VOLUMES"
|
||||
mkdir -p "$EASYQEMU_CONFIGS"
|
||||
mkdir -p "$EASYQEMU_REPO"
|
||||
mkdir -p "$EASYQEMU_LOCKS"
|
||||
}
|
||||
|
||||
# Check if QEMU is installed
|
||||
check_qemu() {
|
||||
if ! command -v qemu-system-x86_64 &> /dev/null; then
|
||||
fatal "QEMU is not installed. Please install qemu-system-x86_64"
|
||||
fi
|
||||
if ! command -v qemu-img &> /dev/null; then
|
||||
fatal "qemu-img is not installed. Please install qemu-utils"
|
||||
fi
|
||||
}
|
||||
|
||||
# Generate VM ID
|
||||
generate_vm_id() {
|
||||
local name="$1"
|
||||
echo "${name}_$(date +%s)"
|
||||
}
|
||||
|
||||
# Save VM configuration
|
||||
save_vm_config() {
|
||||
local vm_id="$1"
|
||||
local config_file="$EASYQEMU_CONFIGS/${vm_id}.json"
|
||||
shift
|
||||
|
||||
cat > "$config_file" << EOF
|
||||
{
|
||||
"id": "$vm_id",
|
||||
"name": "${VM_NAME:-unknown}",
|
||||
"created": "$(date -Iseconds)",
|
||||
"memory": "${VM_MEMORY:-2048}",
|
||||
"cpus": "${VM_CPUS:-2}",
|
||||
"disk": "${VM_DISK:-}",
|
||||
"cdrom": "${VM_CDROM:-}",
|
||||
"network": "${VM_NETWORK:-user}",
|
||||
"display": "${VM_DISPLAY:-gtk}",
|
||||
"boot": "${VM_BOOT:-cd}",
|
||||
"additional_args": "${VM_ADDITIONAL_ARGS:-}"
|
||||
}
|
||||
EOF
|
||||
success "Configuration saved: $config_file"
|
||||
}
|
||||
|
||||
# Load VM configuration
|
||||
load_vm_config() {
|
||||
local vm_id="$1"
|
||||
local config_file="$EASYQEMU_CONFIGS/${vm_id}.json"
|
||||
|
||||
if [[ ! -f "$config_file" ]]; then
|
||||
error "Configuration not found for VM: $vm_id"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Parse JSON (simple extraction)
|
||||
VM_NAME=$(grep '"name"' "$config_file" | cut -d'"' -f4)
|
||||
VM_MEMORY=$(grep '"memory"' "$config_file" | cut -d'"' -f4)
|
||||
VM_CPUS=$(grep '"cpus"' "$config_file" | cut -d'"' -f4)
|
||||
VM_DISK=$(grep '"disk"' "$config_file" | cut -d'"' -f4)
|
||||
VM_CDROM=$(grep '"cdrom"' "$config_file" | cut -d'"' -f4)
|
||||
VM_NETWORK=$(grep '"network"' "$config_file" | cut -d'"' -f4)
|
||||
VM_DISPLAY=$(grep '"display"' "$config_file" | cut -d'"' -f4)
|
||||
VM_BOOT=$(grep '"boot"' "$config_file" | cut -d'"' -f4)
|
||||
VM_ADDITIONAL_ARGS=$(grep '"additional_args"' "$config_file" | cut -d'"' -f4)
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# VM Management Functions
|
||||
##############################################################################
|
||||
|
||||
# Create a new VM
|
||||
vm_create() {
|
||||
local name=""
|
||||
local memory="2048"
|
||||
local cpus="2"
|
||||
local disk=""
|
||||
local disk_size="20G"
|
||||
local cdrom=""
|
||||
local network="user"
|
||||
local display="gtk"
|
||||
local boot="cd"
|
||||
local additional_args=""
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--name)
|
||||
name="$2"
|
||||
shift 2
|
||||
;;
|
||||
--memory)
|
||||
memory="$2"
|
||||
shift 2
|
||||
;;
|
||||
--cpus)
|
||||
cpus="$2"
|
||||
shift 2
|
||||
;;
|
||||
--disk)
|
||||
disk="$2"
|
||||
shift 2
|
||||
;;
|
||||
--disk-size)
|
||||
disk_size="$2"
|
||||
shift 2
|
||||
;;
|
||||
--cdrom)
|
||||
cdrom="$2"
|
||||
shift 2
|
||||
;;
|
||||
--network)
|
||||
network="$2"
|
||||
shift 2
|
||||
;;
|
||||
--display)
|
||||
display="$2"
|
||||
shift 2
|
||||
;;
|
||||
--boot)
|
||||
boot="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
additional_args="$additional_args $1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ -z "$name" ]] && fatal "VM name is required. Use --name <name>"
|
||||
|
||||
info "Creating VM: $name"
|
||||
|
||||
# Generate VM ID
|
||||
local vm_id=$(generate_vm_id "$name")
|
||||
|
||||
# Create disk if not provided
|
||||
if [[ -z "$disk" ]]; then
|
||||
disk="$EASYQEMU_VOLUMES/${vm_id}.qcow2"
|
||||
info "Creating disk: $disk ($disk_size)"
|
||||
qemu-img create -f qcow2 "$disk" "$disk_size"
|
||||
fi
|
||||
|
||||
# Save configuration
|
||||
VM_NAME="$name"
|
||||
VM_MEMORY="$memory"
|
||||
VM_CPUS="$cpus"
|
||||
VM_DISK="$disk"
|
||||
VM_CDROM="$cdrom"
|
||||
VM_NETWORK="$network"
|
||||
VM_DISPLAY="$display"
|
||||
VM_BOOT="$boot"
|
||||
VM_ADDITIONAL_ARGS="$additional_args"
|
||||
|
||||
save_vm_config "$vm_id"
|
||||
|
||||
success "VM created successfully: $vm_id"
|
||||
echo "Use 'easyqemu vm start $vm_id' to start the VM"
|
||||
}
|
||||
|
||||
# List VMs
|
||||
vm_list() {
|
||||
info "Available VMs:"
|
||||
echo ""
|
||||
printf "%-30s %-20s %-15s %-10s %-10s\n" "VM ID" "NAME" "CREATED" "MEMORY" "CPUS"
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
|
||||
for config in "$EASYQEMU_CONFIGS"/*.json; do
|
||||
[[ ! -f "$config" ]] && continue
|
||||
|
||||
local vm_id=$(basename "$config" .json)
|
||||
load_vm_config "$vm_id"
|
||||
|
||||
local created=$(grep '"created"' "$config" | cut -d'"' -f4 | cut -d'T' -f1)
|
||||
printf "%-30s %-20s %-15s %-10s %-10s\n" "$vm_id" "$VM_NAME" "$created" "${VM_MEMORY}M" "$VM_CPUS"
|
||||
done
|
||||
}
|
||||
|
||||
# Start VM
|
||||
vm_start() {
|
||||
local vm_id="$1"
|
||||
[[ -z "$vm_id" ]] && fatal "VM ID is required"
|
||||
|
||||
load_vm_config "$vm_id" || fatal "Failed to load VM configuration"
|
||||
|
||||
info "Starting VM: $vm_id ($VM_NAME)"
|
||||
|
||||
# Build QEMU command
|
||||
local qemu_cmd="qemu-system-x86_64"
|
||||
qemu_cmd="$qemu_cmd -name $VM_NAME"
|
||||
qemu_cmd="$qemu_cmd -m $VM_MEMORY"
|
||||
qemu_cmd="$qemu_cmd -smp $VM_CPUS"
|
||||
qemu_cmd="$qemu_cmd -enable-kvm"
|
||||
|
||||
# Disk
|
||||
if [[ -n "$VM_DISK" ]]; then
|
||||
qemu_cmd="$qemu_cmd -drive file=$VM_DISK,format=qcow2,if=virtio"
|
||||
fi
|
||||
|
||||
# CDROM
|
||||
if [[ -n "$VM_CDROM" ]]; then
|
||||
qemu_cmd="$qemu_cmd -cdrom $VM_CDROM"
|
||||
fi
|
||||
|
||||
# Network
|
||||
qemu_cmd="$qemu_cmd -net nic -net $VM_NETWORK"
|
||||
|
||||
# Display
|
||||
if [[ "$VM_DISPLAY" == "none" ]]; then
|
||||
qemu_cmd="$qemu_cmd -nographic"
|
||||
else
|
||||
qemu_cmd="$qemu_cmd -display $VM_DISPLAY"
|
||||
fi
|
||||
|
||||
# Boot
|
||||
qemu_cmd="$qemu_cmd -boot $VM_BOOT"
|
||||
|
||||
# Additional args
|
||||
if [[ -n "$VM_ADDITIONAL_ARGS" ]]; then
|
||||
qemu_cmd="$qemu_cmd $VM_ADDITIONAL_ARGS"
|
||||
fi
|
||||
|
||||
info "Executing: $qemu_cmd"
|
||||
eval "$qemu_cmd"
|
||||
}
|
||||
|
||||
# Delete VM
|
||||
vm_delete() {
|
||||
local vm_id="$1"
|
||||
local force="$2"
|
||||
|
||||
[[ -z "$vm_id" ]] && fatal "VM ID is required"
|
||||
|
||||
local config_file="$EASYQEMU_CONFIGS/${vm_id}.json"
|
||||
[[ ! -f "$config_file" ]] && fatal "VM not found: $vm_id"
|
||||
|
||||
load_vm_config "$vm_id"
|
||||
|
||||
if [[ "$force" != "-f" ]] && [[ "$force" != "--force" ]]; then
|
||||
read -p "Delete VM '$VM_NAME' ($vm_id)? This will remove the disk. [y/N] " -n 1 -r
|
||||
echo
|
||||
[[ ! $REPLY =~ ^[Yy]$ ]] && fatal "Deletion cancelled"
|
||||
fi
|
||||
|
||||
info "Deleting VM: $vm_id"
|
||||
|
||||
# Remove disk if it exists
|
||||
if [[ -f "$VM_DISK" ]]; then
|
||||
rm -f "$VM_DISK"
|
||||
success "Disk removed: $VM_DISK"
|
||||
fi
|
||||
|
||||
# Remove configuration
|
||||
rm -f "$config_file"
|
||||
|
||||
success "VM deleted: $vm_id"
|
||||
}
|
||||
|
||||
# Show VM info
|
||||
vm_info() {
|
||||
local vm_id="$1"
|
||||
[[ -z "$vm_id" ]] && fatal "VM ID is required"
|
||||
|
||||
local config_file="$EASYQEMU_CONFIGS/${vm_id}.json"
|
||||
[[ ! -f "$config_file" ]] && fatal "VM not found: $vm_id"
|
||||
|
||||
info "VM Information:"
|
||||
echo ""
|
||||
cat "$config_file" | sed 's/^/ /'
|
||||
}
|
||||
|
||||
# Modify VM
|
||||
vm_modify() {
|
||||
local vm_id="$1"
|
||||
shift
|
||||
|
||||
[[ -z "$vm_id" ]] && fatal "VM ID is required"
|
||||
|
||||
load_vm_config "$vm_id" || fatal "Failed to load VM configuration"
|
||||
|
||||
# Parse modification arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--name)
|
||||
VM_NAME="$2"
|
||||
shift 2
|
||||
;;
|
||||
--memory)
|
||||
VM_MEMORY="$2"
|
||||
shift 2
|
||||
;;
|
||||
--cpus)
|
||||
VM_CPUS="$2"
|
||||
shift 2
|
||||
;;
|
||||
--cdrom)
|
||||
VM_CDROM="$2"
|
||||
shift 2
|
||||
;;
|
||||
--network)
|
||||
VM_NETWORK="$2"
|
||||
shift 2
|
||||
;;
|
||||
--display)
|
||||
VM_DISPLAY="$2"
|
||||
shift 2
|
||||
;;
|
||||
--boot)
|
||||
VM_BOOT="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
warning "Unknown option: $1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
save_vm_config "$vm_id"
|
||||
success "VM modified: $vm_id"
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Volume Management Functions
|
||||
##############################################################################
|
||||
|
||||
# Create volume
|
||||
volume_create() {
|
||||
local name=""
|
||||
local size="10G"
|
||||
local format="qcow2"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--name)
|
||||
name="$2"
|
||||
shift 2
|
||||
;;
|
||||
--size)
|
||||
size="$2"
|
||||
shift 2
|
||||
;;
|
||||
--format)
|
||||
format="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ -z "$name" ]] && fatal "Volume name is required. Use --name <name>"
|
||||
|
||||
local volume_path="$EASYQEMU_VOLUMES/${name}.${format}"
|
||||
|
||||
info "Creating volume: $volume_path ($size)"
|
||||
qemu-img create -f "$format" "$volume_path" "$size"
|
||||
|
||||
success "Volume created: $volume_path"
|
||||
}
|
||||
|
||||
# List volumes
|
||||
volume_list() {
|
||||
info "Available volumes:"
|
||||
echo ""
|
||||
printf "%-40s %-10s %-15s %-15s\n" "NAME" "FORMAT" "SIZE" "ACTUAL SIZE"
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
|
||||
for volume in "$EASYQEMU_VOLUMES"/*; do
|
||||
[[ ! -f "$volume" ]] && continue
|
||||
|
||||
local name=$(basename "$volume")
|
||||
local info=$(qemu-img info "$volume")
|
||||
local format=$(echo "$info" | grep "file format:" | awk '{print $3}')
|
||||
local vsize=$(echo "$info" | grep "virtual size:" | awk '{print $3}')
|
||||
local dsize=$(echo "$info" | grep "disk size:" | awk '{print $3}')
|
||||
|
||||
printf "%-40s %-10s %-15s %-15s\n" "$name" "$format" "$vsize" "$dsize"
|
||||
done
|
||||
}
|
||||
|
||||
# Convert volume
|
||||
volume_convert() {
|
||||
local source=""
|
||||
local target=""
|
||||
local format="qcow2"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--source)
|
||||
source="$2"
|
||||
shift 2
|
||||
;;
|
||||
--target)
|
||||
target="$2"
|
||||
shift 2
|
||||
;;
|
||||
--format)
|
||||
format="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ -z "$source" ]] && fatal "Source volume is required. Use --source <path>"
|
||||
[[ -z "$target" ]] && fatal "Target volume is required. Use --target <path>"
|
||||
|
||||
info "Converting: $source -> $target (format: $format)"
|
||||
qemu-img convert -f raw -O "$format" "$source" "$target"
|
||||
|
||||
success "Volume converted: $target"
|
||||
}
|
||||
|
||||
# Volume info
|
||||
volume_info() {
|
||||
local volume="$1"
|
||||
[[ -z "$volume" ]] && fatal "Volume path is required"
|
||||
|
||||
[[ ! -f "$volume" ]] && fatal "Volume not found: $volume"
|
||||
|
||||
info "Volume Information:"
|
||||
echo ""
|
||||
qemu-img info "$volume"
|
||||
}
|
||||
|
||||
# Import volume
|
||||
volume_import() {
|
||||
local source="$1"
|
||||
local name="$2"
|
||||
|
||||
[[ -z "$source" ]] && fatal "Source path is required"
|
||||
[[ -z "$name" ]] && name=$(basename "$source")
|
||||
|
||||
local target="$EASYQEMU_VOLUMES/$name"
|
||||
|
||||
info "Importing volume: $source -> $target"
|
||||
cp "$source" "$target"
|
||||
|
||||
success "Volume imported: $target"
|
||||
}
|
||||
|
||||
# Export volume
|
||||
volume_export() {
|
||||
local name="$1"
|
||||
local target="$2"
|
||||
|
||||
[[ -z "$name" ]] && fatal "Volume name is required"
|
||||
[[ -z "$target" ]] && fatal "Target path is required"
|
||||
|
||||
local source="$EASYQEMU_VOLUMES/$name"
|
||||
[[ ! -f "$source" ]] && fatal "Volume not found: $name"
|
||||
|
||||
info "Exporting volume: $source -> $target"
|
||||
cp "$source" "$target"
|
||||
|
||||
success "Volume exported: $target"
|
||||
}
|
||||
|
||||
# Delete volume
|
||||
volume_delete() {
|
||||
local name="$1"
|
||||
local force="$2"
|
||||
|
||||
[[ -z "$name" ]] && fatal "Volume name is required"
|
||||
|
||||
local volume_path="$EASYQEMU_VOLUMES/$name"
|
||||
[[ ! -f "$volume_path" ]] && fatal "Volume not found: $name"
|
||||
|
||||
if [[ "$force" != "-f" ]] && [[ "$force" != "--force" ]]; then
|
||||
read -p "Delete volume '$name'? [y/N] " -n 1 -r
|
||||
echo
|
||||
[[ ! $REPLY =~ ^[Yy]$ ]] && fatal "Deletion cancelled"
|
||||
fi
|
||||
|
||||
rm -f "$volume_path"
|
||||
success "Volume deleted: $name"
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Snapshot Management Functions
|
||||
##############################################################################
|
||||
|
||||
# Create snapshot
|
||||
snapshot_create() {
|
||||
local vm_id="$1"
|
||||
local snapshot_name="$2"
|
||||
|
||||
[[ -z "$vm_id" ]] && fatal "VM ID is required"
|
||||
[[ -z "$snapshot_name" ]] && snapshot_name="snapshot_$(date +%Y%m%d_%H%M%S)"
|
||||
|
||||
load_vm_config "$vm_id" || fatal "Failed to load VM configuration"
|
||||
|
||||
[[ ! -f "$VM_DISK" ]] && fatal "Disk not found: $VM_DISK"
|
||||
|
||||
info "Creating snapshot: $snapshot_name for VM: $vm_id"
|
||||
qemu-img snapshot -c "$snapshot_name" "$VM_DISK"
|
||||
|
||||
success "Snapshot created: $snapshot_name"
|
||||
}
|
||||
|
||||
# List snapshots
|
||||
snapshot_list() {
|
||||
local vm_id="$1"
|
||||
|
||||
[[ -z "$vm_id" ]] && fatal "VM ID is required"
|
||||
|
||||
load_vm_config "$vm_id" || fatal "Failed to load VM configuration"
|
||||
|
||||
[[ ! -f "$VM_DISK" ]] && fatal "Disk not found: $VM_DISK"
|
||||
|
||||
info "Snapshots for VM: $vm_id ($VM_DISK)"
|
||||
echo ""
|
||||
qemu-img snapshot -l "$VM_DISK"
|
||||
}
|
||||
|
||||
# Apply snapshot
|
||||
snapshot_apply() {
|
||||
local vm_id="$1"
|
||||
local snapshot_name="$2"
|
||||
|
||||
[[ -z "$vm_id" ]] && fatal "VM ID is required"
|
||||
[[ -z "$snapshot_name" ]] && fatal "Snapshot name is required"
|
||||
|
||||
load_vm_config "$vm_id" || fatal "Failed to load VM configuration"
|
||||
|
||||
[[ ! -f "$VM_DISK" ]] && fatal "Disk not found: $VM_DISK"
|
||||
|
||||
info "Applying snapshot: $snapshot_name for VM: $vm_id"
|
||||
qemu-img snapshot -a "$snapshot_name" "$VM_DISK"
|
||||
|
||||
success "Snapshot applied: $snapshot_name"
|
||||
}
|
||||
|
||||
# Delete snapshot
|
||||
snapshot_delete() {
|
||||
local vm_id="$1"
|
||||
local snapshot_name="$2"
|
||||
|
||||
[[ -z "$vm_id" ]] && fatal "VM ID is required"
|
||||
[[ -z "$snapshot_name" ]] && fatal "Snapshot name is required"
|
||||
|
||||
load_vm_config "$vm_id" || fatal "Failed to load VM configuration"
|
||||
|
||||
[[ ! -f "$VM_DISK" ]] && fatal "Disk not found: $VM_DISK"
|
||||
|
||||
info "Deleting snapshot: $snapshot_name for VM: $vm_id"
|
||||
qemu-img snapshot -d "$snapshot_name" "$VM_DISK"
|
||||
|
||||
success "Snapshot deleted: $snapshot_name"
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Repository Management Functions
|
||||
##############################################################################
|
||||
|
||||
# Save VM to repository
|
||||
repo_save() {
|
||||
local vm_id="$1"
|
||||
local repo_name="$2"
|
||||
|
||||
[[ -z "$vm_id" ]] && fatal "VM ID is required"
|
||||
[[ -z "$repo_name" ]] && repo_name="$vm_id"
|
||||
|
||||
load_vm_config "$vm_id" || fatal "Failed to load VM configuration"
|
||||
|
||||
local repo_dir="$EASYQEMU_REPO/$repo_name"
|
||||
mkdir -p "$repo_dir"
|
||||
|
||||
info "Saving VM to repository: $repo_name"
|
||||
|
||||
# Copy configuration
|
||||
cp "$EASYQEMU_CONFIGS/${vm_id}.json" "$repo_dir/config.json"
|
||||
|
||||
# Copy disk
|
||||
if [[ -f "$VM_DISK" ]]; then
|
||||
cp "$VM_DISK" "$repo_dir/disk.qcow2"
|
||||
fi
|
||||
|
||||
# Create metadata
|
||||
cat > "$repo_dir/metadata.json" << EOF
|
||||
{
|
||||
"name": "$repo_name",
|
||||
"original_vm_id": "$vm_id",
|
||||
"saved": "$(date -Iseconds)",
|
||||
"version": "1.0"
|
||||
}
|
||||
EOF
|
||||
|
||||
success "VM saved to repository: $repo_name"
|
||||
}
|
||||
|
||||
# Load VM from repository
|
||||
repo_load() {
|
||||
local repo_name="$1"
|
||||
local new_name="$2"
|
||||
|
||||
[[ -z "$repo_name" ]] && fatal "Repository name is required"
|
||||
|
||||
local repo_dir="$EASYQEMU_REPO/$repo_name"
|
||||
[[ ! -d "$repo_dir" ]] && fatal "Repository not found: $repo_name"
|
||||
|
||||
# Generate new VM ID
|
||||
local vm_id=$(generate_vm_id "${new_name:-$repo_name}")
|
||||
|
||||
info "Loading VM from repository: $repo_name -> $vm_id"
|
||||
|
||||
# Copy configuration
|
||||
cp "$repo_dir/config.json" "$EASYQEMU_CONFIGS/${vm_id}.json"
|
||||
|
||||
# Update VM ID in config
|
||||
sed -i "s/\"id\": \"[^\"]*\"/\"id\": \"$vm_id\"/" "$EASYQEMU_CONFIGS/${vm_id}.json"
|
||||
|
||||
if [[ -n "$new_name" ]]; then
|
||||
sed -i "s/\"name\": \"[^\"]*\"/\"name\": \"$new_name\"/" "$EASYQEMU_CONFIGS/${vm_id}.json"
|
||||
fi
|
||||
|
||||
# Copy disk
|
||||
if [[ -f "$repo_dir/disk.qcow2" ]]; then
|
||||
cp "$repo_dir/disk.qcow2" "$EASYQEMU_VOLUMES/${vm_id}.qcow2"
|
||||
sed -i "s|\"disk\": \"[^\"]*\"|\"disk\": \"$EASYQEMU_VOLUMES/${vm_id}.qcow2\"|" "$EASYQEMU_CONFIGS/${vm_id}.json"
|
||||
fi
|
||||
|
||||
success "VM loaded from repository: $vm_id"
|
||||
echo "Use 'easyqemu vm start $vm_id' to start the VM"
|
||||
}
|
||||
|
||||
# List repository entries
|
||||
repo_list() {
|
||||
info "Repository entries:"
|
||||
echo ""
|
||||
printf "%-30s %-20s\n" "NAME" "SAVED"
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
|
||||
for repo_dir in "$EASYQEMU_REPO"/*; do
|
||||
[[ ! -d "$repo_dir" ]] && continue
|
||||
|
||||
local name=$(basename "$repo_dir")
|
||||
local metadata="$repo_dir/metadata.json"
|
||||
|
||||
if [[ -f "$metadata" ]]; then
|
||||
local saved=$(grep '"saved"' "$metadata" | cut -d'"' -f4 | cut -d'T' -f1)
|
||||
printf "%-30s %-20s\n" "$name" "$saved"
|
||||
else
|
||||
printf "%-30s %-20s\n" "$name" "unknown"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Delete repository entry
|
||||
repo_delete() {
|
||||
local repo_name="$1"
|
||||
local force="$2"
|
||||
|
||||
[[ -z "$repo_name" ]] && fatal "Repository name is required"
|
||||
|
||||
local repo_dir="$EASYQEMU_REPO/$repo_name"
|
||||
[[ ! -d "$repo_dir" ]] && fatal "Repository not found: $repo_name"
|
||||
|
||||
if [[ "$force" != "-f" ]] && [[ "$force" != "--force" ]]; then
|
||||
read -p "Delete repository entry '$repo_name'? [y/N] " -n 1 -r
|
||||
echo
|
||||
[[ ! $REPLY =~ ^[Yy]$ ]] && fatal "Deletion cancelled"
|
||||
fi
|
||||
|
||||
rm -rf "$repo_dir"
|
||||
success "Repository entry deleted: $repo_name"
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Main Command Dispatcher
|
||||
##############################################################################
|
||||
|
||||
show_help() {
|
||||
cat << EOF
|
||||
EasyQEMU v${VERSION} - Intuitive QEMU Virtual Machine Management
|
||||
|
||||
USAGE:
|
||||
easyqemu <command> [options]
|
||||
|
||||
COMMANDS:
|
||||
VM Management:
|
||||
vm create Create a new virtual machine
|
||||
vm list List all virtual machines
|
||||
vm start Start a virtual machine
|
||||
vm stop Stop a virtual machine (use QEMU controls)
|
||||
vm delete Delete a virtual machine
|
||||
vm info Show VM information
|
||||
vm modify Modify VM configuration
|
||||
|
||||
Volume Management:
|
||||
volume create Create a new volume
|
||||
volume list List all volumes
|
||||
volume info Show volume information
|
||||
volume convert Convert volume format
|
||||
volume import Import external volume
|
||||
volume export Export volume
|
||||
volume delete Delete a volume
|
||||
|
||||
Snapshot Management:
|
||||
snapshot create Create a snapshot
|
||||
snapshot list List snapshots for a VM
|
||||
snapshot apply Apply/restore a snapshot
|
||||
snapshot delete Delete a snapshot
|
||||
|
||||
Repository Management:
|
||||
repo save Save VM to repository
|
||||
repo load Load VM from repository
|
||||
repo list List repository entries
|
||||
repo delete Delete repository entry
|
||||
|
||||
Other:
|
||||
version Show version information
|
||||
help Show this help message
|
||||
|
||||
EXAMPLES:
|
||||
# Create a new VM
|
||||
easyqemu vm create --name ubuntu --memory 4096 --cpus 4 --disk-size 50G
|
||||
|
||||
# Start VM with ISO
|
||||
easyqemu vm create --name test --cdrom /path/to/iso
|
||||
easyqemu vm start test_<timestamp>
|
||||
|
||||
# List VMs
|
||||
easyqemu vm list
|
||||
|
||||
# Create snapshot
|
||||
easyqemu snapshot create <vm_id> my_snapshot
|
||||
|
||||
# Save VM to repository
|
||||
easyqemu repo save <vm_id> my_saved_vm
|
||||
|
||||
# Convert volume
|
||||
easyqemu volume convert --source disk.raw --target disk.qcow2 --format qcow2
|
||||
|
||||
For more information, see the README.md file.
|
||||
EOF
|
||||
}
|
||||
|
||||
show_version() {
|
||||
echo "EasyQEMU version $VERSION"
|
||||
}
|
||||
|
||||
main() {
|
||||
# Initialize
|
||||
init_dirs
|
||||
check_qemu
|
||||
|
||||
# Parse command
|
||||
local command="${1:-help}"
|
||||
shift || true
|
||||
|
||||
case "$command" in
|
||||
vm)
|
||||
local subcommand="${1:-list}"
|
||||
shift || true
|
||||
|
||||
case "$subcommand" in
|
||||
create)
|
||||
vm_create "$@"
|
||||
;;
|
||||
list)
|
||||
vm_list "$@"
|
||||
;;
|
||||
start)
|
||||
vm_start "$@"
|
||||
;;
|
||||
delete)
|
||||
vm_delete "$@"
|
||||
;;
|
||||
info)
|
||||
vm_info "$@"
|
||||
;;
|
||||
modify)
|
||||
vm_modify "$@"
|
||||
;;
|
||||
*)
|
||||
error "Unknown VM subcommand: $subcommand"
|
||||
echo "Use 'easyqemu help' for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
volume)
|
||||
local subcommand="${1:-list}"
|
||||
shift || true
|
||||
|
||||
case "$subcommand" in
|
||||
create)
|
||||
volume_create "$@"
|
||||
;;
|
||||
list)
|
||||
volume_list "$@"
|
||||
;;
|
||||
info)
|
||||
volume_info "$@"
|
||||
;;
|
||||
convert)
|
||||
volume_convert "$@"
|
||||
;;
|
||||
import)
|
||||
volume_import "$@"
|
||||
;;
|
||||
export)
|
||||
volume_export "$@"
|
||||
;;
|
||||
delete)
|
||||
volume_delete "$@"
|
||||
;;
|
||||
*)
|
||||
error "Unknown volume subcommand: $subcommand"
|
||||
echo "Use 'easyqemu help' for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
snapshot)
|
||||
local subcommand="${1:-list}"
|
||||
shift || true
|
||||
|
||||
case "$subcommand" in
|
||||
create)
|
||||
snapshot_create "$@"
|
||||
;;
|
||||
list)
|
||||
snapshot_list "$@"
|
||||
;;
|
||||
apply)
|
||||
snapshot_apply "$@"
|
||||
;;
|
||||
delete)
|
||||
snapshot_delete "$@"
|
||||
;;
|
||||
*)
|
||||
error "Unknown snapshot subcommand: $subcommand"
|
||||
echo "Use 'easyqemu help' for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
repo)
|
||||
local subcommand="${1:-list}"
|
||||
shift || true
|
||||
|
||||
case "$subcommand" in
|
||||
save)
|
||||
repo_save "$@"
|
||||
;;
|
||||
load)
|
||||
repo_load "$@"
|
||||
;;
|
||||
list)
|
||||
repo_list "$@"
|
||||
;;
|
||||
delete)
|
||||
repo_delete "$@"
|
||||
;;
|
||||
*)
|
||||
error "Unknown repo subcommand: $subcommand"
|
||||
echo "Use 'easyqemu help' for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
version)
|
||||
show_version
|
||||
;;
|
||||
|
||||
help|--help|-h)
|
||||
show_help
|
||||
;;
|
||||
|
||||
*)
|
||||
error "Unknown command: $command"
|
||||
echo "Use 'easyqemu help' for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
166
install.sh
Archivo ejecutable
166
install.sh
Archivo ejecutable
@@ -0,0 +1,166 @@
|
||||
#!/bin/bash
|
||||
|
||||
##############################################################################
|
||||
# EasyQEMU Installation Script
|
||||
##############################################################################
|
||||
|
||||
set -e
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1" >&2
|
||||
}
|
||||
|
||||
cat << 'EOF'
|
||||
╔═══════════════════════════════════════════════════════════════╗
|
||||
║ EasyQEMU Installation ║
|
||||
╚═══════════════════════════════════════════════════════════════╝
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
|
||||
# Check if QEMU is installed
|
||||
info "Checking for QEMU installation..."
|
||||
if ! command -v qemu-system-x86_64 &> /dev/null; then
|
||||
error "qemu-system-x86_64 not found"
|
||||
echo ""
|
||||
echo "Please install QEMU first:"
|
||||
echo ""
|
||||
echo " Debian/Ubuntu: sudo apt-get install qemu-system-x86 qemu-utils"
|
||||
echo " Fedora/RHEL: sudo dnf install qemu-kvm qemu-img"
|
||||
echo " Arch Linux: sudo pacman -S qemu"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v qemu-img &> /dev/null; then
|
||||
error "qemu-img not found"
|
||||
echo ""
|
||||
echo "Please install QEMU utilities:"
|
||||
echo ""
|
||||
echo " Debian/Ubuntu: sudo apt-get install qemu-utils"
|
||||
echo " Fedora/RHEL: sudo dnf install qemu-img"
|
||||
echo " Arch Linux: sudo pacman -S qemu"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
success "QEMU is installed"
|
||||
|
||||
# Check KVM
|
||||
info "Checking for KVM support..."
|
||||
if [[ -e /dev/kvm ]]; then
|
||||
if [[ -r /dev/kvm ]] && [[ -w /dev/kvm ]]; then
|
||||
success "KVM is available and accessible"
|
||||
else
|
||||
echo -e "${YELLOW}[WARNING]${NC} KVM device exists but is not accessible"
|
||||
echo "You may need to add your user to the kvm group:"
|
||||
echo " sudo usermod -a -G kvm \$USER"
|
||||
echo "Then log out and log back in."
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}[WARNING]${NC} KVM is not available"
|
||||
echo "VMs will run without hardware acceleration (slower)"
|
||||
fi
|
||||
|
||||
# Install location
|
||||
echo ""
|
||||
info "Select installation type:"
|
||||
echo ""
|
||||
echo " 1) System-wide installation (requires sudo, installs to /usr/local/bin)"
|
||||
echo " 2) User installation (installs to ~/.local/bin)"
|
||||
echo " 3) Don't install, just use from current directory"
|
||||
echo ""
|
||||
|
||||
read -p "Choose [1-3]: " -n 1 -r
|
||||
echo ""
|
||||
|
||||
INSTALL_TYPE=$REPLY
|
||||
|
||||
case $INSTALL_TYPE in
|
||||
1)
|
||||
info "Installing system-wide..."
|
||||
sudo cp easyqemu /usr/local/bin/easyqemu
|
||||
sudo chmod +x /usr/local/bin/easyqemu
|
||||
success "Installed to /usr/local/bin/easyqemu"
|
||||
;;
|
||||
2)
|
||||
info "Installing for user..."
|
||||
mkdir -p ~/.local/bin
|
||||
cp easyqemu ~/.local/bin/easyqemu
|
||||
chmod +x ~/.local/bin/easyqemu
|
||||
success "Installed to ~/.local/bin/easyqemu"
|
||||
|
||||
# Check if ~/.local/bin is in PATH
|
||||
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
|
||||
echo ""
|
||||
echo -e "${YELLOW}[WARNING]${NC} ~/.local/bin is not in your PATH"
|
||||
echo "Add this line to your ~/.bashrc or ~/.zshrc:"
|
||||
echo ""
|
||||
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
|
||||
echo ""
|
||||
fi
|
||||
;;
|
||||
3)
|
||||
info "No installation performed"
|
||||
success "You can run easyqemu from this directory: ./easyqemu"
|
||||
;;
|
||||
*)
|
||||
error "Invalid choice"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Create default directories
|
||||
info "Initializing EasyQEMU directories..."
|
||||
mkdir -p ~/.easyqemu/{vms,volumes,configs,repository,locks}
|
||||
success "Directories created in ~/.easyqemu"
|
||||
|
||||
# Copy configuration if it doesn't exist
|
||||
if [[ ! -f ~/.easyqemu/config ]]; then
|
||||
if [[ -f .easyqemu.conf ]]; then
|
||||
cp .easyqemu.conf ~/.easyqemu/config
|
||||
success "Configuration file created"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
cat << 'EOF'
|
||||
╔═══════════════════════════════════════════════════════════════╗
|
||||
║ Installation Complete! ║
|
||||
╚═══════════════════════════════════════════════════════════════╝
|
||||
|
||||
Getting Started:
|
||||
|
||||
1. View help:
|
||||
easyqemu help
|
||||
|
||||
2. Create your first VM:
|
||||
easyqemu vm create --name myvm --memory 2048 --cpus 2
|
||||
|
||||
3. List VMs:
|
||||
easyqemu vm list
|
||||
|
||||
4. View examples:
|
||||
./EXAMPLES.sh
|
||||
|
||||
5. Read documentation:
|
||||
cat README.md
|
||||
|
||||
For more information, visit the documentation or run 'easyqemu help'
|
||||
|
||||
EOF
|
||||
229
test.sh
Archivo ejecutable
229
test.sh
Archivo ejecutable
@@ -0,0 +1,229 @@
|
||||
#!/bin/bash
|
||||
|
||||
##############################################################################
|
||||
# EasyQEMU Test Suite
|
||||
# Run basic tests to ensure everything works correctly
|
||||
##############################################################################
|
||||
|
||||
set -e
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
PASSED=0
|
||||
FAILED=0
|
||||
TESTS=0
|
||||
|
||||
test_start() {
|
||||
TESTS=$((TESTS + 1))
|
||||
echo -ne "${BLUE}[TEST $TESTS]${NC} $1... "
|
||||
}
|
||||
|
||||
test_pass() {
|
||||
PASSED=$((PASSED + 1))
|
||||
echo -e "${GREEN}PASSED${NC}"
|
||||
}
|
||||
|
||||
test_fail() {
|
||||
FAILED=$((FAILED + 1))
|
||||
echo -e "${RED}FAILED${NC}"
|
||||
if [[ -n "$1" ]]; then
|
||||
echo " Error: $1"
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
echo ""
|
||||
echo "Cleaning up test data..."
|
||||
./easyqemu vm delete test-vm-$$ -f 2>/dev/null || true
|
||||
./easyqemu vm delete test-vm-clone-$$ -f 2>/dev/null || true
|
||||
./easyqemu volume delete test-volume-$$.qcow2 -f 2>/dev/null || true
|
||||
./easyqemu volume delete test-raw-$$.raw -f 2>/dev/null || true
|
||||
./easyqemu volume delete test-converted-$$.qcow2 -f 2>/dev/null || true
|
||||
./easyqemu repo delete test-template-$$ -f 2>/dev/null || true
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
cat << 'EOF'
|
||||
╔═══════════════════════════════════════════════════════════════╗
|
||||
║ EasyQEMU Test Suite ║
|
||||
╚═══════════════════════════════════════════════════════════════╝
|
||||
|
||||
EOF
|
||||
|
||||
# Test 1: Help command
|
||||
test_start "Help command"
|
||||
if ./easyqemu help > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Help command failed"
|
||||
fi
|
||||
|
||||
# Test 2: Version command
|
||||
test_start "Version command"
|
||||
if ./easyqemu version > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Version command failed"
|
||||
fi
|
||||
|
||||
# Test 3: Create VM
|
||||
test_start "Create VM"
|
||||
if ./easyqemu vm create --name test-vm-$$ --memory 512 --cpus 1 --disk-size 1G > /dev/null 2>&1; then
|
||||
VM_ID=$(./easyqemu vm list | grep "test-vm-$$" | awk '{print $1}')
|
||||
if [[ -n "$VM_ID" ]]; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "VM was not created properly"
|
||||
fi
|
||||
else
|
||||
test_fail "Failed to create VM"
|
||||
fi
|
||||
|
||||
# Test 4: List VMs
|
||||
test_start "List VMs"
|
||||
if ./easyqemu vm list > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to list VMs"
|
||||
fi
|
||||
|
||||
# Test 5: VM Info
|
||||
test_start "VM Info"
|
||||
if ./easyqemu vm info "$VM_ID" > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to get VM info"
|
||||
fi
|
||||
|
||||
# Test 6: Modify VM
|
||||
test_start "Modify VM"
|
||||
if ./easyqemu vm modify "$VM_ID" --memory 1024 > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to modify VM"
|
||||
fi
|
||||
|
||||
# Test 7: Create volume
|
||||
test_start "Create volume"
|
||||
if ./easyqemu volume create --name test-volume-$$ --size 1G --format qcow2 > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to create volume"
|
||||
fi
|
||||
|
||||
# Test 8: List volumes
|
||||
test_start "List volumes"
|
||||
if ./easyqemu volume list > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to list volumes"
|
||||
fi
|
||||
|
||||
# Test 9: Volume info
|
||||
test_start "Volume info"
|
||||
if ./easyqemu volume info ~/.easyqemu/volumes/test-volume-$$.qcow2 > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to get volume info"
|
||||
fi
|
||||
|
||||
# Test 10: Convert volume
|
||||
test_start "Convert volume"
|
||||
qemu-img create -f raw ~/.easyqemu/volumes/test-raw-$$.raw 100M > /dev/null 2>&1
|
||||
if ./easyqemu volume convert \
|
||||
--source ~/.easyqemu/volumes/test-raw-$$.raw \
|
||||
--target ~/.easyqemu/volumes/test-converted-$$.qcow2 \
|
||||
--format qcow2 > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to convert volume"
|
||||
fi
|
||||
|
||||
# Test 11: Create snapshot
|
||||
test_start "Create snapshot"
|
||||
if ./easyqemu snapshot create "$VM_ID" test-snapshot > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to create snapshot"
|
||||
fi
|
||||
|
||||
# Test 12: List snapshots
|
||||
test_start "List snapshots"
|
||||
if ./easyqemu snapshot list "$VM_ID" > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to list snapshots"
|
||||
fi
|
||||
|
||||
# Test 13: Delete snapshot
|
||||
test_start "Delete snapshot"
|
||||
if ./easyqemu snapshot delete "$VM_ID" test-snapshot > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to delete snapshot"
|
||||
fi
|
||||
|
||||
# Test 14: Save to repository
|
||||
test_start "Save to repository"
|
||||
if ./easyqemu repo save "$VM_ID" test-template-$$ > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to save to repository"
|
||||
fi
|
||||
|
||||
# Test 15: List repository
|
||||
test_start "List repository"
|
||||
if ./easyqemu repo list > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to list repository"
|
||||
fi
|
||||
|
||||
# Test 16: Load from repository
|
||||
test_start "Load from repository"
|
||||
if ./easyqemu repo load test-template-$$ test-vm-clone-$$ > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to load from repository"
|
||||
fi
|
||||
|
||||
# Test 17: Delete volume
|
||||
test_start "Delete volume"
|
||||
if ./easyqemu volume delete test-volume-$$.qcow2 -f > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to delete volume"
|
||||
fi
|
||||
|
||||
# Test 18: Delete VM
|
||||
test_start "Delete VM"
|
||||
if ./easyqemu vm delete "$VM_ID" -f > /dev/null 2>&1; then
|
||||
test_pass
|
||||
else
|
||||
test_fail "Failed to delete VM"
|
||||
fi
|
||||
|
||||
# Summary
|
||||
echo ""
|
||||
echo "╔═══════════════════════════════════════════════════════════════╗"
|
||||
echo "║ Test Results ║"
|
||||
echo "╚═══════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
echo -e "Total tests: $TESTS"
|
||||
echo -e "${GREEN}Passed: $PASSED${NC}"
|
||||
echo -e "${RED}Failed: $FAILED${NC}"
|
||||
echo ""
|
||||
|
||||
if [[ $FAILED -eq 0 ]]; then
|
||||
echo -e "${GREEN}All tests passed! ✓${NC}"
|
||||
exit 0
|
||||
else
|
||||
echo -e "${RED}Some tests failed! ✗${NC}"
|
||||
exit 1
|
||||
fi
|
||||
Referencia en una nueva incidencia
Block a user