VMware Template Ubuntu 20.04: verschil tussen versies

Uit WaaaghPedia
Geen bewerkingssamenvatting
 
(6 tussenliggende versies door dezelfde gebruiker niet weergegeven)
Regel 1: Regel 1:
https://docs.microsoft.com/nl-nl/azure/cloud-adoption-framework/manage/hybrid/server/best-practices/vmware-ubuntu-template
== Installeer Ubuntu ==


https://jimangel.io/post/create-a-vm-template-ubuntu-18.04/
== Ubuntu updaten ==
 
[[Categorie:Ubuntu]]
[[Categorie:ToDo]]
[[Categorie:VMWare Templates]]
[[Categorie:Tutorials]]
 
 
== INSTALATIE UBUNTU ==
 
== UPDATEN UBUNTU ==
<pre># Ik heb voor het gemak -y toegevoegd maar ben hier voorzichtig mee. Deze tag zorgt er voor dat updates automatisch geïnstalleerd worden.
<pre># Ik heb voor het gemak -y toegevoegd maar ben hier voorzichtig mee. Deze tag zorgt er voor dat updates automatisch geïnstalleerd worden.
sudo apt -y update
sudo apt -y update
Regel 20: Regel 10:
sudo apt -y install open-vm-tools</pre>
sudo apt -y install open-vm-tools</pre>


==Template afronden==
== Persoonlijke Tweaks (mag je overslaan) ==
Gooi hostname leeg
<pre>echo 'alias vi="nano"' >> ~/.bashrc
<pre>sudo sed -i 's/preserve_hostname: false/preserve_hostname: true/g' /etc/cloud/cloud.cfg
echo 'alias ll="ls -ls"' >> ~/.bashrc
echo 'export PS1="\[\033[38;5;11m\]\u\[$(tput sgr0)\]\[\033[38;5;15m\]@\h\[$(tput sgr0)\]\[\033[38;5;6m\][\w]:\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]"' >> ~/.bashrc</pre>
 
==Template afronden=={{Alertbox/Info
|info=Dit gedeelte moet na elke aanpassing aan het template opnieuw gedaan worden.
}}
<pre>#Stop services for cleanup
sudo service rsyslog stop
 
#verwijder audit logs
if [ -f /var/log/wtmp ]; then
    sudo truncate -s0 /var/log/wtmp
fi
if [ -f /var/log/lastlog ]; then
    sudo truncate -s0 /var/log/lastlog
fi
 
#leeg /tmp map
sudo rm -rf /tmp/*
sudo rm -rf /var/tmp/*
 
#verwijder host SSH keys
sudo rm -f /etc/ssh/ssh_host_*
 
#genereer SSH Host Keys bij nieuwe bootup wanneer deze er niet meer is.
sudo cat << 'EOL' | sudo tee /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# dynamically create hostname (optional)
#if hostname | grep localhost; then
#    hostnamectl set-hostname "$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo '')"
#fi
test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
exit 0
EOL
 
# make sure the script is executable
sudo chmod +x /etc/rc.local
 
#reset hostname
# prevent cloudconfig from preserving the original hostname
sudo sed -i 's/preserve_hostname: false/preserve_hostname: true/g' /etc/cloud/cloud.cfg
sudo truncate -s0 /etc/hostname
sudo truncate -s0 /etc/hostname
sudo hostnamectl set-hostname localhost</pre>
sudo hostnamectl set-hostname localhost
 
#schoon apt op
sudo apt clean


#schoon netwerk op
sudo sed -i 's/optional: true/dhcp-identifier: mac/g' /etc/netplan/50-cloud-init.yaml


Verwijder terminal history
# Cloud-init logs opschonen
<pre>cat /dev/null > ~/.bash_history && history -c</pre>
sudo cloud-init clean --logs


#Schoon terminal history op.
sudo cat /dev/null > ~/.bash_history && history -c
cat /dev/null > ~/.bash_history && history -c
history -w


Shutdown
#Uitschakelen
<pre>sudo shutdown now</pre>
sudo shutdown -h now</pre>


== Converteer naar Template ==
== Converteer naar Template ==
Regel 38: Regel 88:


Rechtermuistoets klik op de VM die je wilt veranderen naar een template. Ga naar Clone en vervolgens naar Clone to template. Volg de wizard.
Rechtermuistoets klik op de VM die je wilt veranderen naar een template. Ga naar Clone en vervolgens naar Clone to template. Volg de wizard.
== Bronnen ==
* https://docs.microsoft.com/nl-nl/azure/cloud-adoption-framework/manage/hybrid/server/best-practices/vmware-ubuntu-template
* https://jimangel.io/post/create-a-vm-template-ubuntu-18.04/
[[Categorie:Ubuntu]]
[[Categorie:ToDo]]
[[Categorie:VMWare Templates]]
[[Categorie:Tutorials]]

Huidige versie van 1 jul 2021 om 17:46

Installeer Ubuntu

Ubuntu updaten

# Ik heb voor het gemak -y toegevoegd maar ben hier voorzichtig mee. Deze tag zorgt er voor dat updates automatisch geïnstalleerd worden.
sudo apt -y update
sudo apt -y upgrade

Tools installeeren

# Waarschijnlijk al geïnstalleerd.
sudo apt -y install open-vm-tools

Persoonlijke Tweaks (mag je overslaan)

echo 'alias vi="nano"' >> ~/.bashrc
echo 'alias ll="ls -ls"' >> ~/.bashrc
echo 'export PS1="\[\033[38;5;11m\]\u\[$(tput sgr0)\]\[\033[38;5;15m\]@\h\[$(tput sgr0)\]\[\033[38;5;6m\][\w]:\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]"' >> ~/.bashrc

Template afronden

Dit gedeelte moet na elke aanpassing aan het template opnieuw gedaan worden.
#Stop services for cleanup
sudo service rsyslog stop

#verwijder audit logs
if [ -f /var/log/wtmp ]; then
    sudo truncate -s0 /var/log/wtmp
fi
if [ -f /var/log/lastlog ]; then
    sudo truncate -s0 /var/log/lastlog
fi

#leeg /tmp map
sudo rm -rf /tmp/*
sudo rm -rf /var/tmp/*

#verwijder host SSH keys
sudo rm -f /etc/ssh/ssh_host_*

#genereer SSH Host Keys bij nieuwe bootup wanneer deze er niet meer is.
sudo cat << 'EOL' | sudo tee /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# dynamically create hostname (optional)
#if hostname | grep localhost; then
#    hostnamectl set-hostname "$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo '')"
#fi
test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
exit 0
EOL

# make sure the script is executable
sudo chmod +x /etc/rc.local

#reset hostname
# prevent cloudconfig from preserving the original hostname
sudo sed -i 's/preserve_hostname: false/preserve_hostname: true/g' /etc/cloud/cloud.cfg
sudo truncate -s0 /etc/hostname
sudo hostnamectl set-hostname localhost

#schoon apt op
sudo apt clean

#schoon netwerk op
sudo sed -i 's/optional: true/dhcp-identifier: mac/g' /etc/netplan/50-cloud-init.yaml

# Cloud-init logs opschonen
sudo cloud-init clean --logs

#Schoon terminal history op.
sudo cat /dev/null > ~/.bash_history && history -c
cat /dev/null > ~/.bash_history && history -c
history -w

#Uitschakelen
sudo shutdown -h now

Converteer naar Template

Pas de systeem instellingen aan.

Rechtermuistoets klik op de VM die je wilt veranderen naar een template. Ga naar Clone en vervolgens naar Clone to template. Volg de wizard.


Bronnen