Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean IMGB during installation #2956

Merged
merged 1 commit into from
Dec 19, 2022

Conversation

giggsoff
Copy link
Contributor

@giggsoff giggsoff commented Dec 5, 2022

In case of usage the same drive for EVE-OS installation (for example SD card in ROL) we may keep the old data in IMGB which is not expected, so let's clean it.

Signed-off-by: Petr Fedchenkov giggsoff@gmail.com

else
# clean first bytes of partition
# to avoid keeping of stale data
dd if=/dev/zero of="$IMGFILE" bs=512 count=1 conv=notrunc seek="$(( SEC_START * 512 ))" oflag=seek_bytes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you still use bs=512, so multiplication and "seek_bytes" flag are excessive. but this is minor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thank you, modified.

@rouming
Copy link
Contributor

rouming commented Dec 5, 2022

Just to be sure I understand the intention correctly: are you trying to wipe out the partition table? If yes - then do we care about secondary gpt header (at the end of the disk)?

@giggsoff
Copy link
Contributor Author

giggsoff commented Dec 5, 2022

Just to be sure I understand the intention correctly: are you trying to wipe out the partition table? If yes - then do we care about secondary gpt header (at the end of the disk)?

Actually I try to invalidate squashfs partition (at least to broke header) we potentially have in IMGB to avoid its mount and introspection (in baseosmgr) from pillar's logic.

@giggsoff giggsoff force-pushed the clean-imgb-installer branch from 8e719c3 to 86514dd Compare December 5, 2022 15:37
@rouming
Copy link
Contributor

rouming commented Dec 5, 2022

Does it make sense to use wipefs instead of raw dd? (just it might be you did not consider it).

@giggsoff
Copy link
Contributor Author

giggsoff commented Dec 5, 2022

Does it make sense to use wipefs instead of raw dd? (just it might be you did not consider it).

The logic here assume that in general IMGFILE is a file (raw image) that we try to modify using offsets, not a device with partitions which we can use to point wipefs command onto.

else
# clean first block of partition
# to avoid mounting of stale data
dd if=/dev/zero of="$IMGFILE" bs=512 count=1 conv=notrunc seek="$SEC_START"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why seek using sectors here and bytes on line 210? Is there a reason for them to differ?

Copy link
Contributor Author

@giggsoff giggsoff Dec 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main difference in block size. We use large block size on line 210 and should use bytes offset to seek and calculate it using SEC_START * 512. Here we use bs (block size) 512, and seek SEC_START * 512 in bytes equivalent with SEC_START * bs, so we can use seek in blocks (SEC_START) and avoid unnecessary calculation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might save 100us in CPU time, but it uses tens of seconds of human brain processing time each time anybody will read this code since they need to determine that it is actually writing to the same place.
I know which one I think is more expensive.

Copy link
Contributor

@rouming rouming Dec 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! This is exactly the opposite what I feel (I prefer memory and storage offsets in blocks, pages, not bytes) :) Because Petr already changed this line from what you, Erik, suggest here, to this current line, pointed by me. But anyway, this is very minor to me, both ways work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And for me was a surprise to see the special flag in dd 'seek_bytes', because when you often work with these commands you think in blocks and then you see bs=X and then seek=$BS * N, not noticing the 'seek_bytes', and then you brain stops here thinking 'hey there is an error, your block size is X, why you do this multiplication?"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is why I hanged for a couple of seconds on this particular line :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's funny! One line, different view perspective, different path of thinking

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rouming my only request is that the two dd lines use the same approach.

@@ -216,8 +222,8 @@ do_imga() {
}

do_imgb() {
# for now we are not initializing IMGB - hence passing /dev/null
do_rootfs $1 IMGB /dev/null
# for now we are not initializing IMGB - hence not passing the source
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of "not initializing" how about "wiping"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense, modified

@giggsoff giggsoff force-pushed the clean-imgb-installer branch from 86514dd to c92fd7d Compare December 14, 2022 08:49
@eriknordmark
Copy link
Contributor

Will the eden install/onboarding tests exercise this? Or do we need to do some manual install with a USB stick?

In case of usage the same drive for EVE-OS installation (for example SD
card in ROL) we may keep the old data in IMGB which is not expected, so
let's clean it.

Signed-off-by: Petr Fedchenkov <giggsoff@gmail.com>
@giggsoff giggsoff force-pushed the clean-imgb-installer branch from c92fd7d to 39f9489 Compare December 14, 2022 12:44
@giggsoff
Copy link
Contributor Author

Will the eden install/onboarding tests exercise this? Or do we need to do some manual install with a USB stick?

Right now we use installer only in ROL (during EdenGCP).

Copy link
Contributor

@eriknordmark eriknordmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eriknordmark eriknordmark merged commit 4aa7edc into lf-edge:master Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants