Skip to content

Commit

Permalink
Rewrote VM compression
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-duponchelle committed Jul 9, 2015
1 parent bdc03a4 commit fd2b62d
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 18 deletions.
14 changes: 14 additions & 0 deletions config/rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#
# By default this script does nothing.

if [ -f /usr/local/bin/gns3server ]
then
IP=$(ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | cut -d' ' -f1)
cat << EOF > /etc/issue
Welcome to GNS3 appliance
Expand All @@ -30,5 +32,17 @@ Images and projects are located in /opt/gns3
$(kvm-ok)
EOF
else
cat << EOF > /etc/issue
Welcome to GNS3 appliance
VM version: $(cat /home/gns3/.config/GNS3/gns3vm_version)
Please wait the end of installation.
The VM will reboot at the end.
$(kvm-ok)
EOF
fi

exit 0
48 changes: 48 additions & 0 deletions config/zerofree
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: zerofree
# Required-Start:
# Required-Stop:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Compress the filesystem
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin/
. /lib/init/vars.sh

. /lib/lsb/init-functions

do_stop () {
if [ -f /zerofree ]
then
echo "Compress disks"
zerofree /dev/sda1
zerofree /dev/sdb1
fi
}

do_start() {
if [ -f /zerofree ]
then
rm /zerofree
fi
}

