refactor: generate GRUB images #12611
Conversation
| return fmt.Errorf("failed to write back META partition data: %w", err) | ||
| } | ||
|
|
||
| return gptdev.Sync() |
There was a problem hiding this comment.
both .Sync() calls were in the "image" mode, so they flush the pre-allocated file to disk which results in tons of useless I/O, as the file has gaps, and we're going to compress and throw it away in a moment.
So don't call fsync() on the disk image.
| }) | ||
| for idx, p := range pt.Partitions() { | ||
| if p.Name == constants.BIOSGrubPartitionLabel { | ||
| biosPartition = p |
There was a problem hiding this comment.
if we find the partition in the live partition table, we find the FirstLBA which is the first sector - this is what we need for patching, drop all the math later
|
|
||
| partitionImageFile := filepath.Join(i.options.MountPrefix, biosPartitionInfo[0].Label+".img") | ||
|
|
||
| if err := utils.CreateRawDisk(i.options.Printf, partitionImageFile, int64(biosPartitionInfo[0].Size), true); err != nil { |
There was a problem hiding this comment.
we don't need an intermediate file to have an image of the future partition which contains core.img -> just write core.img directly
| mbr := make([]byte, 446) | ||
|
|
||
| if _, err := bootImg.ReadAt(mbr, 0); err != nil { | ||
| if _, err := io.ReadFull(bootImg, mbr); err != nil { |
There was a problem hiding this comment.
Read() call is not guaranteed to read all bytes (vs. the Write call), so use ReadFull
There was a problem hiding this comment.
i thought newer go fixed the Read(), anyways let's be safe
Simplify the flow a bit by using live partition info, avoid doing some calculations which are already done in the partition code. Remove some steps I believe we don't need to do. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
|
/m |
Simplify the flow a bit by using live partition info,
avoid doing some calculations which are already done in the
partition code.
Remove some steps I believe we don't need to do.