Skip to content

Commit

Permalink
Handle network interface repair during firstboot
Browse files Browse the repository at this point in the history
It's easier to fix the ens2/ens3 mismatch in the interfaces file from
the firstboot script than from the virt-builder command.

Also drop SSH and other unnecessary packages during firstboot.
  • Loading branch information
lovett committed Sep 8, 2019
1 parent 8f58ad8 commit be44678
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Makefile
Expand Up @@ -155,7 +155,6 @@ toils-os.qcow2:
--root-password password:toils \ --root-password password:toils \
--append-line /etc/fstab:'LABEL=toils-app /mnt/toils-app ext4 defaults,noatime,noexec 0 0' \ --append-line /etc/fstab:'LABEL=toils-app /mnt/toils-app ext4 defaults,noatime,noexec 0 0' \
--append-line /etc/fstab:'LABEL=toils-storage /mnt/toils-storage ext4 defaults,noatime,noexec 0 0' \ --append-line /etc/fstab:'LABEL=toils-storage /mnt/toils-storage ext4 defaults,noatime,noexec 0 0' \
--run-command 'sed -i "s/ens2/ens3/" /etc/network/interfaces' \
--run-command 'mkdir -p /etc/nginx/sites-enabled' \ --run-command 'mkdir -p /etc/nginx/sites-enabled' \
--run-command 'mkdir -p /etc/php/7.3/fpm/pool.d' \ --run-command 'mkdir -p /etc/php/7.3/fpm/pool.d' \
--run-command 'mkdir /mnt/toils-app' \ --run-command 'mkdir /mnt/toils-app' \
Expand All @@ -164,7 +163,7 @@ toils-os.qcow2:
--copy-in resources/qemu/toils-pool.conf:/etc/php/7.3/fpm/pool.d \ --copy-in resources/qemu/toils-pool.conf:/etc/php/7.3/fpm/pool.d \
--copy-in resources/qemu/toils-setup.sh:/usr/local/sbin \ --copy-in resources/qemu/toils-setup.sh:/usr/local/sbin \
--copy-in resources/qemu/toils-setup.service:/etc/systemd/system \ --copy-in resources/qemu/toils-setup.service:/etc/systemd/system \
--uninstall man-db,git,python2,geoip-database,iso-codes \ --uninstall man-db \
--run-command 'apt autoremove -y' \ --run-command 'apt autoremove -y' \
--firstboot resources/qemu/toils-firstboot.sh --firstboot resources/qemu/toils-firstboot.sh


Expand All @@ -191,11 +190,13 @@ toils-storage.qcow2:
testrun: testrun:
qemu-system-x86_64 -m 256M \ qemu-system-x86_64 -m 256M \
-accel kvm \ -accel kvm \
-nic user,hostfwd=tcp::$(LOCAL_PORT)-:80,hostfwd=tcp::2222-:22 \ -nic user,hostfwd=tcp::$(LOCAL_PORT)-:80 \
-nographic \ -nographic \
-drive file=toils-os.qcow2,index=0,media=disk,format=qcow2 \ -drive file=toils-os.qcow2,index=0,media=disk,format=qcow2 \
-drive file=toils-app.img,index=1,media=disk,format=raw \ -drive file=toils-app.img,index=1,media=disk,format=raw \
-drive file=toils-storage.qcow2,index=2,media=disk,format=qcow2 -drive file=toils-storage.qcow2,index=2,media=disk,format=qcow2

shrink:
qemu-img convert -O qcow2 toils-storage.qcow2 toils-storage-shrunk.qcow2 qemu-img convert -O qcow2 toils-storage.qcow2 toils-storage-shrunk.qcow2
mv toils-storage-shrunk.qcow2 toils-storage.qcow2 mv toils-storage-shrunk.qcow2 toils-storage.qcow2


Expand Down
19 changes: 19 additions & 0 deletions resources/qemu/toils-firstboot.sh
Expand Up @@ -18,6 +18,11 @@
sed -i 's/GRUB_TIMEOUT=5/GRUB_TIMEOUT=0/' /etc/default/grub sed -i 's/GRUB_TIMEOUT=5/GRUB_TIMEOUT=0/' /etc/default/grub
update-grub update-grub


# Fix a disparity with the network device name.
NETWORK_INTERFACE=$(find /sys/class/net -name ens* -exec basename {} \;)
sed -i "s/ens2/$NETWORK_INTERFACE/" /etc/network/interfaces
ifup $NETWORK_INTERFACE

# Package installation # Package installation
apt-get install -y \ apt-get install -y \
composer \ composer \
Expand All @@ -43,3 +48,17 @@ systemctl restart php7.3-fpm nginx


systemctl enable toils-setup.service systemctl enable toils-setup.service
systemctl start toils-setup.service systemctl start toils-setup.service

apt purge -y \
apt-listchanges \
debian-faq \
doc-debian \
geoip-database \
git \
iso-codes \
krb5-locales \
openssh-client \
openssh-server \
python2

apt autoremove -y

0 comments on commit be44678

Please sign in to comment.