Add script for usb bootable support 19/1319/6
authorchengli3 <cheng1.li@intel.com>
Fri, 2 Aug 2019 09:52:56 +0000 (17:52 +0800)
committerchengli3 <cheng1.li@intel.com>
Mon, 19 Aug 2019 04:10:27 +0000 (12:10 +0800)
Co-Authored-By: songongjun <gongjun.song@intel.com>
Change-Id: Ic7cb87a2910a4fb47aa825b6e6705ea779c14778
Signed-off-by: chengli3 <cheng1.li@intel.com>
README.md
tools/README.md [new file with mode: 0644]
tools/collect.sh [new file with mode: 0755]
tools/create_usb_bootable.sh [changed mode: 0644->0755]
tools/setup_build_machine.sh [new file with mode: 0755]
tools/ubuntu/isolinux/isolinux.cfg [new file with mode: 0644]
tools/ubuntu/preseed/ubuntu-server.seed [new file with mode: 0644]

index cf3756c..523b49d 100644 (file)
--- a/README.md
+++ b/README.md
@@ -3,3 +3,29 @@
 Work in progress
 
 For more information refer - https://wiki.akraino.org/pages/viewpage.action?pageId=11995140
+
+## Build ISO
+
+We should run the following commands on a fresh ubuntu 18.04 of kernel version 4.15.0-45-generic
+
+```bash
+cd ~
+mkdir -p workspace && cd workspace
+git clone "https://gerrit.akraino.org/r/icn" # may need to switch the branch based on your case
+sudo icn/tools/setup_build_machine.sh
+sudo icn/tools/collect.sh
+sudo icn/tools/create_usb_bootable.sh
+```
+
+The script builds an ISO based on the official ubuntu-18.04-server.iso. The generated ISO
+is located at `workspace/icn-ubuntu-18.04.iso`.
+All files under `icn` directory are copied into the ISO. During the installation of the ISO,
+these files are copied to infra-local-controller under `/opt/icn`.
+
+## How to use the ISO to bootstrap a infra-local-controller
+
+1. We burn the ISO onto an USB strick.
+2. We plug this USB into a server and press the power-on button. (choose boot from the USB strick)
+3. The ubuntu 18.04 is supposed to be installed on the server, then it reboots automatically.
+4. Now we can login the server with the default user/password of icn/icn
+5. We can do anything we need here to install/configure/launch services.
diff --git a/tools/README.md b/tools/README.md
new file mode 100644 (file)
index 0000000..5795c41
--- /dev/null
@@ -0,0 +1,22 @@
+# Automatic installation script
+
+`create_usb_bootable.sh` is a script to build an ubuntu ISO
+with capability of no-attended installation. All the questiones
+asked during installation are answered by the [preseed file](ubuntu/preseed/ubuntu-server.seed).
+We copy the icn directory into the target ISO. Before running `create_usb_bootable.sh`
+, the tools/collect.sh script is called to collect files from
+the Internet into icn directory. For example, to download deb packages,
+to pull docker images, etc.
+
+Each component should has its own collect script. `tools/collect.sh` calls
+each component collect script one by one. The componnet collect script must follow
+several rules:
+
+1. The name of component script should be `collect_xx.sh`
+1. `set -ex` is needed in component script. So that the parent collect.sh can be awared of
+the failure of component script.
+1. The component script should accept one parameter, which is the icn directory. So that
+the component script knows where to put the collected files.
+1. Calling the component multiple times must not raise error.
+1. Component scripts are supposed to run with root permission, we don't have to use `sudo`
+in the component scripts.
diff --git a/tools/collect.sh b/tools/collect.sh
new file mode 100755 (executable)
index 0000000..e8a1bde
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+
+set -ex
+
+SCRIPT_PATH=`realpath $0`
+TOOL_PATH=`dirname "$SCRIPT_PATH"`
+ICN_PATH=`dirname $TOOL_PATH`
+# Get into workspace directory, we run every following command from the workspace directory
+cd $ICN_PATH/../
+
+mkdir -p $ICN_PATH/apt/deb/
+
+# Call scripts to collect everything from Internet,
+# all the collected files need to be put under ICN_PATH
+for collect_sh in `find icn/ -name collect_*.sh | sort`
+do
+  collect_parent=`dirname $collect_sh`
+  pushd $collect_parent
+    bash `basename $collect_sh` $ICN_PATH
+  popd
+done
old mode 100644 (file)
new mode 100755 (executable)
index e69de29..75df297
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+
+set -ex
+
+SCRIPT_PATH=`realpath $0`
+TOOL_PATH=`dirname "$SCRIPT_PATH"`
+ICN_PATH=`dirname $TOOL_PATH`
+# Get into workspace directory, we run every following command from the workspace directory
+cd $ICN_PATH/../
+
+mkdir -p build
+
+if [ ! -f "build/ubuntu-18.04.2-server-amd64.iso" ];then
+  curl "http://old-releases.ubuntu.com/releases/18.04.2/ubuntu-18.04.2-server-amd64.iso" \
+    -o build/ubuntu-18.04.2-server-amd64.iso
+else
+  echo "Not download official ISO, using existing one"
+fi
+
+mkdir -p build/iso
+mount build/ubuntu-18.04.2-server-amd64.iso build/iso
+rm -rf build/ubuntu
+cp -r build/iso build/ubuntu
+umount build/iso
+
+cp -rf icn/tools/ubuntu/* build/ubuntu/
+cp -rf icn build/ubuntu/
+
+mkisofs -R -J -T -v -no-emul-boot -boot-load-size 4 -boot-info-table \
+  -b isolinux/isolinux.bin -c isolinux/boot.cat -o icn-ubuntu-18.04.iso build/ubuntu/
diff --git a/tools/setup_build_machine.sh b/tools/setup_build_machine.sh
new file mode 100755 (executable)
index 0000000..293bff9
--- /dev/null
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+apt update
+apt install -y mkisofs coreutils
+# for QAT
+apt install -y g++ pkg-config libelf-dev libssl1.0-dev pciutils-dev
+
diff --git a/tools/ubuntu/isolinux/isolinux.cfg b/tools/ubuntu/isolinux/isolinux.cfg
new file mode 100644 (file)
index 0000000..1ad44c0
--- /dev/null
@@ -0,0 +1,12 @@
+default autoinstall
+prompt 0
+timeout 100
+
+menu title Custom Live CD
+menu background splash.png
+menu color title 1;37;44 #c0ffffff #00000000 std
+
+label autoinstall
+menu label autoinstall - auto install ubuntu
+kernel /install/vmlinuz
+append initrd=/install/initrd.gz file=/cdrom/preseed/ubuntu-server.seed boot=install debian-installer/locale=en_US console-setup/ask_detect=false keyboard-configuration/layoutcode=us quiet splash --
diff --git a/tools/ubuntu/preseed/ubuntu-server.seed b/tools/ubuntu/preseed/ubuntu-server.seed
new file mode 100644 (file)
index 0000000..6cadf0b
--- /dev/null
@@ -0,0 +1,93 @@
+#locate
+d-i debian-installer/locale string en_US
+d-i console-tools/archs select true
+d-i debian-installer/language string en
+d-i debian-installer/country string us
+d-i localechooser/supported-locales multiselect en_US.UTF-8, zh_CN.UTF-8
+
+#keyboard
+d-i console-setup/ask_detect boolean false
+d-i console-configuration/layoutcode string us
+d-i keyboard-configuration/modelcode string SKIP
+
+#clock
+d-i clock-setup/utc boolean false
+d-i time/zone string Asia/Shanghai
+d-i clock-setup/ntp-server string ntp.example.com
+
+#network
+d-i netcfg/choose_interface select auto
+d-i netcfg/dhcp_failed note
+d-i netcfg/dhcp_options select Do not configure the network at this time
+d-i netcfg/get_hostname string infra-controller
+# d-i netcfg/get_domain string intel-domain
+d-i netcfg/wireless_wep string
+d-i netcfg/dhcp_timeout string 3
+d-i netcfg/dhcpv6_timeout string 3
+
+# Mirror
+
+d-i pkgsel/language-pack-patterns      string
+d-i pkgsel/install-language-support    boolean false
+d-i apt-setup/partner boolean true
+d-i debian-installer/splash    boolean false
+d-i oem-config-udeb/frontend   string debconf
+d-i mirror/http/proxy string
+
+# clock
+d-i clock-setup/ntp boolean true
+d-i clock-setup/ntp-server string ntp.example.com
+
+#user
+d-i passwd/root-login boolean false
+d-i passwd/make-user boolean true
+d-i passwd/user-fullname string icn
+d-i passwd/username string icn
+d-i passwd/user-password password icn
+d-i passwd/user-password-again password icn
+d-i user-setup/allow-password-weak boolean true
+d-i user-setup/encrypt-home boolean false
+
+#disk
+#d-i s390-dasd/dasd string 0.0.0300,0.0.0400,0.0.0500
+#d-i s390-dasd/auto-format boolean true
+#d-i s390-dasd/force-format boolean true
+
+d-i partman-auto/init_automatically_partitioin select biggest_free
+#d-i partman-auto/disk string /dev/sda
+# add "umount" workaround to address the debian-installer bug
+# https://bugs.launchpad.net/ubuntu/+source/debian-installer/+bug/1347726
+d-i preseed/early_command string umount /media || true
+d-i partman/early_command \
+    string debconf-set partman-auto/disk "$(echo /dev/`ls -l /sys/block/[vhs]d* | grep -v "usb" | head -n1 | sed 's/^.*\([hs]d[a-z]\+\).*$/\1/'`)"
+d-i partman-auto/method string lvm
+d-i partman-lvm/device_remove_lvm boolean true
+d-i partman-md/device_remove_md boolean true
+d-i partman-lvm/confirm boolean true
+d-i partman-lvm/confirm_nooverwrite boolean true
+d-i partman-auto-lvm/guided_size string max
+d-i partman-auto/choose_recipe select atomic
+d-i partman-partitioning/confirm_write_new_label boolean true
+d-i partman/choose_partition select finish
+d-i partman/confirm boolean true
+d-i partman/confirm_nooverwrite boolean true
+
+#basic system
+#d-i base-installer/kernel/linux/initramfs-generators string yaird
+
+#package
+tasksel tasksel/first multiselect standard
+d-i pkgsel/include string openssh-server       vim
+d-i pkgsel/update-policy select none
+
+#grub
+d-i grub-installer/only_debian boolean true
+d-i grub-installer/with_other_os boolean true
+d-i grub-installer/bootdev  string default
+
+# copy files into the ISO
+d-i preseed/late_command string cp -r /cdrom/icn /target/opt/icn ; cp -r /cdrom/pool/main/* /target/opt/icn/apt/deb/
+
+# Finish
+d-i finish-install/reboot_in_progress note
+oem-config     oem-config/steps        multiselect language, timezone, keyboard, user, network, tasksroot