Skip to content

Commit 4803847

Browse files
authored
Remove the rw folder from the image after installing in KVM (#8746)
* Remove the rw folder from the image after installing in KVM When the image is installed from within KVM and then loaded, some files (such as timer stamp files) are created as part of that bootup that then get into the final image. This can cause some side effects, such as systemd thinking that some persistent timers need to run because the last trigger time got missed. Therefore, at the end of the check_install.py script, remove the rw folder so that it doesn't exist in the image, and that when this image is started up in a KVM setup for the first time, it starts with a truly clean slate. Without this change, the issue seen was that for fstrim.timer, a stamp file would be present in /var/lib/systemd/timers (and for other timers that are marked as persistent). This would then cause fstrim.service to get started immediately when starting a QEMU setup if the timer for that service missed a trigger, and not wait 10 minutes after bootup. In the case of fstrim.timer, that means if the image was started in QEMU after next Monday, since that timer is scheduled to be triggered weekly. Signed-off-by: Saikrishna Arcot <[email protected]> * Split installation of SONiC and test bootup into two separate scripts Just removing the rw directory causes other issues, since the first boot tasks no longer run since that file isn't present. Also, just recreating that file doesn't completely help, because there are some files that are moved from the /host folder into the base filesystem layer, and so are no longer available. Instead, split the installation of SONiC and doing the test bootup into two separate scripts and two separate KVM instances. The first KVM instance is the one currently being run, while the second one has the `-snapshot` flag added in, which means any changes to the disk image don't take effect. Signed-off-by: Saikrishna Arcot <[email protected]>
1 parent afd4098 commit 4803847

File tree

3 files changed

+83
-12
lines changed

3 files changed

+83
-12
lines changed

check_install.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ def main():
1515

1616
args = parser.parse_args()
1717

18-
KEY_UP = '\x1b[A'
19-
KEY_DOWN = '\x1b[B'
20-
KEY_RIGHT = '\x1b[C'
21-
KEY_LEFT = '\x1b[D'
22-
2318
login_prompt = 'sonic login:'
2419
passwd_prompt = 'Password:'
2520
cmd_prompt = "{}@sonic:~\$ $".format(args.u)
@@ -37,22 +32,19 @@ def main():
3732
raise
3833
time.sleep(1)
3934

40-
# select ONIE embed
35+
# select default SONiC Image
4136
p.expect(grub_selection)
42-
p.sendline(KEY_DOWN)
37+
p.sendline()
4338

44-
# install sonic image
39+
# bootup sonic image
4540
while True:
46-
i = p.expect([login_prompt, passwd_prompt, grub_selection, cmd_prompt])
41+
i = p.expect([login_prompt, passwd_prompt, cmd_prompt])
4742
if i == 0:
4843
# send user name
4944
p.sendline(args.u)
5045
elif i == 1:
5146
# send password
5247
p.sendline(args.P)
53-
elif i == 2:
54-
# select onie install
55-
p.sendline()
5648
else:
5749
break
5850

install_sonic.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import pexpect
5+
import sys
6+
import time
7+
8+
9+
def main():
10+
11+
parser = argparse.ArgumentParser(description='test_login cmdline parser')
12+
parser.add_argument('-p', type=int, default=9000, help='local port')
13+
14+
args = parser.parse_args()
15+
16+
#KEY_UP = '\x1b[A'
17+
KEY_DOWN = '\x1b[B'
18+
#KEY_RIGHT = '\x1b[C'
19+
#KEY_LEFT = '\x1b[D'
20+
21+
grub_selection = "The highlighted entry will be executed"
22+
23+
i = 0
24+
while True:
25+
try:
26+
p = pexpect.spawn("telnet 127.0.0.1 {}".format(args.p), timeout=600, logfile=sys.stdout, encoding='utf-8')
27+
break
28+
except Exception as e:
29+
print(str(e))
30+
i += 1
31+
if i == 10:
32+
raise
33+
time.sleep(1)
34+
35+
# select ONIE embed
36+
p.expect(grub_selection)
37+
p.sendline(KEY_DOWN)
38+
39+
# select ONIE install
40+
p.expect(['ONIE: Install OS'])
41+
p.expect([grub_selection])
42+
p.sendline()
43+
44+
# wait for grub, and exit
45+
p.expect([grub_selection])
46+
47+
48+
if __name__ == '__main__':
49+
main()

scripts/build_kvm_image.sh

+30
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ kvm_log=$(mktemp)
7171
trap on_exit EXIT
7272
trap on_error ERR
7373

74+
echo "Installing SONiC"
75+
7476
/usr/bin/kvm -m $MEM \
7577
-name "onie" \
7678
-boot "order=cd,once=d" -cdrom "$ONIE_RECOVERY_ISO" \
@@ -94,6 +96,34 @@ sleep 2.0
9496

9597
echo "to kill kvm: sudo kill $kvm_pid"
9698

99+
./install_sonic.py
100+
101+
kill $kvm_pid
102+
103+
echo "Booting up SONiC"
104+
105+
/usr/bin/kvm -m $MEM \
106+
-name "onie" \
107+
-device e1000,netdev=onienet \
108+
-netdev user,id=onienet,hostfwd=:0.0.0.0:3041-:22 \
109+
-vnc 0.0.0.0:0 \
110+
-vga std \
111+
-snapshot \
112+
-drive file=$DISK,media=disk,if=virtio,index=0 \
113+
-serial telnet:127.0.0.1:$KVM_PORT,server > $kvm_log 2>&1 &
114+
115+
kvm_pid=$!
116+
117+
sleep 2.0
118+
119+
[ -d "/proc/$kvm_pid" ] || {
120+
echo "ERROR: kvm died."
121+
cat $kvm_log
122+
exit 1
123+
}
124+
125+
echo "to kill kvm: sudo kill $kvm_pid"
126+
97127
./check_install.py -u $SONIC_USERNAME -P $PASSWD -p $KVM_PORT
98128

99129
kill $kvm_pid

0 commit comments

Comments
 (0)