<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sugarlabs.org/index.php?action=history&amp;feed=atom&amp;title=Machine%2Ftemplate-xenial</id>
	<title>Machine/template-xenial - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sugarlabs.org/index.php?action=history&amp;feed=atom&amp;title=Machine%2Ftemplate-xenial"/>
	<link rel="alternate" type="text/html" href="https://wiki.sugarlabs.org/index.php?title=Machine/template-xenial&amp;action=history"/>
	<updated>2026-05-25T10:27:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://wiki.sugarlabs.org/index.php?title=Machine/template-xenial&amp;diff=100549&amp;oldid=prev</id>
		<title>Scg: Created page with &quot;== VM Creation (host part) ==   virt-install -v --accelerate --nographics -x console=ttyS0,115200 \  --name template-xenial --vcpus=3 --ram $((1 * 1024)) \  --os-type=linux --...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.sugarlabs.org/index.php?title=Machine/template-xenial&amp;diff=100549&amp;oldid=prev"/>
		<updated>2017-08-07T02:06:28Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== VM Creation (host part) ==   virt-install -v --accelerate --nographics -x console=ttyS0,115200 \  --name template-xenial --vcpus=3 --ram $((1 * 1024)) \  --os-type=linux --...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== VM Creation (host part) ==&lt;br /&gt;
&lt;br /&gt;
 virt-install -v --accelerate --nographics -x console=ttyS0,115200 \&lt;br /&gt;
 --name template-xenial --vcpus=3 --ram $((1 * 1024)) \&lt;br /&gt;
 --os-type=linux --os-variant=ubuntu16.04 --network bridge:br0 \&lt;br /&gt;
 --disk path=/var/lib/libvirt/images/boot/template-xenial-boot.img,bus=virtio,size=0.25,format=raw \&lt;br /&gt;
 --disk path=/dev/justice/template-xenial-root,bus=virtio,size=10 \&lt;br /&gt;
 --location http://ubuntu.media.mit.edu/ubuntu/dists/xenial/main/installer-amd64/&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Obs&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;format=raw&amp;#039;&amp;#039; is mandatory, otherwise qcow2 format will be used by default. &lt;br /&gt;