case "$1" in
start)
do_start
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
do_stop
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac
31 changes: 29 additions & 2 deletions gns3.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"variables" : {
"ssh_pass" : "gns3",
"ssh_name" : "gns3",
"hostname" : "gns3",
"hostname" : "gns3vm",
"memory": "2048",
"disk_size": "20000",
"data_disk": "100000"
Expand Down Expand Up @@ -46,6 +46,11 @@
"type" : "shell",
"script" : "scripts/splashscreen.sh"
},
{
"destination" : "/tmp/init_zerofree",
"type" : "file",
"source" : "config/zerofree"
},
{
"script" : "scripts/cleaner.sh",
"type" : "shell"
Expand All @@ -59,6 +64,8 @@
"disk_size" : "{{user `disk_size`}}",
"iso_checksum_type" : "sha1",
"shutdown_command" : "echo {{user `ssh_name`}} | sudo -S shutdown -P now",
"shutdown_timeout": "60m",
"format": "ova",
"vboxmanage" : [
[
"modifyvm",
Expand Down Expand Up @@ -151,10 +158,30 @@
"memsize" : "{{user `memory`}}",
"cpuid.coresPerSocket" : "1",
"numvcpus": "1",
"vhv.enable": "TRUE"
"vhv.enable": "TRUE",
"ethernet0.present": "TRUE",
"ethernet0.startConnected": "TRUE",
"ethernet0.connectionType": "nat",
"ethernet0.addressType": "generated",
"ethernet0.generatedAddressOffset": "0",
"ethernet0.wakeOnPcktRcv": "FALSE",
"ethernet0.pciSlotNumber": "32",
"ethernet1.present": "FALSE",
"ethernet1.startConnected": "TRUE",
"ethernet1.connectionType": "nat",
"ethernet1.addressType": "generated",
"ethernet1.generatedAddressOffset": "10",
"ethernet1.wakeOnPcktRcv": "FALSE",
"ethernet1.pciSlotNumber": "33"
},
"vmx_data_post":
{
"ethernet0.connectionType": "hostonly",
"ethernet1.present": "TRUE"
},
"iso_checksum_type" : "sha1",
"shutdown_command" : "echo {{user `ssh_name`}} | sudo -S shutdown -P now",
"shutdown_timeout": "60m",
"ssh_password" : "{{user `ssh_pass`}}",
"boot_command" : [
"<esc><wait>",
Expand Down
10 changes: 4 additions & 6 deletions gns3_compress.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@
"shutdown_command": "sudo shutdown -P now",
"format": "ova",
"vm_name": "GNS3 VM",
"boot_wait": "30s",
"boot_wait": "150s",
"boot_command": [
"<enter><wait><wait><down><wait><down><wait><enter><wait>",
"sudo service gns3 stop<enter>",
"sudo pip3 uninstall gns3-server -y<enter>",
"sudo service ssh stop<enter>",
"sudo service rsyslog stop<enter>",
"sudo service dbus stop<enter>",
"sudo service docker stop<enter>",
"sudo telinit 1<enter><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait>",
"sudo service docker stop<enter>",
"mount -o remount,ro /dev/sda1<enter>",
"zerofree /dev/sda1<enter>",
"mount -o remount,rw /dev/sda1<enter>",
"service ssh start<enter>"
"mount -o remount,rw /dev/sda1<enter>"
],
"vboxmanage_post" : [
[
Expand Down Expand Up @@ -69,7 +67,7 @@
"sudo service ssh stop<enter>",
"sudo service rsyslog stop<enter>",
"sudo service dbus stop<enter>",
"sudo service docker stop<enter>",
"sudo service docker stop<enter>",
"sudo telinit 1<enter><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait><wait>",
"mount -o remount,ro /dev/sda1<enter>",
"zerofree /dev/sda1<enter>",
Expand Down
14 changes: 13 additions & 1 deletion scripts/cleaner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sudo locale-gen --purge --lang en_US
# Tools for cleaning the disk
sudo apt-get install -y zerofree

sudo apt-get -y autoremove
sudo apt-get -y autoremove
sudo apt-get -y clean

sudo rm -fr /var/lib/apt/lists/*
Expand All @@ -24,3 +24,15 @@ sudo rm -fr /var/cache/man/*
sudo rm -Rf /var/log/installer/*
sudo rm -Rf /usr/share/doc
sudo rm -Rf /var/lib/docker/devicemapper

sudo pip3 uninstall -y gns3-server

# Setup zerofree for disk compaction
sudo mv /tmp/init_zerofree /etc/init.d/zerofree
sudo chown root:root /etc/init.d/zerofree
sudo chmod 744 /etc/init.d/zerofree
sudo update-rc.d zerofree defaults 61
sudo mv /etc/rc0.d/K61zerofree /etc/rc0.d/S61zerofree
sudo mv /etc/rc6.d/K61zerofree /etc/rc6.d/S61zerofree
sudo touch /zerofree

3 changes: 0 additions & 3 deletions scripts/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ EOF
fi


sudo mkdir -p /opt/gns3
sudo chown gns3:gns3 /opt/gns3

# Setup the message display on console
sudo mv "/tmp/rc.local" "/etc/rc.local"
sudo chmod 700 /etc/rc.local
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7
0.8
3 changes: 1 addition & 2 deletions virtualbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ export GNS3VM_VERSION=`cat version`

echo "Build VM $GNS3VM_VERSION"

packer build -only=virtualbox-iso gns3.json
packer build -only=virtualbox-ovf gns3_compress.json
packer build -force -only=virtualbox-iso gns3.json
4 changes: 1 addition & 3 deletions vmware.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export GNS3VM_VERSION=`cat version`
echo "Build VM $GNS3VM_VERSION"

rm -Rf output-vmware-iso
rm -Rf output-vmware-vmx
packer build -only=vmware-iso gns3.json
packer build -only=vmware-vmx gns3_compress.json

ovftool --extraConfig:vhv.enable=true --allowAllExtraConfig --overwrite output-vmware-vmx/GNS3\ VM.vmx GNS3\ VM\ ${GNS3VM_VERSION}.ova
ovftool --extraConfig:vhv.enable=true --extraConfig:ethernet0.connectionType=hostonly --extraConfig:ethernet1.present=true --allowAllExtraConfig --overwrite output-vmware-iso/GNS3\ VM.vmx GNS3\ VM\ ${GNS3VM_VERSION}.ova

0 comments on commit fd2b62d

Please sign in to comment.