Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
vbox-scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto LIVIO BECCARIA
vbox-scripts
Commits
f431e573
Commit
f431e573
authored
5 years ago
by
Alberto LIVIO BECCARIA
Browse files
Options
Downloads
Patches
Plain Diff
Keep vm-setup from crashing when disks with identical UUID exist.
parent
ac199ba7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
vm-setup
+67
-34
67 additions, 34 deletions
vm-setup
with
67 additions
and
34 deletions
vm-setup
+
67
−
34
View file @
f431e573
...
@@ -74,18 +74,66 @@ EOF
...
@@ -74,18 +74,66 @@ EOF
}
}
###############################################################################
###############################################################################
vbox_sanitize_storage_uuid
()
{
disk_img
=
$1
# check if disk image exists, otherwise abort
if
[[
!
-f
"
${
disk_img
}
"
]]
;
then
echo
echo
"
${
ERROR
}
Disk image
${
BOLD
}${
disk_img
}${
NORMAL
}${
ERROR
}
does not exist on this computer. Abort. Bye!
${
NORMAL
}
"
exit
0
fi
# try to remove the same disk from media registry (just in case it exists)
vboxmanage closemedium disk
${
disk_img
}
>
/dev/null 2>&1
# try to get the disk UUID here...
vboxmanage showhdinfo
"
${
disk_img
}
"
>
/dev/null 2>&1
if
[[
$?
!=
0
]]
;
then
echo
echo
"
${
ERROR
}
Error: storage UUID already exists in virtual media registry!
${
NORMAL
}
"
askYesNo
"
${
GREEN
}
Assign new UUID to storage (write permission needed)?
${
NORMAL
}
"
true
if
[[
$?
==
0
]]
;
then
# change the disk UUID
vboxmanage internalcommands sethduuid
"
${
disk_img
}
"
else
echo
echo
"
${
ERROR
}
Abort. Bye!
${
NORMAL
}
"
exit
0
fi
fi
}
###############################################################################
# vbox_attach_medium (disk_img, port_num)
###################
vbox_attach_storage
()
{
vbox_attach_storage
()
{
###############################################################################
# vbox_attach_storage (disk_img, port_num)
###################
local
disk_img
=
$1
local
disk_img
=
$1
local
port_num
=
$2
local
port_num
=
$2
vboxmanage storageattach
"
${
VM_NAME
}
"
--storagectl
"
${
STORAGE_CONTROLLER_NAME
}
"
${
STORAGE_EXTRA_PARAMS
}
--port
${
port_num
}
--device
0
--type
hdd
--medium
"
${
disk_img
}
"
vboxmanage storageattach
"
${
VM_NAME
}
"
--storagectl
"
${
STORAGE_CONTROLLER_NAME
}
"
\
${
STORAGE_EXTRA_PARAMS
}
--port
${
port_num
}
--device
0
--type
hdd
--medium
"
${
disk_img
}
"
}
}
###############################################################################
# vbox_set_storage_type
# sets storage type to "normal" to allow update (if UPDATE=1), otherwise to STORAGE_TYPE (default: "immutable")
###################
#
vbox_set_storage_type
()
{
local
disk_img
=
$1
vbox_sanitize_storage_uuid
"
${
disk_img
}
"
if
[[
${
UPDATE
}
==
1
]]
;
then
vboxmanage modifyhd
"
${
disk_img
}
"
--type
normal
else
vboxmanage modifyhd
"
${
disk_img
}
"
--type
${
STORAGE_TYPE
}
fi
}
# print title
# print title
title
title
...
@@ -136,7 +184,7 @@ debug
...
@@ -136,7 +184,7 @@ debug
# import VM settings by id or name
# import VM settings by id or name
vm_settings
=
`
get_vm_settings
"
${
VM_ID
}
"
`
vm_settings
=
`
get_vm_settings
"
${
VM_ID
}
"
`
if
[
"
$vm_settings
"
==
""
]
;
then
if
[
[
"
$vm_settings
"
==
""
]
]
;
then
usage
"
${
ERROR
}
ERROR: wrong vm_id
\"
${
BOLD
}${
VM_ID
}
\"
.
${
NORMAL
}
"
usage
"
${
ERROR
}
ERROR: wrong vm_id
\"
${
BOLD
}${
VM_ID
}
\"
.
${
NORMAL
}
"
fi
fi
...
@@ -149,7 +197,7 @@ VM_DIR="${MACHINES_DIR}/${VM_NAME}"
...
@@ -149,7 +197,7 @@ VM_DIR="${MACHINES_DIR}/${VM_NAME}"
# if registered, unregister it
# if registered, unregister it
VBoxManage showvminfo
"
${
VM_NAME
}
"
&> /dev/null
VBoxManage showvminfo
"
${
VM_NAME
}
"
&> /dev/null
if
[
$?
-eq
0
]
;
then
if
[
[
$?
-eq
0
]
]
;
then
VBoxManage unregistervm
"
${
VM_NAME
}
"
VBoxManage unregistervm
"
${
VM_NAME
}
"
fi
fi
...
@@ -199,33 +247,18 @@ if [[ ${CREATE_VM} == 1 ]]; then
...
@@ -199,33 +247,18 @@ if [[ ${CREATE_VM} == 1 ]]; then
--audioin
on
--audioout
on
--audioin
on
--audioout
on
# working on VB version >= 5.2.20
# working on VB version >= 5.2.20
# set storage type to "normal" to allow update, otherwise to STORAGE_TYPE (default: "immutable")
# set storages' type
if
[[
${
UPDATE
}
==
1
]]
;
then
if
[[
"
${
DISK_IMAGE_1
}
"
!=
""
]]
;
then
if
[[
"
${
DISK_IMAGE_1
}
"
!=
""
]]
;
then
vbox_set_storage_type
"
${
DISK_IMAGE_1
}
"
VBoxManage modifyhd
"
${
DISK_IMAGE_1
}
"
--type
normal
fi
fi
if
[[
"
${
DISK_IMAGE_2
}
"
!=
""
]]
;
then
if
[[
"
${
DISK_IMAGE_2
}
"
!=
""
]]
;
then
vbox_set_storage_type
"
${
DISK_IMAGE_2
}
"
VBoxManage modifyhd
"
${
DISK_IMAGE_2
}
"
--type
normal
fi
fi
if
[[
"
${
DISK_IMAGE_3
}
"
!=
""
]]
;
then
if
[[
"
${
DISK_IMAGE_3
}
"
!=
""
]]
;
then
vbox_set_storage_type
"
${
DISK_IMAGE_3
}
"
VBoxManage modifyhd
"
${
DISK_IMAGE_3
}
"
--type
normal
fi
fi
if
[[
"
${
DISK_IMAGE_4
}
"
!=
""
]]
;
then
if
[[
"
${
DISK_IMAGE_4
}
"
!=
""
]]
;
then
vbox_set_storage_type
"
${
DISK_IMAGE_4
}
"
VBoxManage modifyhd
"
${
DISK_IMAGE_4
}
"
--type
normal
fi
else
if
[[
"
${
DISK_IMAGE_1
}
"
!=
""
]]
;
then
VBoxManage modifyhd
"
${
DISK_IMAGE_1
}
"
--type
${
STORAGE_TYPE
}
fi
if
[[
"
${
DISK_IMAGE_2
}
"
!=
""
]]
;
then
VBoxManage modifyhd
"
${
DISK_IMAGE_2
}
"
--type
${
STORAGE_TYPE
}
fi
if
[[
"
${
DISK_IMAGE_3
}
"
!=
""
]]
;
then
VBoxManage modifyhd
"
${
DISK_IMAGE_3
}
"
--type
${
STORAGE_TYPE
}
fi
if
[[
"
${
DISK_IMAGE_4
}
"
!=
""
]]
;
then
VBoxManage modifyhd
"
${
DISK_IMAGE_4
}
"
--type
${
STORAGE_TYPE
}
fi
fi
fi
# add storage
# add storage
...
@@ -264,7 +297,7 @@ else
...
@@ -264,7 +297,7 @@ else
sed
-i
's@\(SharedFolder.*name="'
"
`
echo
"
${
SF_MEDIA_NAME
}
"
`
"
'".*hostPath="\)\([^"]*\)\("\)@\1'
"
`
echo
"
${
SF_MEDIA_TARGET
}
"
`
"
'\3@g'
"
${
VM_DIR
}
/
${
VM_NAME
}
.vbox"
sed
-i
's@\(SharedFolder.*name="'
"
`
echo
"
${
SF_MEDIA_NAME
}
"
`
"
'".*hostPath="\)\([^"]*\)\("\)@\1'
"
`
echo
"
${
SF_MEDIA_TARGET
}
"
`
"
'\3@g'
"
${
VM_DIR
}
/
${
VM_NAME
}
.vbox"
sed
-i
's@\(MACAddress="\)\([^"]*\)\("\)@\1'
"
`
printf
'080027%02X%02X%02X'
$[
RANDOM%256]
$[
RANDOM%256]
$[
RANDOM%256]
`
"
'\3@g'
"
${
VM_DIR
}
/
${
VM_NAME
}
.vbox"
sed
-i
's@\(MACAddress="\)\([^"]*\)\("\)@\1'
"
`
printf
'080027%02X%02X%02X'
$[
RANDOM%256]
$[
RANDOM%256]
$[
RANDOM%256]
`
"
'\3@g'
"
${
VM_DIR
}
/
${
VM_NAME
}
.vbox"
if
[
"
${
DIFF_DISK_FILE
}
"
!=
""
]
;
then
if
[
[
"
${
DIFF_DISK_FILE
}
"
!=
""
]
]
;
then
sed
-i
's@\(HardDisk.*location="\)\([^"]*diff_[^"]*\)\("\)@\1'
"
`
echo
"
${
USER_TMP_DIR
}
/
${
DIFF_DISK_FILE
}
"
`
"
'\3@g'
"
${
VM_DIR
}
/
${
VM_NAME
}
.vbox"
sed
-i
's@\(HardDisk.*location="\)\([^"]*diff_[^"]*\)\("\)@\1'
"
`
echo
"
${
USER_TMP_DIR
}
/
${
DIFF_DISK_FILE
}
"
`
"
'\3@g'
"
${
VM_DIR
}
/
${
VM_NAME
}
.vbox"
fi
fi
...
...
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