-
Notifications
You must be signed in to change notification settings - Fork 1
/
ubuntu.logic
150 lines (148 loc) · 5.33 KB
/
ubuntu.logic
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#
set -e
#
NEEDED_PACKAGES=sudo,openssh-server,file,kbd,lsof
PKGLIST=${NEEDED_PACKAGES},bash-completion,less,bzip2,acpid,net-tools
DEBOOTSTRAP=$(which debootstrap)
MIRROR=http://archive.ubuntu.com/ubuntu
IMAGE_NEEDS="git vim language-pack-en gcc g++ make euca2ools"
UUFILE=/etc/apt/apt.conf.d/20auto-upgrades
#
if [ ${ARCH} = x86_64 ]; then
ARCH=amd64
fi
#
installBaseSystem(){
echo "* Installing Ubuntu ${RELEASE} ${ARCH} system to ${MOUNTDIR}"
debootstrap --no-check-gpg --arch=${ARCH} --verbose --include=${PKGLIST},${KERNEL} ${RELEASE} ${MOUNTDIR} ${MIRROR}
}
#
setLocale(){
# set locale
echo "en_US.UTF-8 UTF-8" >> ${MOUNTDIR}/etc/locale.gen
chroot ${MOUNTDIR} locale-gen en_US.UTF-8
chroot ${MOUNTDIR} update-locale LANG=en_US.UTF-8
}
#
createRepositories(){
echo "deb ${MIRROR} ${RELEASE} main restricted universe multiverse" > ${MOUNTDIR}/etc/apt/sources.list
echo "deb ${MIRROR} ${RELEASE}-updates main restricted universe multiverse" >> ${MOUNTDIR}/etc/apt/sources.list
echo "deb ${MIRROR} ${RELEASE}-security main restricted universe multiverse" >> ${MOUNTDIR}/etc/apt/sources.list
if [[ ${BACKPORTS} = yes ]]; then
echo "deb ${MIRROR} ${RELEASE}-backports main restricted universe multiverse" >> ${MOUNTDIR}/etc/apt/sources.list
fi
chroot ${MOUNTDIR} apt-get update
}
#
upgradeSystem(){
chroot ${MOUNTDIR} apt-get -y install apt-transport-https || true
chroot ${MOUNTDIR} bash -c "DEBIAN_FRONTEND=noninteractive apt-get -y install extlinux cloud-init cloud-utils linux-image-virtual cloud-initramfs-growroot"
chroot ${MOUNTDIR} apt-get -y install ${IMAGE_NEEDS}
chroot ${MOUNTDIR} apt-get -y dist-upgrade
chroot ${MOUNTDIR} apt-get -y autoremove || true
}
#
adjustCloudSettings(){
# Allow SSH in as root, even though it might be unsecure
sed -i 's/disable_root: true/disable_root: false/' ${MOUNTDIR}/etc/cloud/cloud.cfg
sed -i "s/name: ubuntu/name: ${CLOUD_USER}/" ${MOUNTDIR}/etc/cloud/cloud.cfg
# Since we implemented "backdoor" we want to be able to use it :)
sed -i "s/PermitRootLogin yes/PermitRootLogin without-password/" ${MOUNTDIR}/etc/ssh/sshd_config
#
# set timezone
cp ${MOUNTDIR}/usr/share/zoneinfo/America/New_York ${MOUNTDIR}/etc/localtime
}
#
configureFSTab(){
# Setup fstab
echo "# /etc/fstab: static file system information.
proc /proc proc nodev,noexec,nosuid 0 0
UUID=${UUID} / ext4 errors=remount-ro 0 1
" > ${MOUNTDIR}/etc/fstab
# avoiding micro /tmp of 1024k size
rm -fv ${MOUNTDIR}/etc/init/mounted-tmp.conf
}
#
configureBoot(){
# Setting-up initramfs
chroot ${MOUNTDIR} update-initramfs -u
KERNEL=$(chroot ${MOUNTDIR} find boot -name 'vmlinuz-*' | sort | tail -n 1)
RAMDISK=$(chroot ${MOUNTDIR} find boot -name 'initrd.img-*' | sort | tail -n 1)
mkdir -p ${MOUNTDIR}/boot/extlinux
extlinux --install ${MOUNTDIR}/boot/extlinux
chroot ${MOUNTDIR} ln -snf . /boot/boot
echo "default linux
timeout 10
label linux
kernel /${KERNEL}
append initrd=/${RAMDISK} root=UUID=${UUID} rootfstype=ext4 console=tty0 console=ttyS0,115200 net.ifnames=0 ro" > ${MOUNTDIR}/boot/extlinux/extlinux.conf
}
#
configureNetwork(){
#
mkdir -p /etc/network
chroot ${MOUNTDIR} apt-get -y install ifupdown
#
echo "# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The normal eth0
auto eth0
iface eth0 inet dhcp
" > ${MOUNTDIR}/etc/network/interfaces
}
#
configureModules(){
echo "# disable pc speaker
blacklist pcspkr" > ${MOUNTDIR}/etc/modprobe.d/blacklist.conf
echo "# Required for cinder hotplug
acpiphp
pci_hotplug
" >> ${MOUNTDIR}/etc/modules
}
#
cleanupSystem(){
echo "* removing SSH keys ..."
rm -f ${MOUNTDIR}/etc/ssh/ssh_host_*
echo "* removing UDEV persistent net rules ..."
rm -f ${MOUNTDIR}/etc/udev/rules.d/*-persistent-net.rules
rm -f ${MOUNTDIR}/lib/udev/write_net_rules
echo "* cleaning downloaded APT archives ..."
rm -f ${MOUNTDIR}/var/cache/apt/archives/*.deb
if [ -f ${MOUNTDIR}/${UUFILE} ]; then
sed -i 's:1:0:g' ${MOUNTDIR}/${UUFILE}
fi
}
#
setupConsole(){
if [ -d ${MOUNTDIR}/etc/systemd ]; then
mkdir -p ${MOUNTDIR}/etc/systemd/system/getty@tty1.service.d
echo '[Service]
TTYVTDisallocate=no' > ${MOUNTDIR}/etc/systemd/system/getty@tty1.service.d/noclear.conf
chroot ${MOUNTDIR} systemctl enable serial-getty@ttyS0.service || true
fi
if [ -f ${MOUNTDIR}/etc/kbd/config ]; then
# Turn off console blanking which is *very* annoying and increase KEYBOARD_DELAY because it can be annoying over network.
sed -i s/^BLANK_TIME=.*/BLANK_TIME=0/ ${MOUNTDIR}/etc/kbd/config
sed -i s/^POWERDOWN_TIME=.*/POWERDOWN_TIME=0/ ${MOUNTDIR}/etc/kbd/config
sed -i 's/^[ \t#]KEYBOARD_DELAY=.*/KEYBOARD_DELAY=1000/' ${MOUNTDIR}/etc/kbd/config
fi
}
#
setHostname(){
echo "${DISTRO}.${RELEASE}.openstack" > ${MOUNTDIR}/etc/hostname
if [[ ${RELEASE} = artful ]] || [[ ${RELEASE} = bionic ]] || [[ ${RELEASE} = cosmic ]]; then
chroot ${MOUNTDIR} systemctl enable systemd-networkd
chroot ${MOUNTDIR} apt-get -y install policykit-1
rm -fv ${MOUNTDIR}/etc/resolv.conf
chroot ${MOUNTDIR} ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
fi
}
#
createCloudUser(){
echo "* adding cloud user ${CLOUD_USER} ..."
chroot ${MOUNTDIR} adduser --gecos ${DISTRO}-cloud-user --disabled-password --quiet ${CLOUD_USER}
}
#