Merge ~alextu/pc-enablement/+git/oem-scripts:recovery-from-iso-inject-stella-on-somverville-img into ~oem-solutions-engineers/pc-enablement/+git/oem-scripts:master

Proposed by Alex Tu
Status: Merged
Merged at revision: e42da8a4375e891c496dec28057f4c75a22607fc
Proposed branch: ~alextu/pc-enablement/+git/oem-scripts:recovery-from-iso-inject-stella-on-somverville-img
Merge into: ~oem-solutions-engineers/pc-enablement/+git/oem-scripts:master
Diff against target: 132 lines (+70/-3)
1 file modified
recovery-from-iso.sh (+70/-3)
Reviewer Review Type Date Requested Status
jeremyszu (community) Approve
Andy Chi Approve
OEM Solutions Group: Engineers Pending
Review via email: mp+407688@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alex Tu (alextu) wrote :

test steps:
1. install iso from http://{jenkins}/job/dell-bto-focal-fossa-edge-alloem_dev_jenkins_remote_trigger/ on VM

2. recovery-from-iso.sh --local-iso {stella iso} --ubr -t {ip of target machine}

=> the target can done recovery with target iso.

Revision history for this message
Alex Tu (alextu) wrote :
Revision history for this message
Alex Tu (alextu) wrote :
Revision history for this message
Alex Tu (alextu) wrote :
Revision history for this message
jeremyszu (os369510) wrote :

Hi Alex,

What's different between

dell-bto-focal-fossa-edge-alloem
dell-bto-focal-fossa-edge-alloem_dev
dell-bto-focal-fossa-edge-alloem-init
dell-bto-focal-fossa-edge-alloem-init_dev
dell-bto-focal-fossa-edge-alloem_dev_jenkins_remote_trigger

?

review: Needs Information
Revision history for this message
jeremyszu (os369510) wrote :

I still need to try it in physical machine but I need the information from previous comment.
And one thing needs to be fixed at least.

review: Needs Fixing
Revision history for this message
Andy Chi (andch) wrote :

Cannot enter recovery partition.

error: file 'casper/vmlinuz' not found
error: you need to load kernel first

Revision history for this message
Alex Tu (alextu) wrote :

comment inline

Revision history for this message
Alex Tu (alextu) wrote :

just also verified on HP laptop (202103-28767) with the patch 22c3478

Revision history for this message
Andy Chi (andch) wrote :

Test pass with 202104-28974. One question of dell-bto-focal-fossa-edge-alloem-init-X170-20211019-16.iso, what is the expected user name of this image? I see u and ubuntu both exist. When OS startup, I observe u as login user. `user_on_target` expects "ubuntu".

Revision history for this message
jeremyszu (os369510) wrote :

> Hi Alex,
>
> What's different between
>
> dell-bto-focal-fossa-edge-alloem
> dell-bto-focal-fossa-edge-alloem_dev
> dell-bto-focal-fossa-edge-alloem-init
> dell-bto-focal-fossa-edge-alloem-init_dev
> dell-bto-focal-fossa-edge-alloem_dev_jenkins_remote_trigger
>
> ?

the answer is here
https://chat.canonical.com/canonical/pl/pfyw9y7yzbrcp8dcpq5a8uhddy

Revision history for this message
Alex Tu (alextu) wrote :

> Test pass with 202104-28974. One question of dell-bto-focal-fossa-edge-alloem-
> init-X170-20211019-16.iso, what is the expected user name of this image? I see
> u and ubuntu both exist. When OS startup, I observe u as login user.
> `user_on_target` expects "ubuntu".

`u` is used for original usb dev flow and I'm trying to make `ubuntu` as default if no one is concerning on that change.

Revision history for this message
Andy Chi (andch) :
review: Approve
Revision history for this message
jeremyszu (os369510) wrote :

Hi Alex,

I can not install "dell-bto-focal-fossa-edge-alloem-X170-20211019-28.iso" on stella machine to verify your patch. IIRC, the alloem is made by you.

The error shows in dell-recovery. "this recovery media only function on Dell..."

review: Needs Information
Revision history for this message
jeremyszu (os369510) wrote :

Verified by

1. installing dell-bto-focal-fossa-edge-alloem-init-X172-20211029-17.iso by USB
2. recovery-from-iso.sh pc-stella-cmit-focal-amd64-X00-20211029-1725.iso, then
3. recovery-from-iso.sh pc-stella-cmit-focal-amd64-X00-20211109-1733.iso

