-
Notifications
You must be signed in to change notification settings - Fork 0
/
xenify_trusty.sh
executable file
·93 lines (76 loc) · 2.53 KB
/
xenify_trusty.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
apt-get update
apt-get install -fy cloud-init xenstore-utils curl wget byobu
# Fix cloud-init #1523921 - # https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1523921
wget -qO - 'http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/diff/1084.2.2?context=3' | patch -p0 -d /usr/lib/python2.7/dist-packages
# attach data drive
cat > /etc/cloud/cloud.cfg.d/10_data.cfg <<EOF
disk_setup:
/dev/xvdb:
type: mbr
layout: True
overwrite: False
fs_setup:
- label: data
filesystem: ext4
device: /dev/xvdb1
partition: auto
mounts:
- [ /dev/xvdb1, /mnt ]
mount_default_fields: [ None, None, "ext4", "defaults,nobarrier,noatime,nobootwait", "0","2" ]
EOF
# setup cloud-init
echo 'datasource_list: [ ConfigDrive, CloudStack, None ]' > /etc/cloud/cloud.cfg.d/90_dpkg.cfg
# cleanup cloud-init
addgroup --system --quiet netdev
rm -f /etc/udev/rules.d/70*
ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules
# set some stuff
echo 'vm.swappiness = 0' >> /etc/sysctl.conf
# fix fstab
cat > /etc/fstab <<'EOF'
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/xvda1 / ext3 errors=remount-ro,noatime,barrier=0 0 1
EOF
export DEBIAN_FRONTEND=noninteractive
# set ssh keys to regenerate at first boot if missing
# this is a fallback to catch when cloud-init fails doing the same
# it will do nothing if the keys already exist
cat > /etc/rc.local <<'EOF'
dpkg-reconfigure openssh-server
echo > /etc/rc.local
EOF
# console fix for PV Ubuntus
cat > /etc/init/hvc0.conf <<'EOF'
# hvc0 - getty
#
# This service maintains a getty on hvc0 from the point the system is
# started until it is shut down again.
start on stopped rc or RUNLEVEL=[2345]
stop on runlevel [!2345]
respawn
exec /sbin/getty -L 115200 hvc0 vt102
EOF
# clean up
apt-get -y clean
apt-get -y autoremove
sed -i '/.*cdrom.*/d' /etc/apt/sources.list
rm -f /etc/ssh/ssh_host_*
rm -f /var/cache/apt/archives/*.deb
rm -f /var/cache/apt/*cache.bin
rm -f /var/lib/apt/lists/*_Packages
rm -f /etc/resolv.conf
rm -f /root/.bash_history
rm -f /root/.nano_history
rm -f /root/.lesshst
rm -f /root/.ssh/known_hosts
rm -rf /tmp/tmp
for k in $(find /var/log -type f); do echo > $k; done
for k in $(find /tmp -type f); do rm -f $k; done
for k in $(find /root -type f \( ! -iname ".*" \)); do rm -f $k; done