5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 DEVICE_MOUNT="/tmp/installmedia"
18 CLOUD_RPMS_DIR="/sysroot/var/cloud/basebuild_rpms"
19 USERCONFIG_DIR="/sysroot/etc/userconfig/"
20 IMAGE_DIR="/sysroot/opt/images"
22 source /usr/lib/installmedia-lib.sh
24 logmsg "Installing OS to HDD"
26 mkdir -p $DEVICE_MOUNT
28 if ( is_using_boot_cd );then
29 warn "Must be boot_cd env. Mounting $BOOTCD_LOCATION"
30 run_crit mount -o ro -t iso9660 $BOOTCD_LOCATION $DEVICE_MOUNT
32 find_iso $DEVICE_MOUNT false
34 logmsg "No ISO image to install. Cannot proceed!"
39 if [ -e $CLOUD_CONFIGS/network_config ];then
40 logmsg "Sourcing network_config"
41 source $CLOUD_CONFIGS/network_config
44 if [ -n "${ROOTFS_DISK}" ];then
45 rootdev_by_path=${ROOTFS_DISK}
47 # Find out the disk name where rootfs has to be installed
48 rootdev_by_path=$(python /usr/lib/python2.7/site-packages/hw_detector/local_os_disk.py)
51 rootdev=$(readlink -e $rootdev_by_path)
53 #Wait for the device to appear for 60 seconds and then give up
54 while [ -z "${rootdev}" ]; do
56 rootdev=$(readlink -e $rootdev_by_path)
57 count=$(( ${count}+1 ))
58 if [ ${count} == 20 ]; then
64 if [ -z ${rootdev} ] || ! [ -b ${rootdev} ]; then
65 logmsg "No matching HDD (${rootdev}) found to install OS image. Cannot proceed!"
68 if ! [ -e $DEVICE_MOUNT/guest-image.img ]; then
69 logmsg "No guest-image.img in CDROM. Cannot proceed!"
73 logmsg "Matching device found for root disk. Installing image on ${rootdev}"
76 for hd_dev in ${hd_devices[@]}; do
77 if [ -b /dev/$hd_dev ] && (( is_removable $hd_dev ) || ( is_partition $hd_dev ) || ( is_loop $hd_dev )); then
78 logmsg "Removable, loop or partition $hd_dev. Skipping..."
80 elif ! [ -b /dev/$hd_dev ];then
83 logmsg "Erasing existing GPT and MBR data structures from ${hd_dev}"
84 sgdisk -Z /dev/$hd_dev
85 dd if=/dev/zero of=/dev/$hd_dev bs=1M count=1
88 logmsg "Dumping $DEVICE_MOUNT/guest-image.img to $rootdev"
90 # limit the memory usage for qemu-img to 1 GiB
92 qemu-img convert -p -t directsync -O host_device $DEVICE_MOUNT/guest-image.img $rootdev > $CONSOLE_DEV
94 logmsg "Failed to dump image to disk... Failing installation."
99 logmsg "${rootdev} dumped successfully!"
100 echo "Finishing installation... Please wait." > $CONSOLE_DEV
103 # create a new partion for LVMs before rootfs expands till end
104 parted ${rootdev} --script -- mkpart primary 50GiB -1
107 mount ${rootdev}1 /sysroot/
109 logmsg "FAILED TO MOUNT SYSROOT. All hope is lost"
113 kernel_cmdline="intel_iommu=on iommu=pt crashkernel=256M"
114 # Check if this has a iscsi target if so, add extra cmdline option for HDD boot.
115 iscsiadm -m fw >/dev/null 2>&1
116 if [[ $? == 0 ]]; then
117 kernel_cmdline="${kernel_cmdline} rd.iscsi.firmware=1 rd.retry=30"
119 if grep -q "^GRUB_CMDLINE_LINUX=" /sysroot/etc/default/grub; then
120 sed -i "s/^\(GRUB_CMDLINE_LINUX=.*\)\"$/\1 $kernel_cmdline\"/g" /sysroot/etc/default/grub
122 echo "GRUB_CMDLINE_LINUX=\"$kernel_cmdline\"" >> /sysroot/etc/default/grub
125 run_crit mount -o bind /dev /sysroot/dev
126 run_crit mount -o bind /proc /sysroot/proc
127 run_crit mount -o bind /sys /sysroot/sys
128 run_crit chroot /sysroot /bin/bash -c \"/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg\"
130 logmsg "Extending partition and filesystem size"
131 run_crit chroot /sysroot /bin/bash -c \"growpart ${rootdev} 1\"
132 run_crit chroot /sysroot /bin/bash -c \"xfs_growfs /\"
134 logmsg "Copying cloud guest image"
136 run_crit cp -f $DEVICE_MOUNT/guest-image.img $IMAGE_DIR
138 if [ -d $CLOUD_CONFIGS ]; then
139 logmsg "Copying user config"
140 mkdir -p $USERCONFIG_DIR
141 cp -rf $CLOUD_CONFIGS/* $USERCONFIG_DIR
144 if [ -e $DEVICE_MOUNT/rpms ]; then
145 logmsg "Copying build base RPMs"
146 mkdir -p $CLOUD_RPMS_DIR
148 for file in $DEVICE_MOUNT/rpms/*;do
149 cp -a $file $CLOUD_RPMS_DIR
150 echo -n "." > $CONSOLE_DEV
152 echo -n " done" > $CONSOLE_DEV
157 logmsg "Disabling cloud-init services on this node"
158 run_crit chroot /sysroot /bin/systemctl --no-reload disable cloud-config.service
159 run_crit chroot /sysroot /bin/systemctl --no-reload disable cloud-final.service
160 run_crit chroot /sysroot /bin/systemctl --no-reload disable cloud-init.service
161 run_crit chroot /sysroot /bin/systemctl --no-reload disable cloud-init-local.service
164 logmsg "Copying installation logs"
165 mkdir -p /sysroot/var/log/provisioning-logs
166 cp -rf /run/log/ /sysroot/var/log/provisioning-logs/
167 cp -rf /run/initramfs/ /sysroot/var/log/provisioning-logs/
177 logmsg "Everything done rebooting!"