summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Ionescu <gabriel.ionescu@enea.com>2017-10-13 16:01:47 +0200
committerMartin Borg <martin.borg@enea.com>2017-10-13 16:07:55 +0200
commit52b21feca5803392c6156b148332d93fad9288a2 (patch)
tree2b5628879aaaaf1fa9e04e48108f3a8a323f168c
downloadnfv-access-tools-52b21feca5803392c6156b148332d93fad9288a2.tar.gz
Add NFV Access installer script
Signed-off-by: Gabriel Ionescu <gabriel.ionescu@enea.com> Signed-off-by: Martin Borg <martin.borg@enea.com>
-rw-r--r--nfv-installer/script-installer/README110
-rwxr-xr-xnfv-installer/script-installer/install_nfvaccess.sh415
2 files changed, 525 insertions, 0 deletions
diff --git a/nfv-installer/script-installer/README b/nfv-installer/script-installer/README
new file mode 100644
index 0000000..e94e178
--- /dev/null
+++ b/nfv-installer/script-installer/README
@@ -0,0 +1,110 @@
1:The purpose of this installer is to guide you through creating a bootable
2Enea NFV Access installation on a physical media (e.g. USB stick or HDD).
3
4Prerequisites:
5 - A GRUB .efi binary
6 - A drive of 16GB or larger
7 - For USB booting you will need:
8 - A development based rootfs (e.g. enea-nfv-access-dev-inteld1521.tar.gz)
9 - For booting from an SSD or HDD you will need:
10 - Any rootfs that needs to be installed on the board
11 (e.g. enea-nfv-access.tar.gz)
12
13A bootable media is created after the installer runs the following steps:
14 1. Create two partitions on a designated drive (e.g. /dev/sda):
15 - a 512MB partition for GRUB
16 - the rest of the drive is reserved for the rootfs.
17 2. Configure GRUB on one partition (usually the first one).
18 3. Copy a root filesystem on the other partition.
19
20Note: Running step 3 will implicitly copy the installer on that root filesystem
21in /usr/bin/install_nfvaccess.sh
22----------------------------------------------------------------------------------------
23To get a list of what commands are built in the installer, launch it with root
24rights and press ENTER, once the "nfv_installer>" console is displayed:
25 help - a guide on how to use the installer
26 list-params - lists parameters
27 list-steps - lists the available steps and the parameters that they depend on
28 set - sets a parameter (e.g. "set drive=/dev/sda")
29 clear - clears a parameter (e.g. "clear drive")
30 list-partitions - lists current drives and partitions
31 dry - describes the steps to be executed and checks if the files exist
32 run - executes the steps
33 q or quit - exits the script
34
35Run 'list-steps' to understand the built-in steps that the installer
36can execute and what parameters they depend on in order to be executed.
37
38Running 'list-steps' will print the following:
39 1. Format drive - Uses the drive set for the "drive" parameter to create a
40 512MB partition for GRUB and another partition for the rootfs. The rootfs
41 partition will be as large as the physical media minus 512MB.
42 Depends on the following parameter(s):
43 drive=
44 2. GRUB install - Installs the binary pointed by "grub_binary" on the drive
45 set in "grub_destination". A grub.cfg file will be created that will be
46 configured to boot off of "rootfs_destination".
47 Depends on the following parameters:
48 grub_destination=
49 grub_binary=
50 rootfs_destination=
51 3. Root filesystem install - Copies the files found in "rootfs_targz" to
52 the drive set in "rootfs_destination".
53 Depends on the following parameters:
54 rootfs_targz=
55 rootfs_destination=
56
57A parameter can be set through the "set" command or cleared through "clear".
58As some parameters are common for multiple steps, like rootfs_destination
59is for the GRUB and rootfs installation steps, you can get a list of all the
60parameters, by running "list-params".
61
62The following parameters can be configured:
63 grub_destination=[drive] - specifies the drive where GRUB will be
64 installed
65 grub_binary=[file] - points to the GRUB executable to be installed
66 where grub_destination is set
67 rootfs_destination=[drive] - specifies where the rootfs will be deployed
68 rootfs_targz=[.tar.gz file] - what file to unpack to where
69 rootfs_destination is set
70 drive=[/dev/sdaX] - what drive to partition
71
72Before running the actual partitioning and copying, a dry run can be executed
73without affecting the actual layout of the physical media, by running the
74"dry" command.
75
76Example of partitioning a drive:
77 set drive=/dev/sda
78 run
79
80Example of partitioning a drive, installing GRUB and a root filesystem:
81 set drive=/dev/sda
82 set grub_destination=/dev/sda1
83 set grub_binary=/home/user/grub-binary.efi
84 set rootfs_destination=/dev/sda2
85 set rootfs_targz=/home/user/rootfs.tar.gz
86 run
87
88Example of deploying ONLY a root filesystem:
89 set rootfs_destination=/dev/sda2
90 set rootfs_targz=/home/user/rootfs.tar.gz
91 runs
92
93Troubleshooting:
94 - GRUB is throwing "error: no such partition" or "error: disk not found":
95 The default GRUB config is set to use 'hd0' as the primary drive for
96 booting.
97 Due to this, the errors described above have two possible causes:
98 - The drive where NFV Access was installed is not identified as 'hd0'
99 by the BIOS
100 - The BIOS has assigned the 'hd0' label to a different drive (e.g. USB
101 stick) than the one where NFV Access was installed.
102 Solution:
103 1. In the GRUB selection screen press 'c' to enter the command line.
104 2. Run 'ls' to list all the available partitions.
105 3. For each available partition run 'ls PARTITION' in order to identify
106 where NFV Access was installed.
107 4. After identifying the partition, press ESC to return to the GRUB
108 selection screen and press 'e' to edit the boot command.
109 5. Set the boot partition to the one identified in step 3
110 6. Press F10 to boot
diff --git a/nfv-installer/script-installer/install_nfvaccess.sh b/nfv-installer/script-installer/install_nfvaccess.sh
new file mode 100755
index 0000000..5b23a07
--- /dev/null
+++ b/nfv-installer/script-installer/install_nfvaccess.sh
@@ -0,0 +1,415 @@
1#!/bin/bash
2set -eu
3
4grub_destination=""
5grub_binary=""
6rootfs_destination=""
7rootfs_targz=""
8drive=""
9
10function unmount_drives(){
11 echo "Checking if drives are mounted from $1"
12
13 mounts=$(mount | grep $1 | awk '{print $3}')
14
15 for i in $mounts; do
16 echo unmounting $i
17 umount $i
18 done
19}
20
21function deploy_installer() {
22 rootfs_dest="$1"
23
24 this_script=$(readlink -f $0)
25
26 mkdir -p "$rootfs_dest/usr/bin"
27 cp "$this_script" "$rootfs_dest/usr/bin/"
28}
29
30function deploy_rootfs_targz(){
31 rootfs_destination="$1"
32 rootfs_targz="$2"
33
34 echo "Deploying tar.gz"
35
36 echo "Generate random name"
37 mount_dir="/tmp/$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)"
38
39 echo "Create mount folder"
40 mkdir -p "$mount_dir"
41
42 echo "Mount drive to mount folder"
43 mount "$rootfs_destination" "$mount_dir"
44
45 echo "Clean up mounted folder"
46 rm -rf "$mount_dir"/*
47
48 echo "Untar archive to destination folder"
49 tar -zvxf "$rootfs_targz" -C "$mount_dir"
50
51 deploy_installer "$mount_dir"
52
53 echo "Cleanup"
54 umount "$mount_dir"
55 rm -rf "$mount_dir"
56
57 echo "rootfs deployment done!"
58}
59
60function deploy_grub(){
61 grub_destination="$1"
62 grub_binary="$2"
63 rootfs_destination="$3"
64
65 echo "Deploying grub"
66
67 echo "Generate random name"
68 mount_dir="/tmp/$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)"
69
70 echo "Create mount folder"
71 mkdir -p "$mount_dir"
72
73 echo "Mount drive to mount folder"
74 mount "$grub_destination" "$mount_dir"
75
76 echo "Create grub path"
77 mkdir -p "$mount_dir"/EFI/boot/
78
79 echo "Copy the grub binary"
80 cp "$grub_binary" "$mount_dir"/EFI/boot/bootx64.efi
81
82 rootfs_uuid=$(ls -l /dev/disk/by-partuuid/ | grep $(basename "$rootfs_destination") | awk '{print $9}')
83
84 echo "setting root in grub.cfg to: $rootfs_uuid"
85
86 echo "Create grub.cfg"
87 cat<<EOT > "$mount_dir"/EFI/boot/grub.cfg
88default=1
89
90menuentry "Enea Linux - normal booting" {
91 linux (hd0,gpt2)/boot/bzImage root=PARTUUID=${rootfs_uuid} ip=dhcp console=ttyS0,115200 earlyprintk=ttyS0,115200
92}
93
94menuentry "Enea Linux - high performance booting" {
95 linux (hd0,gpt2)/boot/bzImage root=PARTUUID=${rootfs_uuid} console=ttyS0,115200 earlyprintk=ttyS0,115200 ip=dhcp nohz_full=1-7 isolcpus=1-7 rcu-nocbs=1-7 rcu_nocb_poll intel_pstate=disable clocksource=tsc tsc=reliable nohpet nosoftlockup intel_idle.max_cstate=0 processor.max_cstate=0 mce=ignore_ce audit=0 nmi_watchdog=0 iommu=pt intel_iommu=on hugepagesz=1GB hugepages=8 default_hugepagesz=1GB hugepagesz=2M hugepages=2048 vfio_iommu_type1.allow_unsafe_interrupts=1
96}
97EOT
98 echo "Cleanup"
99 umount "$mount_dir"
100 rm -rf "$mount_dir"
101
102 echo "grub deployment done!"
103}
104
105function format_drive(){
106 unmount_drives "$1"
107
108 sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk ${1}
109 o # clear the in memory partition table
110 g # GPT partition type
111 n # new partition
112 1 # partition number 1
113 # default - start at beginning of disk
114 +512M # 100 MB boot parttion
115 t # change parition type
116 1 # set type to EFI System
117 n # new partition
118 2 # partion number 2
119 # default, start immediately after preceding partition
120 # default, extend partition to end of disk
121 p # print the in-memory partition table
122 w # write the partition table
123 q # and we're done
124EOF
125
126 sleep 1
127
128 unmount_drives "$1"
129 mkfs.fat -F32 -nEFI "$1"1
130 unmount_drives "$1"
131 yes | mkfs.ext2 -LROOT "$1"2
132}
133
134function help(){
135cat<<EOH
136
137The purpose of this installer is to guide you through creating a bootable
138Enea NFV Access installation on a physical media (e.g. USB stick or HDD).
139
140Prerequisites:
141 - A GRUB .efi binary
142 - A drive of 16GB or larger
143 - For USB booting you will need:
144 - A development based rootfs (e.g. enea-nfv-access-dev-inteld1521.tar.gz)
145 - For booting from an SSD or HDD you will need:
146 - Any rootfs that needs to be installed on the board
147 (e.g. enea-nfv-access.tar.gz)
148
149A bootable media is created after the installer runs the following steps:
150 1. Create two partitions on a designated drive (e.g. /dev/sda):
151 - a 512MB partition for GRUB
152 - the rest of the drive is reserved for the rootfs.
153 2. Configure GRUB on one partition (usually the first one).
154 3. Copy a root filesystem on the other partition.
155
156Note: Running step 3 will implicitly copy the installer on that root filesystem
157in /usr/bin/install_nfvaccess.sh
158----------------------------------------------------------------------------------------
159To get a list of what commands are built in the installer, launch it with root
160rights and press ENTER, once the "nfv_installer>" console is displayed:
161 help - a guide on how to use the installer
162 list-params - lists parameters
163 list-steps - lists the available steps and the parameters that they depend on
164 set - sets a parameter (e.g. "set drive=/dev/sda")
165 clear - clears a parameter (e.g. "clear drive")
166 list-partitions - lists current drives and partitions
167 dry - describes the steps to be executed and checks if the files exist
168 run - executes the steps
169 q or quit - exits the script
170
171Run 'list-steps' to understand the built-in steps that the installer
172can execute and what parameters they depend on in order to be executed.
173
174Running 'list-steps' will print the following:
175 1. Format drive - Uses the drive set for the "drive" parameter to create a
176 512MB partition for GRUB and another partition for the rootfs. The rootfs
177 partition will be as large as the physical media minus 512MB.
178 Depends on the following parameter(s):
179 drive=
180 2. GRUB install - Installs the binary pointed by "grub_binary" on the drive
181 set in "grub_destination". A grub.cfg file will be created that will be
182 configured to boot off of "rootfs_destination".
183 Depends on the following parameters:
184 grub_destination=
185 grub_binary=
186 rootfs_destination=
187 3. Root filesystem install - Copies the files found in "rootfs_targz" to
188 the drive set in "rootfs_destination".
189 Depends on the following parameters:
190 rootfs_targz=
191 rootfs_destination=
192
193A parameter can be set through the "set" command or cleared through "clear".
194As some parameters are common for multiple steps, like rootfs_destination
195is for the GRUB and rootfs installation steps, you can get a list of all the
196parameters, by running "list-params".
197
198The following parameters can be configured:
199 grub_destination=[drive] - specifies the drive where GRUB will be
200 installed
201 grub_binary=[file] - points to the GRUB executable to be installed
202 where grub_destination is set
203 rootfs_destination=[drive] - specifies where the rootfs will be deployed
204 rootfs_targz=[.tar.gz file] - what file to unpack to where
205 rootfs_destination is set
206 drive=[/dev/sdaX] - what drive to partition
207
208Before running the actual partitioning and copying, a dry run can be executed
209without affecting the actual layout of the physical media, by running the
210"dry" command.
211
212Example of partitioning a drive:
213 set drive=/dev/sda
214 run
215
216Example of partitioning a drive, installing GRUB and a root filesystem:
217 set drive=/dev/sda
218 set grub_destination=/dev/sda1
219 set grub_binary=/home/user/grub-binary.efi
220 set rootfs_destination=/dev/sda2
221 set rootfs_targz=/home/user/rootfs.tar.gz
222 run
223
224Example of deploying ONLY a root filesystem:
225 set rootfs_destination=/dev/sda2
226 set rootfs_targz=/home/user/rootfs.tar.gz
227 run
228
229EOH
230}
231
232function bye(){
233 echo "Exiting. Bye!"
234 exit 0
235}
236
237function list_part(){
238 fdisk -l | grep \/dev\/
239}
240
241function list_params(){
242 echo " grub_destination=$grub_destination"
243 echo " grub_binary=$grub_binary"
244 echo " rootfs_destination=$rootfs_destination"
245 echo " rootfs_targz=$rootfs_targz"
246 echo " drive=$drive"
247}
248
249function clear_param(){
250 shift
251 case "${1}" in
252 grub_destination)
253 grub_destination=""
254 ;;
255 grub_binary)
256 grub_binary=""
257 ;;
258 rootfs_destination)
259 rootfs_destination=""
260 ;;
261 rootfs_targz)
262 rootfs_targz=""
263 ;;
264 drive)
265 drive=""
266 ;;
267 *)
268 echo "Unknown parameter: ${1}" >&2
269 esac
270}
271
272function set_param(){
273 shift
274 case "${1}" in
275 grub_destination=*)
276 grub_destination="${1#*=}"
277 ;;
278 grub_binary=*)
279 grub_binary="${1#*=}"
280 ;;
281 rootfs_destination=*)
282 rootfs_destination="${1#*=}"
283 ;;
284 rootfs_targz=*)
285 rootfs_targz="${1#*=}"
286 ;;
287 drive=*)
288 drive="${1#*=}"
289 ;;
290 *)
291 echo "Unknown parameter: ${1}" >&2
292 esac
293}
294
295function check_for_file() {
296 if [ ! -e "$1" ]; then
297 echo " Warning: $1 does not exist"
298 fi
299}
300
301function list_steps() {
302cat<<EOS
303 1. Format drive - Uses the drive set in the 'drive' parameter to create a
304 512MB partition for GRUB and another partition for the rootfs. The rootfs
305 partition will be as large as the physical media minus 512MB.
306 Depends on these parameters:
307 drive=$drive
308 2. GRUB install - Installs the binary pointed by 'grub_binary' on the drive
309 set in 'grub_destination'. A grub.cfg file will be created that will be
310 configured to boot off 'rootfs_destination'.
311 Depends on these parameters:
312 grub_destination=$grub_destination
313 grub_binary=$grub_binary
314 rootfs_destination=$rootfs_destination
315 3. Root filesystem install - Copies the files found in 'rootfs_targz' to
316 the drive set in 'rootfs_destination'
317 Depends on these parameters:
318 rootfs_targz=$rootfs_targz
319 rootfs_destination=$rootfs_destination
320EOS
321}
322
323function run() {
324 DRY_RUN="NO"
325 step=1
326 if [ "$1" == "dry-run" ]; then
327 DRY_RUN="YES"
328 echo "The following steps will be executed:"
329 fi
330
331 if [[ ! -z $drive ]]; then
332 echo " $step. Will format drive $drive"
333 step=$((step+1))
334
335 if [[ $DRY_RUN == "NO" ]]; then
336 format_drive "$drive"
337 else
338 check_for_file $drive
339 fi
340 fi
341
342 if [[ ! -z $grub_destination && ! -z $grub_binary && ! -z $rootfs_destination ]]; then
343 echo " $step. Will deploy GRUB on $grub_destination, using the binary from $grub_binary and will set the rootfs partition to $rootfs_destination"
344 step=$((step+1))
345
346 if [[ $DRY_RUN == "NO" ]]; then
347 unmount_drives "$grub_destination"
348 deploy_grub "$grub_destination" "$grub_binary" "$rootfs_destination"
349 else
350 check_for_file $grub_destination
351 check_for_file $grub_binary
352 check_for_file $rootfs_destination
353 fi
354 fi
355
356 if [[ ! -z $rootfs_targz && ! -z $rootfs_destination ]]; then
357 echo " $step. Will deploy $rootfs_targz on $rootfs_destination"
358 step=$((step+1))
359
360 if [[ $DRY_RUN == "NO" ]]; then
361 unmount_drives "$rootfs_destination"
362 deploy_rootfs_targz "$rootfs_destination" "$rootfs_targz"
363 else
364 check_for_file $rootfs_destination
365 check_for_file $rootfs_targz
366 fi
367 fi
368}
369
370if [[ $EUID -ne 0 ]]; then
371 echo "This script must be executed as root. Continue anyway? [y/n]"
372 read line
373 if [ $line == "n" ]; then
374 exit 1
375 fi
376fi
377
378while IFS="" read -r -e -d $'\n' -p "nfv_installer> " line; do
379 case $line in
380 q)
381 bye;;
382 quit)
383 bye;;
384 list-partitions)
385 list_part;;
386 list-params)
387 list_params;;
388 set\ *)
389 set_param $line;;
390 clear\ *)
391 clear_param $line;;
392 help)
393 help;;
394 dry)
395 run "dry-run";;
396 run)
397 run "run-it";;
398 list-steps)
399 list_steps;;
400 *)
401 echo "Unknown command $line"
402 echo "Commands:"
403 echo " help - guide on how to use the installer"
404 echo " list-params - lists parameters"
405 echo " list-steps - lists the available steps and the parameters that they depend on"
406 echo " set - set a parameter (e.g. \"set drive=/dev/sda\")"
407 echo " clear - clears a parameter (e.g. \"clear drive\")"
408 echo " list-partitions - lists current drives and partitions"
409 echo " dry - describes the steps to be executed and checks if the files exist"
410 echo " run - executes the steps"
411 echo " q or quit - exits the script"
412 esac
413 history -s "$line"
414 echo ""
415done