В Thu, 23 Apr 2015 10:23:09 -0400 David Shaw <[email protected]> пишет:
> > When booting the box with grub2 2.02, it does not work. The error is: > > Ramdisk at 0x37979000, length 0x0033b290 > gzip image: decompressed addr 0xbfff7000, len 0x00008f58: failed > Decompression error: output buffer overrun > Could you test attached patch? While I'm past this message using your archive, in qemu-kvm it hangs after "... booting ..." and in qemu-system-i386 I get something that looks like memory corruption with occasional crash when initrd is uncompressed. From: Andrei Borzenkov <[email protected]> Subject: [PATCH] loader/linux: do not pad initrd with zeroes at the end Syslinux memdisk is using initrd image and needs to know uncompressed size in advance. For gzip uncompressed size is at the end of compressed stream. Grub padded each input file to 4 bytes at the end, which means syslinux got wrong size. Linux initramfs loader apparently does not care about trailing alignment. So change code to align beginning of each file instead which automatically gives us the correct size for single file. Reported-By: David Shaw <[email protected]> --- grub-core/loader/linux.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c index 117232f..35b858e 100644 --- a/grub-core/loader/linux.c +++ b/grub-core/loader/linux.c @@ -161,6 +161,9 @@ grub_initrd_init (int argc, char *argv[], for (i = 0; i < argc; i++) { const char *fname = argv[i]; + + initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4); + if (grub_memcmp (argv[i], "newc:", 5) == 0) { const char *ptr, *eptr; @@ -205,7 +208,7 @@ grub_initrd_init (int argc, char *argv[], initrd_ctx->nfiles++; initrd_ctx->components[i].size = grub_file_size (initrd_ctx->components[i].file); - initrd_ctx->size += ALIGN_UP (initrd_ctx->components[i].size, 4); + initrd_ctx->size += initrd_ctx->components[i].size; } if (newc) @@ -253,6 +256,9 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, { grub_ssize_t cursize; + grub_memset (ptr, 0, ALIGN_UP_OVERHEAD ((grub_addr_t)ptr, 4)); + ptr += ALIGN_UP_OVERHEAD ((grub_addr_t)ptr, 4); + if (initrd_ctx->components[i].newc_name) { ptr += insert_dir (initrd_ctx->components[i].newc_name, @@ -283,8 +289,6 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, return grub_errno; } ptr += cursize; - grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); - ptr += ALIGN_UP_OVERHEAD (cursize, 4); } if (newc) ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, 0); -- tg: (104dff3..) u/initrd-pad (depends on: master) _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
