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
1diff --git a/recovery-from-iso.sh b/recovery-from-iso.sh
2index a6f4439..3b42656 100755
3--- a/recovery-from-iso.sh
4+++ b/recovery-from-iso.sh
5@@ -4,6 +4,7 @@ set -ex
6 jenkins_job_for_iso=""
7 jenkins_job_build_no="lastSuccessfulBuild"
8 script_on_target_machine="inject_recovery_from_iso.sh"
9+additional_grub_for_ubuntu_recovery="99_ubuntu_recovery"
10 user_on_target="ubuntu"
11 SSH="ssh -o StrictHostKeyChecking=no"
12 SCP="scp -o StrictHostKeyChecking=no"
13@@ -91,6 +92,7 @@ ubiquity ubuntu-recovery/recovery_type string dev
14 git clone --depth 1 -b maas-focal lp:~lyoncore-team/lyoncore/+git/somerville-maas-override maas_deps
15 cd maas_deps
16 git rev-parse --short HEAD
17+ rm -f maas-pkgs/oem-fix-misc-cnl-maas-helper*
18 cd ..
19 cp -r maas_deps/maas-pkgs/*.deb .
20 find .
21@@ -116,6 +118,61 @@ apt-get install -fy
22 # get pkgs for ssh key and skip disk checking.
23 $GIT clone https://git.launchpad.net/~oem-solutions-engineers/pc-enablement/+git/oem-fix-misc-cnl-misc-for-automation --depth 1 misc_for_automation
24
25+ if [ "${ubr}" == "yes" ]; then
26+ mkdir -p "$temp_folder"/preseed
27+ cat <<EOF1 > "$temp_folder/preseed/$additional_grub_for_ubuntu_recovery"
28+#!/bin/bash -e
29+source /usr/lib/grub/grub-mkconfig_lib
30+cat <<EOF
31+menuentry "ubuntu-recovery restore" --hotkey f9 {
32+ search --no-floppy --hint '(hd0,gpt2)' --set --fs-uuid UUID_OF_RECOVERY_PARTITION
33+ if [ -s /boot/grub/common.cfg ]; then
34+ source /boot/grub/common.cfg
35+ else
36+ set options="boot=casper automatic-ubiquity noprompt quiet splash"
37+ fi
38+
39+ if [ "\\\${grub_platform}" != "efi" ]; then
40+ if [ -f \\\${prefix}/nomodesetlist.txt ]; then
41+ if hwmatch \\\${prefix}/nomodesetlist.txt 3; then
42+ if [ \\\${match} != 0 ]; then
43+ set options="nomodeset \\\$options"
44+ fi
45+ fi
46+ fi
47+ fi
48+
49+ #Support starting from a loopback mount (Only support ubuntu.iso for filename)
50+ if [ -f /ubuntu.iso ]; then
51+ loopback loop /ubuntu.iso
52+ set root=(loop)
53+ set options="\\\$options iso-scan/filename=/ubuntu.iso"
54+ fi
55+ if [ -n "\\\${lang}" ]; then
56+ set options="\\\$options locale=\\\$lang"
57+ fi
58+
59+ linux /casper/vmlinuz ubuntu-recovery/recovery_type=hdd \\\$options
60+ initrd /casper/initrd
61+}
62+EOF
63+EOF1
64+ cat <<EOF > "$temp_folder/preseed/set_env_for_ubuntu_recovery"
65+#!/bin/bash -ex
66+# replace the grub entry which ubuntu_recovery expected
67+recover_p=\$(lsblk -l | grep efi | cut -d ' ' -f 1 | sed 's/.$/2'/)
68+UUID_OF_RECOVERY_PARTITION=\$(ls -l /dev/disk/by-uuid/ | grep \$recover_p | awk '{print \$9}')
69+echo partition = \$UUID_OF_RECOVERY_PARTITION
70+sed -i "s/UUID_OF_RECOVERY_PARTITION/\$UUID_OF_RECOVERY_PARTITION/" push_preseed/preseed/$additional_grub_for_ubuntu_recovery
71+sudo rm -f /etc/grub.d/99_dell_recovery || true
72+chmod 766 push_preseed/preseed/$additional_grub_for_ubuntu_recovery
73+sudo cp push_preseed/preseed/$additional_grub_for_ubuntu_recovery /etc/grub.d/
74+
75+# Force changing the recovery partition label to PQSERVICE for ubuntu-recovery
76+sudo fatlabel /dev/\$recover_p PQSERVICE
77+EOF
78+ fi
79+
80 return 0
81 }
82 push_preseed() {
83@@ -152,12 +209,19 @@ inject_preseed() {
84 download_preseed && \
85 push_preseed
86 scp -o StrictHostKeyChecking=no "$user_on_target"@"$target_ip":/cdrom/SUCCSS_push_preseed "$temp_folder" || usage
87+
88+ if [ "${ubr}" == "yes" ]; then
89+ $SSH "$user_on_target"@"$target_ip" bash \$HOME/push_preseed/preseed/set_env_for_ubuntu_recovery || usage
90+ fi
91 $SSH "$user_on_target"@"$target_ip" touch /tmp/SUCCSS_inject_preseed
92 }
93
94 inject_recovery_iso() {
95 if [ -n "$local_iso" ]; then
96 img_name="$(basename "$local_iso")"
97+ if [ -z "${img_name##*stella*}" ]; then
98+ ubr="yes"
99+ fi
100 if [ "${ubr}" == "yes" ]; then
101 rsync_opts="--exclude=efi --delete --temp-dir=/var/tmp/rsync"
102 else
103@@ -172,7 +236,8 @@ cat <<EOF > "$temp_folder/$script_on_target_machine"
104 set -ex
105 sudo umount /cdrom /mnt || true
106 sudo mount -o loop $img_name /mnt && \
107-sudo mount /dev/\$(lsblk -l | grep efi | cut -d ' ' -f 1 | sed 's/.$/2'/) /cdrom && \
108+recover_p=\$(lsblk -l | grep efi | cut -d ' ' -f 1 | sed 's/.$/2'/) && \
109+sudo mount /dev/\$recover_p /cdrom && \
110 df | grep "cdrom\|mnt" | awk '{print \$2" "\$6}' | sort | tail -n1 | grep -q cdrom && \
111 sudo mkdir -p /var/tmp/rsync && \
112 sudo rsync -alv /mnt/ /cdrom/ $rsync_opts && \
113@@ -188,7 +253,7 @@ EOF
114 img_name="$(wget -q "$img_jenkins_out_url/" -O - | grep -o 'href=.*iso"' | awk -F/ '{print $NF}' | tr -d \")"
115 pushd "$temp_folder" || usage
116 wget "$img_jenkins_out_url/$img_name".md5sum
117- md5sum -c "$img_name".md5sum || wget "$img_jenkins_out_url"/"$img_name"
118+ md5sum -c "$img_name".md5sum || wget "$img_jenkins_out_url"/"$img_name" 2> /dev/null
119 md5sum -c "$img_name".md5sum || usage
120 local_iso="$PWD/$img_name"
121 popd
122@@ -212,7 +277,9 @@ poll_recovery_status() {
123
124 do_recovery() {
125 if [ "${ubr}" == "yes" ]; then
126- echo GRUB_DEFAULT=3 | $SSH "$user_on_target"@"$target_ip" -T "sudo tee -a /etc/default/grub.d/automatic-oem-config.cfg"
127+ echo GRUB_DEFAULT='"ubuntu-recovery restore"' | $SSH "$user_on_target"@"$target_ip" -T "sudo tee -a /etc/default/grub.d/automatic-oem-config.cfg"
128+ echo GRUB_TIMEOUT_STYLE=menu | $SSH "$user_on_target"@"$target_ip" -T "sudo tee -a /etc/default/grub.d/automatic-oem-config.cfg"
129+ echo GRUB_TIMEOUT=5 | $SSH "$user_on_target"@"$target_ip" -T "sudo tee -a /etc/default/grub.d/automatic-oem-config.cfg"
130 $SSH "$user_on_target"@"$target_ip" sudo update-grub
131 $SSH "$user_on_target"@"$target_ip" sudo reboot &
132 else

Subscribers

People subscribed via source and target branches