&amp;#039;&amp;#039;raw&amp;#039;&amp;#039; format allows us to easily create device mappings for the image.&lt;br /&gt;
&lt;br /&gt;
The new VM will boot into the installer. Answer all questions with the defaults, except:&lt;br /&gt;
&lt;br /&gt;
# Hostname: template-precise&lt;br /&gt;
# Mirror: enter information manually&lt;br /&gt;
# Mirror hostname: ubuntu.media.mit.edu&lt;br /&gt;
# (create your user with a strong password and no encrypted home)&lt;br /&gt;
# Partitioning: manual (see Partitioning below)&lt;br /&gt;
# Automatically install security updates&lt;br /&gt;
# Software selection:&lt;br /&gt;
#* Basic Ubuntu Server&lt;br /&gt;
#* OpenSSH server&lt;br /&gt;
# GRUB: let the installer setup grub on /dev/vba (which contains /boot)&lt;br /&gt;
&lt;br /&gt;
== Partitioning ==&lt;br /&gt;
&lt;br /&gt;
The goal is to have a small disk file for the MBR and /boot, and a larger raw filesystem in&lt;br /&gt;
an LVM Logical Volume. We don&amp;#039;t want the LV to be partitioned because this makes it harder to&lt;br /&gt;
resize, mount, etc.&lt;br /&gt;
&lt;br /&gt;
Now create a partition table in the smallest disk (256MB) and create a single partition in it.&lt;br /&gt;
Format this partition as ext4, labeled &amp;quot;boot&amp;quot; and mounted as /boot.&lt;br /&gt;
&lt;br /&gt;
The installer won&amp;#039;t let you format the entire disk as a filesystem, so go ahead and partition&lt;br /&gt;
the 10GB disk too, then create a primary partition in it and format it as ext4, mounted as /&lt;br /&gt;
and labeled &amp;quot;template-xenial&amp;quot; (&amp;#039;&amp;#039;&amp;#039;&amp;quot;template-xenial-root&amp;quot; would exceed the ext4 limit&amp;#039;&amp;#039;&amp;#039;).&lt;br /&gt;
&lt;br /&gt;
And yes.. just in case you&amp;#039;re wondering. We don&amp;#039;t use swap partitions.&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll have to fix the disk later.&lt;br /&gt;
&lt;br /&gt;
== First boot ==&lt;br /&gt;
After installation has finished and OS is restarted, it will boot but we won&amp;#039;t have serial console access &lt;br /&gt;
(&amp;lt;code&amp;gt;virsh console template-xenial&amp;lt;/code&amp;gt;). This is due the getty service for serial device is disabled by default on Ubuntu 16.04.&lt;br /&gt;
We&amp;#039;ll fix this later.&lt;br /&gt;
&lt;br /&gt;
== Switch the root filesystem to an LV ==&lt;br /&gt;
&lt;br /&gt;
When the machine is offline, go to the host to recreate the root filesystem directly as an LV (as opposed to a partitioned volume)&lt;br /&gt;
&lt;br /&gt;
First of all, we need to set up the device mapping for the first and only partition where the root filesystem resides.&lt;br /&gt;
 &lt;br /&gt;
 kpartx -av  /dev/justice/template-xenial-root&lt;br /&gt;
&lt;br /&gt;
Mount the root partition:&lt;br /&gt;
&lt;br /&gt;
 mkdir /mnt/template-xenial-root&lt;br /&gt;
 mount /dev/mapper/justice-template--xenial-root1 /mnt/template-xenial-root&lt;br /&gt;
&lt;br /&gt;
Now create and format a new LV:&lt;br /&gt;
&lt;br /&gt;
  lvcreate -L 10G -n template-xenial-root2 justice&lt;br /&gt;
  mkfs.ext4 -L template-xenial -O flex_bg,extent,uninit_bg,sparse_super /dev/justice/template-xenial-root2&lt;br /&gt;
  tune2fs -c -1 -i 0 /dev/justice/template-xenial-root2&lt;br /&gt;
  mkdir /mnt/template-xenial-root2&lt;br /&gt;
  mount /dev/justice/template-xenial-root2 /mnt/template-xenial-root2&lt;br /&gt;
&lt;br /&gt;
Move the files over:&lt;br /&gt;
&lt;br /&gt;
  rsync -HAXphax --numeric-ids /mnt/template-xenial-root/ /mnt/template-xenial-root2/&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;NOTE&amp;#039;&amp;#039;&amp;#039;: By default, Ubuntu 16.04 uses UUID in /etc/fstab in order to mount partitions. Since we have changed the root &lt;br /&gt;
partition to a new disk, the UUID will change. Aside from that, the grub.cfg also specifies the location of the root filesystem&lt;br /&gt;
using UUID notation (ex: /vmlinuz-4.4.0-89-generic root=UUID=0ad5d004-e5dd-4b93-abe4-2bb0ba4fd94a).&lt;br /&gt;
&lt;br /&gt;
Before we umount the filesystems, let&amp;#039;s create a chroot environment and fix previous issues:&lt;br /&gt;
&lt;br /&gt;
  kpartx -av /var/lib/libvirt/images/boot/template-xenial-boot.img&lt;br /&gt;
  mount /dev/mapper/loop0p1 /mnt/template-xenial-root2/boot&lt;br /&gt;
  mount --bind /dev/ /mnt/template-xenial-root2/dev/&lt;br /&gt;
  mount -t proc proc /mnt/template-xenial-root2/proc/&lt;br /&gt;
  mount -t sysfs sys /mnt/template-xenial-root2/sys/&lt;br /&gt;
  chroot /mnt/template-xenial-root2/&lt;br /&gt;
&lt;br /&gt;
Once inside the chroot environment:&lt;br /&gt;
&lt;br /&gt;
* Fix serial console access by making getty listen on /dev/ttyS0:&lt;br /&gt;
  systemctl enable serial-getty@ttyS0.service&lt;br /&gt;
&lt;br /&gt;
* Replace UUID with device name for root fs location inside /boot/grub/grub.cfg&lt;br /&gt;
  sed -i -r &amp;quot;s/root=UUID=[0-9a-f-]+/root=\/dev\/vdb/&amp;quot; /boot/grub/grub.cfg&lt;br /&gt;
&lt;br /&gt;
* Adjust /etc/fstab to mount the filesystems from &amp;quot;LABEL=boot&amp;quot; and &amp;quot;LABEL=template-xenial&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally (VERY IMPORTANT), umount all filesystems before starting the VM:&lt;br /&gt;
  umount /mnt/template-xenial-root2/boot/&lt;br /&gt;
  umount /mnt/template-xenial-root2/dev/&lt;br /&gt;
  umount /mnt/template-xenial-root2/proc/&lt;br /&gt;
  umount /mnt/template-xenial-root2/sys/&lt;br /&gt;
  umount /mnt/template-xenial-root2/ /mnt/template-xenial-root/&lt;br /&gt;
&lt;br /&gt;
Get rid of the old root and rename the new one on top of it&lt;br /&gt;
&lt;br /&gt;
  lvremove /dev/justice/template-xenial-root&lt;br /&gt;
  lvrename justice template-xenial-root2 template-xenial-root&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Configuration after system start ==&lt;br /&gt;
&lt;br /&gt;
After the installation, the machine will boot automatically and you&amp;#039;ll be dropped into the serial console.&lt;br /&gt;
You can return to the console at any time by doing:&lt;br /&gt;
&lt;br /&gt;
 virsh console template-xenial&lt;br /&gt;
&lt;br /&gt;
Login with your installation username and password, then become root:&lt;br /&gt;
&lt;br /&gt;
 sudo -i&lt;br /&gt;
&lt;br /&gt;
* Adjust /etc/default/grub:&lt;br /&gt;
** Set `GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;console=ttyS0,115200&amp;quot;` (and remove the obnoxious &amp;quot;quiet splash&amp;quot;)&lt;br /&gt;
** Uncomment GRUB_DISABLE_LINUX_UUID&lt;br /&gt;
* Update grub: `update-grub`&lt;br /&gt;
&lt;br /&gt;
* Get rid of the restricted repositories from /etc/apt/sources.list (virtual machines don&amp;#039;t need any non-free drivers anyway).&lt;br /&gt;
* Add a few useful packages:&lt;br /&gt;
&lt;br /&gt;
 apt-get install etckeeper bash-completion strace munin-node postfix vim aptitude&lt;br /&gt;
&lt;br /&gt;
Note: etckeeper uses git by default :)&lt;br /&gt;
&lt;br /&gt;
When prompted on how to configure postfix, say &amp;quot;Internet site&amp;quot;.&lt;br /&gt;
Afterwards, edit `/etc/postfix/main.cs` by hand and set `inet_interfaces = loopback-only` and restart postfix.&lt;br /&gt;
&lt;br /&gt;
* Monitor mail for root:&lt;br /&gt;
&lt;br /&gt;
 echo &amp;gt;&amp;gt;/etc/aliases &amp;quot;root: systems-logs@lists.sugarlabs.org&amp;quot;&lt;br /&gt;
 newaliases&lt;br /&gt;
&lt;br /&gt;
* Switch to the virtual kernel:&lt;br /&gt;
&lt;br /&gt;
 apt-get install linux-image-virtual linux-virtual&lt;br /&gt;
 apt-get purge linux-image-generic&lt;br /&gt;
 apt-get autoremove&lt;br /&gt;
 update-grub&lt;br /&gt;
&lt;br /&gt;
=== Network interface setup ===&lt;br /&gt;
&lt;br /&gt;
We use [http://en.wikipedia.org/wiki/6to4 6to4] to reach the closest IPv6 anycast relay.&lt;br /&gt;
Append the following to /etc/network/interfaces:&lt;br /&gt;
&lt;br /&gt;
 auto eth0&lt;br /&gt;
 iface eth0 inet static&lt;br /&gt;
	address 18.85.44.67&lt;br /&gt;
	netmask 255.255.255.0&lt;br /&gt;
	gateway 18.85.44.1&lt;br /&gt;
	# dns-* options are implemented by the resolvconf package, if installed&lt;br /&gt;
	dns-nameservers 18.71.0.151 18.70.0.160 18.72.0.3&lt;br /&gt;
	dns-search sugarlabs.org&lt;br /&gt;
&lt;br /&gt;
 auto tun6to4&lt;br /&gt;
 iface tun6to4 inet6 v4tunnel&lt;br /&gt;
	# printf &amp;quot;2002:%02x%02x:%02x%02x::1\n&amp;quot; `echo $IPV4ADDR | tr . &amp;#039; &amp;#039;`&lt;br /&gt;
	address 2002:1255:2c43::1&lt;br /&gt;
	netmask 16&lt;br /&gt;
	gateway ::192.88.99.1&lt;br /&gt;
	endpoint any&lt;br /&gt;
	local 18.85.44.67&lt;br /&gt;
&lt;br /&gt;
=== Other configurations === &lt;br /&gt;
&lt;br /&gt;
Add these to /etc/sudoers:&lt;br /&gt;
&lt;br /&gt;
 #bernie: forward ssh-agent&lt;br /&gt;
 Defaults    env_keep+=&amp;quot;SSH_AUTH_SOCK&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 #bernie: &lt;br /&gt;
 %sudo ALL=(ALL:ALL) NOPASSWD: ALL&lt;br /&gt;
&lt;br /&gt;
* Install your ssh keys to /root/.ssh/authorized_keys and to your user account. Also install the wizbackup keys for [[Service/backup]].&lt;br /&gt;
&lt;br /&gt;
Once your keys are installed, you might SSH in and start configuration using a SSH session.&lt;br /&gt;
&lt;br /&gt;
Log in with &amp;quot;ssh -A template-xenial.sugarlabs.org&amp;quot; to forward your ssh-agent and copy files from sunjammer&lt;br /&gt;
&lt;br /&gt;
 rsync -aP &amp;lt;your-user&amp;gt;@sunjammer.sugarlabs.org:/usr/src/devtools/ /usr/src/devtools/&lt;br /&gt;
 ln -sf /usr/src/devtools/sysadm/bashrc.sh /etc/skel/.bashrc&lt;br /&gt;
 ln -sf /usr/src/devtools/sysadm/bashrc.sh /root/.bashrc&lt;br /&gt;
 ln -sf /usr/src/devtools/sysadm/zzz_profile.sh /etc/profile.d/zzz_profile.sh&lt;br /&gt;
 ln -sf /usr/src/devtools/conf/vimrc /etc/vim/vimrc.local&lt;br /&gt;
&lt;br /&gt;
 vim /etc/bash.bashrc # comment out code messing with PS1&lt;br /&gt;
 vim /etc/login.defs # set umask 002&lt;br /&gt;
&lt;br /&gt;
* Create /etc/zzz_profile.conf:&lt;br /&gt;
&lt;br /&gt;
 HOST_COLOR=&amp;#039;\033[1;40;37m&amp;#039;&lt;br /&gt;
&lt;br /&gt;
* Disable PasswordAuthentication in /etc/ssh/sshd_config, then restart ssh&lt;br /&gt;
&lt;br /&gt;
* Set a blank password for root, to be used to log in from the console only&lt;br /&gt;
&lt;br /&gt;
  passwd -d&lt;br /&gt;
&lt;br /&gt;
* Insert into /etc/munin/munin.node:&lt;br /&gt;
&lt;br /&gt;
 #bernie&lt;br /&gt;
 allow ^208\.118\.235\.53$     # sunjammer.sugarlabs.org&lt;br /&gt;
 allow ^2001:4830:134:7::11$   # sunjammer.sugarlabs.org (IPv6)&lt;br /&gt;
&lt;br /&gt;
* Add/remove munin plugins&lt;br /&gt;
&lt;br /&gt;
 cd /etc/munin/plugins&lt;br /&gt;
 rm df_inode entropy forks fw_packets if_err_ens2 open_files open_inodes threads uptime processes proc_pri swap&lt;br /&gt;
&lt;br /&gt;
* Disable unused services (They are dependencies of the ubuntu-server package):&lt;br /&gt;
  systemctl disable snapd.service&lt;br /&gt;
  systemctl disable atd.service &lt;br /&gt;
  systemctl disable iscsid.service &lt;br /&gt;
  systemctl disable lvm2-monitor.service&lt;br /&gt;
  systemctl disable open-vm-tools.service&lt;br /&gt;
  systemctl disable lxcfs.service&lt;br /&gt;
  systemctl disable lxd-containers.service&lt;/div&gt;</summary>
		<author><name>Scg</name></author>
	</entry>
</feed>