All passed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/recovery-from-iso.sh b/recovery-from-iso.sh
index a6f4439..3b42656 100755
--- a/recovery-from-iso.sh
+++ b/recovery-from-iso.sh
@@ -4,6 +4,7 @@ set -ex
4jenkins_job_for_iso=""4jenkins_job_for_iso=""
5jenkins_job_build_no="lastSuccessfulBuild"5jenkins_job_build_no="lastSuccessfulBuild"
6script_on_target_machine="inject_recovery_from_iso.sh"6script_on_target_machine="inject_recovery_from_iso.sh"
7additional_grub_for_ubuntu_recovery="99_ubuntu_recovery"
7user_on_target="ubuntu"8user_on_target="ubuntu"
8SSH="ssh -o StrictHostKeyChecking=no"9SSH="ssh -o StrictHostKeyChecking=no"
9SCP="scp -o StrictHostKeyChecking=no"10SCP="scp -o StrictHostKeyChecking=no"
@@ -91,6 +92,7 @@ ubiquity ubuntu-recovery/recovery_type string dev
91 git clone --depth 1 -b maas-focal lp:~lyoncore-team/lyoncore/+git/somerville-maas-override maas_deps92 git clone --depth 1 -b maas-focal lp:~lyoncore-team/lyoncore/+git/somerville-maas-override maas_deps
92 cd maas_deps93 cd maas_deps
93 git rev-parse --short HEAD94 git rev-parse --short HEAD
95 rm -f maas-pkgs/oem-fix-misc-cnl-maas-helper*
94 cd ..96 cd ..
95 cp -r maas_deps/maas-pkgs/*.deb .97 cp -r maas_deps/maas-pkgs/*.deb .
96 find .98 find .
@@ -116,6 +118,61 @@ apt-get install -fy
116 # get pkgs for ssh key and skip disk checking.118 # get pkgs for ssh key and skip disk checking.
117 $GIT clone https://git.launchpad.net/~oem-solutions-engineers/pc-enablement/+git/oem-fix-misc-cnl-misc-for-automation --depth 1 misc_for_automation119 $GIT clone https://git.launchpad.net/~oem-solutions-engineers/pc-enablement/+git/oem-fix-misc-cnl-misc-for-automation --depth 1 misc_for_automation
118120
121 if [ "${ubr}" == "yes" ]; then
122 mkdir -p "$temp_folder"/preseed
123 cat <<EOF1 > "$temp_folder/preseed/$additional_grub_for_ubuntu_recovery"
124#!/bin/bash -e
125source /usr/lib/grub/grub-mkconfig_lib
126cat <<EOF
127menuentry "ubuntu-recovery restore" --hotkey f9 {
128 search --no-floppy --hint '(hd0,gpt2)' --set --fs-uuid UUID_OF_RECOVERY_PARTITION
129 if [ -s /boot/grub/common.cfg ]; then
130 source /boot/grub/common.cfg
131 else
132 set options="boot=casper automatic-ubiquity noprompt quiet splash"
133 fi
134
135 if [ "\\\${grub_platform}" != "efi" ]; then
136 if [ -f \\\${prefix}/nomodesetlist.txt ]; then
137 if hwmatch \\\${prefix}/nomodesetlist.txt 3; then
138 if [ \\\${match} != 0 ]; then
139 set options="nomodeset \\\$options"
140 fi
141 fi
142 fi
143 fi
144
145 #Support starting from a loopback mount (Only support ubuntu.iso for filename)
146 if [ -f /ubuntu.iso ]; then
147 loopback loop /ubuntu.iso
148 set root=(loop)
149 set options="\\\$options iso-scan/filename=/ubuntu.iso"
150 fi
151 if [ -n "\\\${lang}" ]; then
152 set options="\\\$options locale=\\\$lang"
153 fi
154
155 linux /casper/vmlinuz ubuntu-recovery/recovery_type=hdd \\\$options
156 initrd /casper/initrd
157}
158EOF
159EOF1
160 cat <<EOF > "$temp_folder/preseed/set_env_for_ubuntu_recovery"
161#!/bin/bash -ex
162# replace the grub entry which ubuntu_recovery expected
163recover_p=\$(lsblk -l | grep efi | cut -d ' ' -f 1 | sed 's/.$/2'/)
164UUID_OF_RECOVERY_PARTITION=\$(ls -l /dev/disk/by-uuid/ | grep \$recover_p | awk '{print \$9}')
165echo partition = \$UUID_OF_RECOVERY_PARTITION
166sed -i "s/UUID_OF_RECOVERY_PARTITION/\$UUID_OF_RECOVERY_PARTITION/" push_preseed/preseed/$additional_grub_for_ubuntu_recovery
167sudo rm -f /etc/grub.d/99_dell_recovery || true
168chmod 766 push_preseed/preseed/$additional_grub_for_ubuntu_recovery
169sudo cp push_preseed/preseed/$additional_grub_for_ubuntu_recovery /etc/grub.d/
170
171# Force changing the recovery partition label to PQSERVICE for ubuntu-recovery
172sudo fatlabel /dev/\$recover_p PQSERVICE
173EOF
174 fi
175
119 return 0176 return 0
120}177}
121push_preseed() {178push_preseed() {
@@ -152,12 +209,19 @@ inject_preseed() {
152 download_preseed && \209 download_preseed && \
153 push_preseed210 push_preseed
154 scp -o StrictHostKeyChecking=no "$user_on_target"@"$target_ip":/cdrom/SUCCSS_push_preseed "$temp_folder" || usage211 scp -o StrictHostKeyChecking=no "$user_on_target"@"$target_ip":/cdrom/SUCCSS_push_preseed "$temp_folder" || usage
212
213 if [ "${ubr}" == "yes" ]; then
214 $SSH "$user_on_target"@"$target_ip" bash \$HOME/push_preseed/preseed/set_env_for_ubuntu_recovery || usage
215 fi
155 $SSH "$user_on_target"@"$target_ip" touch /tmp/SUCCSS_inject_preseed216 $SSH "$user_on_target"@"$target_ip" touch /tmp/SUCCSS_inject_preseed
156}217}
157218
158inject_recovery_iso() {219inject_recovery_iso() {
159 if [ -n "$local_iso" ]; then220 if [ -n "$local_iso" ]; then
160 img_name="$(basename "$local_iso")"221 img_name="$(basename "$local_iso")"
222 if [ -z "${img_name##*stella*}" ]; then
223 ubr="yes"
224 fi
161 if [ "${ubr}" == "yes" ]; then225 if [ "${ubr}" == "yes" ]; then
162 rsync_opts="--exclude=efi --delete --temp-dir=/var/tmp/rsync"226 rsync_opts="--exclude=efi --delete --temp-dir=/var/tmp/rsync"
163 else227 else
@@ -172,7 +236,8 @@ cat <<EOF > "$temp_folder/$script_on_target_machine"
172set -ex236set -ex
173sudo umount /cdrom /mnt || true237sudo umount /cdrom /mnt || true
174sudo mount -o loop $img_name /mnt && \238sudo mount -o loop $img_name /mnt && \
175sudo mount /dev/\$(lsblk -l | grep efi | cut -d ' ' -f 1 | sed 's/.$/2'/) /cdrom && \239recover_p=\$(lsblk -l | grep efi | cut -d ' ' -f 1 | sed 's/.$/2'/) && \
240sudo mount /dev/\$recover_p /cdrom && \
176df | grep "cdrom\|mnt" | awk '{print \$2" "\$6}' | sort | tail -n1 | grep -q cdrom && \241df | grep "cdrom\|mnt" | awk '{print \$2" "\$6}' | sort | tail -n1 | grep -q cdrom && \
177sudo mkdir -p /var/tmp/rsync && \242sudo mkdir -p /var/tmp/rsync && \
178sudo rsync -alv /mnt/ /cdrom/ $rsync_opts && \243sudo rsync -alv /mnt/ /cdrom/ $rsync_opts && \
@@ -188,7 +253,7 @@ EOF
188 img_name="$(wget -q "$img_jenkins_out_url/" -O - | grep -o 'href=.*iso"' | awk -F/ '{print $NF}' | tr -d \")"253 img_name="$(wget -q "$img_jenkins_out_url/" -O - | grep -o 'href=.*iso"' | awk -F/ '{print $NF}' | tr -d \")"
189 pushd "$temp_folder" || usage254 pushd "$temp_folder" || usage
190 wget "$img_jenkins_out_url/$img_name".md5sum255 wget "$img_jenkins_out_url/$img_name".md5sum
191 md5sum -c "$img_name".md5sum || wget "$img_jenkins_out_url"/"$img_name"256 md5sum -c "$img_name".md5sum || wget "$img_jenkins_out_url"/"$img_name" 2> /dev/null
192 md5sum -c "$img_name".md5sum || usage257 md5sum -c "$img_name".md5sum || usage
193 local_iso="$PWD/$img_name"258 local_iso="$PWD/$img_name"
194 popd259 popd
@@ -212,7 +277,9 @@ poll_recovery_status() {
212277
213do_recovery() {278do_recovery() {
214 if [ "${ubr}" == "yes" ]; then279 if [ "${ubr}" == "yes" ]; then
215 echo GRUB_DEFAULT=3 | $SSH "$user_on_target"@"$target_ip" -T "sudo tee -a /etc/default/grub.d/automatic-oem-config.cfg"280 echo GRUB_DEFAULT='"ubuntu-recovery restore"' | $SSH "$user_on_target"@"$target_ip" -T "sudo tee -a /etc/default/grub.d/automatic-oem-config.cfg"
281 echo GRUB_TIMEOUT_STYLE=menu | $SSH "$user_on_target"@"$target_ip" -T "sudo tee -a /etc/default/grub.d/automatic-oem-config.cfg"
282 echo GRUB_TIMEOUT=5 | $SSH "$user_on_target"@"$target_ip" -T "sudo tee -a /etc/default/grub.d/automatic-oem-config.cfg"
216 $SSH "$user_on_target"@"$target_ip" sudo update-grub283 $SSH "$user_on_target"@"$target_ip" sudo update-grub
217 $SSH "$user_on_target"@"$target_ip" sudo reboot &284 $SSH "$user_on_target"@"$target_ip" sudo reboot &
218 else285 else

Subscribers

People subscribed via source and target branches