Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simple-vm-manager
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Recolic
simple-vm-manager
Commits
c0562ec8
There was an error fetching the commit references. Please try again later.
Commit
c0562ec8
authored
1 year ago
by
Recolic
Browse files
Options
Downloads
Patches
Plain Diff
.
parent
3164c6cb
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
src/daemon-test.sh
+24
-20
24 additions, 20 deletions
src/daemon-test.sh
with
25 additions
and
20 deletions
.gitignore
0 → 100644
+
1
−
0
View file @
c0562ec8
data
This diff is collapsed.
Click to expand it.
src/daemon-test.sh
+
24
−
20
View file @
c0562ec8
#
aria2c 'https://cloud-images.ubuntu.com/focal/20231003/focal-server-cloudimg-amd64.img' -x2
#
!/bin/bash
#
https://medium.com/@art.vasilyev/use-ubuntu-cloud-image-with-kvm-1f28c19f82f8
#
pacman -S cdrkit qemu-base
cp
template/
*
-data
.
workdir
=
./data
genisoimage
-output
initimg.iso
-volid
cidata
-joliet
-rock
user-data meta-data
mkdir
-p
"
$workdir
"
qemu-img create
-f
qcow2
-F
qcow2
-o
backing_file
=
base/focal-server-cloudimg-amd64.img instance-1.qcow2
cd
"
$workdir
"
qemu-img resize instance-1.qcow2 60G
mkdir
-p
base vm tmp
qemu-system-x86_64
-drive
file
=
instance-1.qcow2,if
=
virtio
-cdrom
initimg.iso
-m
8G
-cpu
host
-smp
4
-vnc
:5
--enable-kvm
-bios
/usr/share/edk2-ovmf/x64/OVMF.fd
function
generate_metadata
()
{
function
generate_metadata
()
{
local
name
=
$1
local
name
=
$1
...
@@ -32,8 +31,6 @@ ssh_pwauth: True
...
@@ -32,8 +31,6 @@ ssh_pwauth: True
"
"
}
}
workdir
=
./data
mkdir
-p
"
$workdir
/base"
"
$workdir
/vm"
"
$workdir
/tmp"
function
create_vm_from
()
{
function
create_vm_from
()
{
local
name
=
$1
local
name
=
$1
local
cores
=
$2
local
cores
=
$2
...
@@ -45,21 +42,28 @@ function create_vm_from () {
...
@@ -45,21 +42,28 @@ function create_vm_from () {
local
vnc
=
$8
local
vnc
=
$8
local
ports
=
"
$9
"
local
ports
=
"
$9
"
if
[[
-f
"
$workdir
/vm/
$name
/disk.img"
]]
;
then
[[
-f
"base/focal-server-cloudimg-amd64.img"
]]
||
aria2c
-o
"base/focal-server-cloudimg-amd64.img"
https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
||
!
echo
"Failed to download ubuntu cloudimg"
||
return
$?
if
[[
-f
"vm/
$name
/disk.img"
]]
;
then
# simply start it
# simply start it
return
:
else
else
rm
-rf
"vm/
$name
"
;
mkdir
-p
"vm/
$name
"
# create and start it
# create and start it
generate_metadata
"
$name
"
>
"
$workdir
/vm/
$name
/meta-data"
generate_metadata
"
$name
"
>
"vm/
$name
/meta-data"
||
return
$?
generate_userdata
"
$username
"
"
$password
"
"
$name
"
>
"
$workdir
/vm/
$name
/user-data"
generate_userdata
"
$username
"
"
$password
"
"
$name
"
>
"vm/
$name
/user-data"
||
return
$?
(
cd
"
$workdir
/vm/
$name
"
;
genisoimage
-output
initimg.iso
-volid
cidata
-joliet
-rock
user-data meta-data
)
(
cd
"vm/
$name
"
;
genisoimage
-output
initimg.iso
-volid
cidata
-joliet
-rock
user-data meta-data
)
||
return
$?
qemu-img create
-f
qcow2
-F
qcow2
-o
backing_file
=
base/focal-server-cloudimg-amd64.img
"
$workdir
/vm/
$name
/disk.img"
qemu-img create
-f
qcow2
-F
qcow2
-o
backing_file
=
"../../base/focal-server-cloudimg-amd64.img"
"vm/
$name
/disk.img"
||
return
$?
qemu-img resize
"
$workdir
/vm/
$name
/disk.img"
"
$disk
"
qemu-img resize
"vm/
$name
/disk.img"
"
$disk
"
||
return
$?
qemu-system-x86_64
-drive
file
=
"
$workdir
/vm/
$name
/disk.img"
,if
=
virtio
-cdrom
"
$workdir
/vm/
$name
/initimg.iso"
-m
"
$ram
"
-cpu
host
-smp
"
$cores
"
-vnc
"
$vnc
"
--enable-kvm
-bios
/usr/share/edk2-ovmf/x64/OVMF.fd
-net
nic,model
=
rtl8139
-net
user,hostfwd
=
tcp::30472-:22 &
pid
=
$!
echo
PID
=
$pid
# TODO
fi
fi
# start it
qemu-system-x86_64
-drive
file
=
"vm/
$name
/disk.img"
,if
=
virtio
-cdrom
"vm/
$name
/initimg.iso"
-m
"
$ram
"
-cpu
host
-smp
"
$cores
"
-vnc
"
$vnc
"
--enable-kvm
-bios
/usr/share/edk2-ovmf/x64/OVMF.fd
-net
nic,model
=
rtl8139
-net
user,hostfwd
=
tcp::30472-:22 &
pid
=
$!
echo
PID
=
$pid
# TODO
}
}
[[
$2
=
""
]]
&&
echo
"Temp script to create VM. Usage:
$0
MY_GOOD_VM11 :11"
&&
exit
1
create_vm_from
"
$1
"
2 4G 50G __hardcoded__ r 1
"
$2
"
__hardcoded__
||
exit
$?
echo
"DEBUG: sshpass -p 1 ssh -p 30472 r@localhost"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment