Skip to content

Commit 562cc90

Browse files
committed
tools/packer: adapt for Ubuntu 18.04
This change is also a complete refactoring of the generation of the vagrant image
1 parent 953e8c9 commit 562cc90

File tree

15 files changed

+443
-265
lines changed

15 files changed

+443
-265
lines changed

Vagrantfile

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,20 @@ require 'fileutils'
55

66
RIOTBASE ||= "./"
77

8-
Vagrant.configure(2) do |config|
9-
# For a complete reference, please see the online documentation at https://docs.vagrantup.com.
10-
11-
config.vm.box = "RIOT/ubuntu1604"
12-
13-
config.vm.provider "virtualbox" do |vb|
14-
vb.name = "RIOT-VM"
15-
16-
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-interval", 10000]
17-
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-min-adjust", 100]
18-
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore", 1]
19-
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000]
20-
21-
# additional USB passthrough entries
22-
# vb.customize ['usbfilter', 'add', '0', '--target', :id, '--name', '<custom_name>', '--vendorid', '<vID>', '--productid', '<pID>']
23-
end
24-
25-
config.vm.synced_folder RIOTBASE, "/home/vagrant/RIOT"
26-
27-
if File.exists?(File.join(Dir.home, ".gitconfig"))
28-
config.vm.provision "file", source: File.join(Dir.home, ".gitconfig"), destination: ".gitconfig"
29-
end
30-
# use a custom provisioning script
31-
# config.vm.provision "shell", path: "dist/tools/vagrant/bootstrap.sh"
8+
Vagrant.configure("2") do |config|
9+
config.vm.define "RIOT-VM"
10+
config.vm.box = "RIOT/ubuntu1804"
11+
config.ssh.username = "user"
12+
config.vm.synced_folder RIOTBASE, "/home/user/RIOT"
13+
14+
if File.exists?(File.join(Dir.home, ".gitconfig"))
15+
config.vm.provision "file", source: File.join(Dir.home, ".gitconfig"), destination: ".gitconfig"
16+
end
17+
18+
config.vm.provider :virtualbox do |v, override|
19+
v.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore", 0]
20+
21+
# additional USB passthrough entries
22+
# v.customize ['usbfilter', 'add', '0', '--target', :id, '--name', '<custom_name>', '--vendorid', '<vID>', '--productid', '<pID>']
23+
end
3224
end

dist/tools/packer/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
packer_cache
2+
output-*-virtualbox-iso/
23
*.box

dist/tools/packer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ A simple build of the vagrant box can be done by:
1313
packer build riot.json
1414
```
1515
This command must be executed in the packer directory [RIOT/dist/tools/packer](https://github.com/RIOT-OS/RIOT/tree/master/dist/tools/packer).
16-
Note that the build process might take several minutes.
16+
Note that the build process might take several minutes.

dist/tools/packer/http/preseed.cfg

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#choose-mirror-bin mirror/http/proxy string
2+
d-i base-installer/kernel/override-image string linux-server
3+
d-i clock-setup/utc boolean true
4+
d-i clock-setup/utc-auto boolean true
5+
d-i finish-install/reboot_in_progress note
6+
d-i grub-installer/only_debian boolean true
7+
d-i grub-installer/with_other_os boolean true
8+
d-i partman-auto-lvm/guided_size string max
9+
d-i partman-auto/choose_recipe select atomic
10+
d-i partman-auto/method string lvm
11+
d-i partman-lvm/confirm boolean true
12+
d-i partman-lvm/confirm boolean true
13+
d-i partman-lvm/confirm_nooverwrite boolean true
14+
d-i partman-lvm/device_remove_lvm boolean true
15+
d-i partman/choose_partition select finish
16+
d-i partman/confirm boolean true
17+
d-i partman/confirm_nooverwrite boolean true
18+
d-i partman/confirm_write_new_label boolean true
19+
20+
# Default mirror
21+
d-i mirror/country string FR
22+
d-i mirror/http/hostname string ftp.fr.debian.org
23+
d-i mirror/http/directory string /ubuntu
24+
d-i mirror/http/proxy string
25+
d-i mirror/http/mirror string ftp.fr.debian.org
26+
27+
# Default user
28+
d-i passwd/user-fullname string user
29+
d-i passwd/username string user
30+
d-i passwd/user-password password user
31+
d-i passwd/user-password-again password user
32+
d-i passwd/username string user
33+
34+
# Minimum packages (see postinstall.sh)
35+
d-i pkgsel/include string openssh-server
36+
d-i pkgsel/install-language-support boolean true
37+
d-i pkgsel/update-policy select none
38+
d-i pkgsel/upgrade select none
39+
40+
d-i time/zone string UTC
41+
d-i user-setup/allow-password-weak boolean true
42+
d-i user-setup/encrypt-home boolean false
43+
tasksel tasksel/first multiselect standard, ubuntu-server

dist/tools/packer/preseed.cfg

Lines changed: 0 additions & 35 deletions
This file was deleted.

dist/tools/packer/riot.json

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,70 @@
11
{
2-
"_comment": "Build with `packer build riot.json`",
32
"builders": [
43
{
4+
"type": "virtualbox-iso",
55
"boot_command": [
6-
"{{ user `boot_command_prefix` }}",
7-
"/install/vmlinuz noapic ",
8-
"initrd=/install/initrd.gz ",
9-
"file=/floppy/{{ user `preseed` }} ",
10-
"debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
11-
"hostname={{ user `hostname` }} ",
12-
"fb=false debconf/frontend=noninteractive ",
13-
"keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
14-
"keyboard-configuration/variant=USA console-setup/ask_detect=false ",
15-
"passwd/user-fullname={{ user `ssh_fullname` }} ",
16-
"passwd/user-password={{ user `ssh_password` }} ",
17-
"passwd/user-password-again={{ user `ssh_password` }} ",
18-
"passwd/username={{ user `ssh_username` }} ",
19-
"-- <enter>"
6+
"<esc><wait>",
7+
"<esc><wait>",
8+
"<enter><wait>",
9+
"/install/vmlinuz<wait>",
10+
" auto<wait>",
11+
" console-setup/ask_detect=false<wait>",
12+
" console-setup/layoutcode=us<wait>",
13+
" console-setup/modelcode=pc105<wait>",
14+
" debconf/frontend=noninteractive<wait>",
15+
" debian-installer=en_US<wait>",
16+
" fb=false<wait>",
17+
" initrd=/install/initrd.gz<wait>",
18+
" kbd-chooser/method=us<wait>",
19+
" keyboard-configuration/layout=USA<wait>",
20+
" keyboard-configuration/variant=USA<wait>",
21+
" locale=en_US<wait>",
22+
" netcfg/get_domain=vm<wait>",
23+
" netcfg/get_hostname={{ user `hostname` }}<wait>",
24+
" grub-installer/bootdev=/dev/sda<wait>",
25+
" noapic<wait>",
26+
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<wait>",
27+
" -- <wait>",
28+
"<enter><wait>"
2029
],
30+
"boot_wait": "10s",
2131
"disk_size": "{{ user `disk_size` }}",
22-
"floppy_files": [ "{{ user `preseed` }}" ],
2332
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
2433
"guest_os_type": "{{ user `virtualbox_guest_os_type` }}",
2534
"headless": "{{ user `headless` }}",
2635
"iso_checksum": "{{ user `iso_checksum` }}",
2736
"iso_checksum_type": "{{ user `iso_checksum_type` }}",
2837
"iso_urls": [ "{{ user `iso_path` }}/{{ user `iso_name` }}", "{{ user `iso_url` }}" ],
2938
"output_directory": "output-{{ user `vm_name` }}-virtualbox-iso",
39+
"http_directory": "http",
3040
"shutdown_command": "echo '{{ user `ssh_password` }}'|sudo -S shutdown -P now",
31-
"ssh_password": "{{ user `ssh_password` }}",
3241
"ssh_username": "{{ user `ssh_username` }}",
42+
"ssh_password": "{{ user `ssh_password` }}",
43+
"ssh_port": 22,
3344
"ssh_wait_timeout": "10000s",
34-
"type": "virtualbox-iso",
3545
"vboxmanage": [
3646
[ "modifyvm", "{{.Name}}", "--memory", "{{ user `memory` }}" ],
3747
[ "modifyvm", "{{.Name}}", "--cpus", "{{ user `cpus` }}" ],
3848
[ "modifyvm", "{{.Name}}", "--usb", "on" ],
39-
[ "modifyvm", "{{.Name}}", "--usbxhci", "on" ],
4049
[ "modifyvm", "{{.Name}}", "--audio", "none"],
4150
[ "modifyvm", "{{.Name}}", "--ioapic", "on"],
4251
[ "modifyvm", "{{.Name}}", "--rtcuseutc", "on"],
43-
[ "modifyvm", "{{.Name}}", "--clipboard", "bidirectional"],
4452
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "FTDI USB-TTL", "--vendorid", "0x0403", "--productid", "0x6001"],
4553
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "CP2102 USB to UART", "--vendorid", "0x10c4", "--productid", "0xea60"],
4654
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "STM32 STLink", "--vendorid", "0x0483", "--productid", "0x3748"],
55+
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "STM32 STLink", "--vendorid", "0x0483", "--productid", "0x374b"],
4756
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "USBasp", "--vendorid", "0x16c0", "--productid", "0x05dc"],
4857
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "iotlab-m3", "--vendorid", "0x0403", "--productid", "0x6010"],
49-
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "samr21-xpro", "--vendorid", "0x03eb", "--productid", "0x2111"],
50-
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Arduino Mega 2560", "--vendorid", "0x2341", "--productid", "0x0042"],
58+
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "iotlab-m3-cn", "--vendorid", "0x0403", "--productid", "0x6011"],
59+
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "CMSIS-DAP", "--vendorid", "0x03eb", "--productid", "0x2111"],
60+
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Arduino UNO", "--vendorid", "0x2341", "--productid", "0x0042"],
61+
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Arduino Mega 2560", "--vendorid", "0x2a03", "--productid", "0x0042"],
5162
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Phytec phyWAVE KW22", "--vendorid", "0x0d28", "--productid", "0x0204"],
5263
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Bluepill", "--vendorid", "0x1d50", "--productid", "0x6017"],
53-
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Bluepill", "--vendorid", "0x1d50", "--productid", "0x6018"]
64+
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Bluepill", "--vendorid", "0x1d50", "--productid", "0x6018"],
65+
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "JLink", "--vendorid", "0x1366", "--productid", "0x1015"],
66+
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Arduino Zero", "--vendorid", "0x03eb", "--productid", "0x2157"],
67+
["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "DAPLink", "--vendorid", "0x0d28", "--productid", "0x0204"]
5468
],
5569
"virtualbox_version_file": ".vbox_version",
5670
"vm_name": "{{user `vm_name`}}"
@@ -68,36 +82,39 @@
6882
],
6983
"provisioners": [
7084
{
71-
"type": "file",
72-
"source": "./udev_rules",
73-
"destination": "/tmp"
74-
},
75-
{
85+
"type": "shell",
7686
"environment_vars": [
77-
"SSH_USERNAME={{user `ssh_username`}}",
78-
"SSH_PASSWORD={{user `ssh_password`}}"
87+
"SSH_USERNAME={{ user `ssh_username` }}"
7988
],
80-
"execute_command": "echo '{{ user `ssh_password` }}' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
81-
"scripts": [ "setup.sh" ],
82-
"type": "shell"
89+
"execute_command": "echo '{{ user `ssh_password` }}' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
90+
"override": {
91+
"virtualbox-iso": {
92+
"scripts": [
93+
"scripts/base.sh",
94+
"scripts/vagrant.sh",
95+
"scripts/riot.sh",
96+
"scripts/toolchains.sh",
97+
"scripts/udev_rules.sh",
98+
"scripts/virtualbox.sh",
99+
"scripts/cleanup.sh"
100+
]
101+
}
102+
}
83103
}
84104
],
85105
"variables": {
86-
"boot_command_prefix": "<enter><wait><f6><esc><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
87-
"cpus": "1",
88-
"disk_size": "65536",
106+
"cpus": "2",
107+
"disk_size": "10240",
89108
"headless": "true",
90-
"iso_checksum": "a06cd926f5855d4f21fb4bc9978a35312f815fbda0d0ef7fdc846861f4fc4600",
109+
"iso_checksum": "e2ecdace33c939527cbc9e8d23576381c493b071107207d2040af72595f8990b",
91110
"iso_checksum_type": "sha256",
92-
"iso_name": "ubuntu-16.04.3-server-amd64.iso",
93-
"iso_path": "/Volumes/Storage/software/ubuntu",
94-
"iso_url": "http://releases.ubuntu.com/16.04/ubuntu-16.04.3-server-amd64.iso",
111+
"iso_name": "ubuntu-18.04.4-server-amd64.iso",
112+
"iso_path": "iso",
113+
"iso_url": "http://cdimage.ubuntu.com/ubuntu/releases/bionic/release/ubuntu-18.04.4-server-amd64.iso",
95114
"memory": "1024",
96-
"preseed" : "preseed.cfg",
97-
"hostname": "vagrant",
98-
"ssh_fullname": "vagrant",
99-
"ssh_password": "vagrant",
100-
"ssh_username": "vagrant",
115+
"hostname": "riot-vm",
116+
"ssh_username": "user",
117+
"ssh_password": "user",
101118
"vagrantfile_template": "vagrantfile.tpl",
102119
"virtualbox_guest_os_type": "Ubuntu_64",
103120
"vm_name": "RIOT-VM"

dist/tools/packer/scripts/base.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apt-get update
2+
apt-get -y upgrade
3+
apt-get -y install linux-headers-$(uname -r)
4+
5+
# Fix locale setup
6+
locale-gen
7+
localectl set-locale LANG="en_US.UTF-8"
8+
9+
# Allow usage of serial port
10+
adduser ${SSH_USERNAME} dialout
11+
12+
echo '%sudo ALL=(ALL:ALL) NOPASSWD:ALL' >> /etc/sudoers
13+
14+
echo "UseDNS no" >> /etc/ssh/sshd_config
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
apt-get -y upgrade
2+
apt-get -y autoremove
3+
apt-get -y clean
4+
5+
echo "cleaning up guest additions"
6+
rm -rf VBoxGuestAdditions_*.iso VBoxGuestAdditions_*.iso.?
7+
8+
echo "cleaning permissions"
9+
chown -R ${SSH_USERNAME}:${SSH_USERNAME} /home/${SSH_USERNAME}
10+
11+
# Remove some packages to get a minimal install
12+
echo "==> Removing all linux kernels except the current one"
13+
dpkg --list | awk '{ print $2 }' | grep 'linux-image-*-generic' | grep -v $(uname -r) | xargs apt-get -y purge
14+
echo "==> Removing linux source"
15+
dpkg --list | awk '{ print $2 }' | grep linux-source | xargs apt-get -y purge
16+
echo "==> Removing documentation"
17+
dpkg --list | awk '{ print $2 }' | grep -- '-doc$' | xargs apt-get -y purge
18+
echo "==> Removing default system Ruby"
19+
apt-get -y purge ruby ri doc
20+
echo "==> Removing obsolete networking components"
21+
apt-get -y purge ppp pppconfig pppoeconf
22+
echo "==> Removing other oddities"
23+
apt-get -y purge popularity-contest installation-report landscape-common wireless-tools wpasupplicant
24+
25+
# Clean up the apt cache
26+
apt-get -y autoremove --purge
27+
apt-get -y autoclean
28+
apt-get -y clean
29+
30+
echo "removing man pages"
31+
rm -rf /usr/share/man/*
32+
echo "removing APT files"
33+
find /var/lib/apt -type f | xargs rm -f
34+
echo "removing any docs"
35+
rm -rf /usr/share/doc/*
36+
echo "removing caches"
37+
find /var/cache -type f -exec rm -rf {} \;
38+
39+
echo "cleaning up tmp"
40+
rm -rf /tmp/*
41+
42+
# Remove Bash history
43+
unset HISTFILE
44+
rm -f /root/.bash_history
45+
rm -f ${SSH_USER_HOME}/.bash_history
46+
47+
# Clean up log files
48+
find /var/log -type f | while read f; do echo -ne '' > "${f}"; done;
49+
50+
echo "clearing last login information"
51+
>/var/log/lastlog
52+
>/var/log/wtmp
53+
>/var/log/btmp
54+
55+
echo "whiteout /"
56+
count=$(df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}')
57+
let count--
58+
dd if=/dev/zero of=/tmp/whitespace bs=1024 count=$count
59+
rm /tmp/whitespace
60+
61+
echo "whiteout /boot"
62+
count=$(df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}')
63+
let count--
64+
dd if=/dev/zero of=/boot/whitespace bs=1024 count=$count
65+
rm /boot/whitespace
66+
67+
echo "clear out swap and disable until reboot"
68+
set +e
69+
swapuuid=$(/sbin/blkid -o value -l -s UUID -t TYPE=swap)
70+
case "$?" in
71+
2|0) ;;
72+
*) exit 1 ;;
73+
esac
74+
set -e
75+
if [ "x${swapuuid}" != "x" ]; then
76+
# Whiteout the swap partition to reduce box size
77+
# Swap is disabled till reboot
78+
swappart=$(readlink -f /dev/disk/by-uuid/$swapuuid)
79+
/sbin/swapoff "${swappart}"
80+
dd if=/dev/zero of="${swappart}" bs=1M || echo "dd exit code $? is suppressed"
81+
/sbin/mkswap -U "${swapuuid}" "${swappart}"
82+
fi
83+
84+
echo "whiteout free space"
85+
dd if=/dev/zero of=/EMPTY bs=1M || echo "dd exit code $? is suppressed"
86+
rm -f /EMPTY
87+
88+
sync
89+
90+
echo "disk usage"
91+
df -h

0 commit comments

Comments
 (0)