Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Erwan BOUSSE
ubuntu-vm-creator
Commits
bb22f4ca
Commit
bb22f4ca
authored
Nov 10, 2020
by
Erwan BOUSSE
Browse files
Add proto customization mecanism
parent
fc69d267
Changes
4
Hide whitespace changes
Inline
Side-by-side
convert_to_vbox.sh
View file @
bb22f4ca
...
...
@@ -5,15 +5,16 @@ set -e
OUTPUT_FOLDER
=
output
OUTPUT_IMG
=
$OUTPUT_FOLDER
/mini-ubuntu.img
OUTPUT_VDI
=
$OUTPUT_FOLDER
/mini-ubuntu.vdi
OUTPUT_OVA
=
$OUTPUT_FOLDER
/mini-ubuntu.ova
OUTPUT_IMG
=
$OUTPUT_FOLDER
/mini-ubuntu
-customized
.img
OUTPUT_VDI
=
$OUTPUT_FOLDER
/mini-ubuntu
-customized
.vdi
OUTPUT_OVA
=
$OUTPUT_FOLDER
/mini-ubuntu
-customized
.ova
VBoxManage unregistervm
"mini-ubuntu"
--delete
||
true
rm
-rf
vbox
mkdir
-p
vbox
mkdir
-p
$OUTPUT_FOLDER
rm
$OUTPUT_VDI
||
true
rm
$OUTPUT_OVA
||
true
VBoxManage convertfromraw
--format
vdi
$OUTPUT_IMG
$OUTPUT_VDI
VBoxManage createvm
--name
"mini-ubuntu"
--ostype
"Ubuntu_64"
--register
--basefolder
$OUTPUT_FOLDER
...
...
create_base_img.sh
View file @
bb22f4ca
...
...
@@ -7,7 +7,7 @@ set -e
UBUNTU_VERSION
=
20.10
ISO_FOLDER
=
isos
OUTPUT_FOLDER
=
output
OUTPUT_IMG
=
$OUTPUT_FOLDER
/mini-ubuntu.img
OUTPUT_IMG
=
$OUTPUT_FOLDER
/mini-ubuntu
-base
.img
# Intermediate variables
ISO
=
$(
curl
-s
http://releases.ubuntu.com/
$UBUNTU_VERSION
/ |
grep
"server install image</a>"
|
cut
-d
'"'
-f
2
)
...
...
customize_base_image.sh
View file @
bb22f4ca
#!/bin/bash
set
-x
set
-e
if
[
$#
-ne
1
]
;
then
echo
"Illegal number of parameters"
exit
2
fi
CUSTOMIZATION_FOLDER
=
$1
CUSTOMIZATION_FOLDER_BASE
=
$(
basename
$CUSTOMIZATION_FOLDER
)
function
cleanup
()
{
sudo rm
/mnt/etc/resolv.conf
||
true
sudo
umount
-f
-l
/mnt
||
true
sudo
vgchange
-an
ubuntu-vg
||
true
sudo
kpartx
-d
"
$LOOP
"
||
true
sudo
losetup
-D
sudo
dmsetup remove_all
}
cleanup
# Variables
#TODO
OUTPUT_FOLDER
=
output
BASE_IMG
=
$OUTPUT_FOLDER
/mini-ubuntu-base.img
CUSTOMIZED_IMG
=
$OUTPUT_FOLDER
/mini-ubuntu-customized.img
LOOP
=
$(
sudo
losetup
-f
)
# Copy base img if needed
touch
$CUSTOMIZED_IMG
# if [ ! "$(md5sum $BASE_IMG)" = "$(md5sum $CUSTOMIZED_IMG)" ]
if
!
cmp
--silent
$BASE_IMG
$CUSTOMIZED_IMG
then
rm
$CUSTOMIZED_IMG
||
true
cp
$BASE_IMG
$CUSTOMIZED_IMG
fi
# Mount img file
#TODO
sudo
losetup
"
$LOOP
"
$CUSTOMIZED_IMG
sudo
kpartx
-a
"
$LOOP
"
sudo
vgscan
sudo
vgchange
-ay
sudo
mount /dev/ubuntu-vg/ubuntu-lv /mnt
#
Copy data
in
/
root
#TODO
#
Enable DNS
in
ch
root
sudo cp
/etc/resolv.conf /mnt/etc
||
true
# Copy
script
in /root
#TODO
# Copy
data
in /root
sudo cp
-R
$CUSTOMIZATION_FOLDER
/mnt/root
# Chroot and run script
#TODO
\ No newline at end of file
sudo chroot
/mnt /bin/bash /root/
$CUSTOMIZATION_FOLDER_BASE
/run.sh
# Cleanup and exit
cleanup
\ No newline at end of file
example-customization/run.sh
0 → 100644
View file @
bb22f4ca
#!/bin/bash
set
-x
set
-e
mkdir
-p
/home/etudiant/Bureau
touch
/home/etudiant/Bureau/Hello
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment