Monday, July 01, 2013

Ubuntu Server 12.04.2 KVM Guest Setup

preparing the template image:
#Setup io scheduler and serial console for virsh
sed -i -r 's/GRUB_CMDLINE_LINUX=".*"/GRUB_CMDLINE_LINUX="elevator=deadline console=ttyS0,38400n8 console=tty0"/g' /etc/default/grub && update-grub

#Setup serial terminal console config
cat <<EOF >/etc/init/ttyS0.conf
# ttyS0 - getty
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

exec /sbin/getty -L 38400 ttyS0 vt102

#Setup fstab mount options to relatime(assumes ext4 file systems)
sed -i -r 's/ext4(\s+)errors/ext4\1relatime,errors/g' /etc/fstab

if [[ $EUID -ne 0 ]]; then
echo "script must be run as root. run with sudo" 2>&1
exit 1

echo "Current hostname:$old_name"
echo -n "Enter new server name:"
read new_name
echo "$new_name">/etc/hostname
hostname $new_name
sed -i "s/$old_name/$new_name/g" /etc/hosts

#regenerate udev persistent net rules on reboot
echo "Removing /etc/udev/rules.d/70-persistent-net.rules"
rm /etc/udev/rules.d/70-persistent-net.rules

echo "Regenerating ssh server keys"
rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server

echo "*** You should probably change the password and reboot ***"

No comments:

Post a Comment