-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathubuntu-server-oem
152 lines (94 loc) · 4.47 KB
/
ubuntu-server-oem
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
151
152
## Why OEM?
Creating an "OEM Install" allows a user to create an image that can be installed
on many systems, which requests more information on the next boot up, or to use a
VM base image that can be cloned any number of times. Windows admins may be familiar
with this process using the "sysprep" tool. The same can be done on linux by combining
a few tools.
While Ubuntu desktop has a built-in OEM mode (guide available [here](https://help.ubuntu.com/community/Ubuntu_OEM_Installer_Overview), Ubuntu Server does not, requiring you to
build your own.
## Base Install
Start by doing a standard ubuntu server install (we're using 18.04).
Use "ubuntu" as the username and password.
When the install is done, make any configuration changes you want added to the base
image. For example:
- package updates
- package installs
- modifications to configuration files
- cronjobs
- modifications to /etc/skel
## Suggested scripts
TODO :
- Add partition expand script
something like this (NOTE: UNTESTED):
start=$(cat /sys/block/mmcblk0/mmcblk0p3/start)
end=$(($start+$(cat /sys/block/mmcblk0/mmcblk0p3/size)))
newend=$(($(cat /sys/block/mmcblk0/size)-8))
if [ "$newend" -gt "$end" ]
then
parted -s /dev/mmcblk0 unit s resize 3 $start $newend
fi
## Prepare for OEM Configuration
When these changes are complete, and you're ready to creae your clean image,
install package `oem-config`:
```bash
$ sudo apt update && sudo apt install -y oem-config ;
```
Once installed, run the following command. This will setup the system to refresh
itself on the next boot.
```bash
$ sudo oem-config-prepare
```
Finally, once complete, shut the system down.
Your system is now ready to clone and boot clones.
## TODO BEFORE COMPLETE
TODO: Look at this alternative option:
https://docs.openstack.org/image-guide/ubuntu-image.html
https://askubuntu.com/questions/736484/oem-install-ubuntu-server-14-04
https://askubuntu.com/questions/717842/oem-install-of-ubuntu-server-14-04-3
https://wiki.ubuntu.com/OemConfigServer
## ALTERNATIVE METHOD
https://docs.openstack.org/image-guide/ubuntu-image.html
``` bash
$ sudo apt-get install cloud-init -y
```
```bash
$ sudo dpkg-reconfigure cloud-init
```
Uncheck "ec2".
Run the sysprep command on the vmname in virsh
```bash
virt-sysprep -d vmname
```
## Method 2
Run a normal install. Reboot, make whatever changes are required.
Then, shut down, make a clone to sysprep.
Then, find the VM name, and run `virt-sysprep` on it. You can find VM
names with `virsh list --all` if you're not sure.
Run a dry run to see what commands will run. This will run the full process
but throw away the changes at the end.
```bash
$ virt-sysprep --dry-run --domain vmname
```
If you are satisfied, run without `--dry-run`:
```bash
$ virt-sysprep --domain vmname
```
Additioally, options like `--firstboot` or `--firstboot-command` can be used
to insert startup scripts.
These can be found here:
http://libguestfs.org/virt-sysprep.1.html
TODO : get a `--firstboot` option working
Untested example:
```bash
$ sudo virt-sysprep --domain ubuntu-apache-base --firstboot-command 'apt update && apt install -y apache2 && reboot' --hostname 'baseos1'
```
However, if you're just installing packages, you can do that at buildtime instad of boot
time, with a command like this:
The `--install` command installs the package into the vm image, and `--network` enables the
networking to do so at build time.
```bash
sudo virt-sysprep --domain ubuntu-apache-base --install apache2 --network --firstboot-command 'apt update && apt dist-upgrade -y && apt autoremove -y && reboot' --hostname 'ubuntu-apache-base'
```
For all the available options, see the [official documentation page](http://libguestfs.org/virt-sysprep.1.html).
# Oneliner example to create a cluster
for f in {00..05} ; do sudo virsh destroy rancher$f ; sudo virsh undefine rancher$f; sudo virt-clone --original=ubuntu-base --name=rancher$f --auto-clone ; sudo virt-sysprep --domain rancher$f --firstboot-command 'while true ; do apt update && break ; ps aux | grep dpk; sleep 1; done ; dpkg --configure -a && while true ; do apt update && break ; sleep 1; done ; apt install curl -y; while true ; do curl https://get.docker.com | sudo bash && break ; ps aux | dpk ; done ; dpkg --configure -a && while true ; do apt update && break ; sleep 1; done ; apt dist-upgrade -y && apt autoremove -y && reboot ; echo test' --hostname "rancher$f"; virt-manager --show-domain-console rancher$f --connect 'qemu:///system'; sudo virsh start rancher$f; done