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

Add lz4 initrd compression support for even faster mkrescue #1218

Closed
ProBackup-nl opened this issue Mar 6, 2017 · 11 comments
Closed

Add lz4 initrd compression support for even faster mkrescue #1218

ProBackup-nl opened this issue Mar 6, 2017 · 11 comments
Assignees
Labels
enhancement Adaptions and new features fixed / solved / done minor bug An alternative or workaround exists
Milestone

Comments

@ProBackup-nl
Copy link
Contributor

Even with REAR_INITRD_COMPRESSION="fast", rear mkrescue does spend significant time in compressing rootfs into a compressed initrd file. After inserting some bash timer code in 900_create_initramfs.sh, it seems that the creation of the 51M file takes 9 seconds.

Creating recovery/rescue system initramfs/initrd initrd.cgz with gzip fast compression
Created initrd.cgz with gzip fast compression (53040694 bytes) in 9 seconds

I'd wish support for the even faster lz4 codec, which seems understood by the Arch Linux kernel by default according to:

$ cat /etc/mkinitcpio.conf | grep COMPRESSION=
#COMPRESSION="gzip"
#COMPRESSION="bzip2"
#COMPRESSION="lzma"
#COMPRESSION="xz"
#COMPRESSION="lzop"
#COMPRESSION="lz4"
@ProBackup-nl
Copy link
Contributor Author

ProBackup-nl commented Mar 6, 2017

Apparently I did something wrong. The commit that was intended for a new pull request was merged with my earlier pull request. I don't know (yet) how to fix this. My uneducated guess is that I need to make a git branch somewhere in the process.

Note: with REAR_INITRD_COMPRESSION="lz4" the 64M initrd file creation is now done in 4 till 5 seconds:

Creating recovery/rescue system initramfs/initrd initrd.lz4 with lz4 compression
Created initrd.lz4 with lz4 compression (66863824 bytes) in 4 seconds
...
Creating recovery/rescue system initramfs/initrd initrd.lz4 with lz4 compression
Created initrd.lz4 with lz4 compression (66864362 bytes) in 5 seconds

I can't test whether it boots correctly because I have an issue with:

BUG in /root/rear/usr/share/rear/output/USB/Linux-i386/100_create_efiboot.sh:
'Unknown EFI bootloader'

@jsmeix
Copy link
Member

jsmeix commented Mar 6, 2017

@ProBackup-nl
the way how I do GitHub pull requests is basically
(on my local git copy):

$ git checkout master

$ git checkout -b implement_new_lz4_initrd_compression_issue1218
Switched to a new branch 'implement_new_lz4_initrd_compression_issue1218'

code hacking

$ git commit -am "implemented new lz4 initrd compression (issue 1218)"

$ git push origin implement_new_lz4_initrd_compression_issue1218

Now my new branch
'implement_new_lz4_initrd_compression_issue1218'
exists on GitHub.
Then I use the GitHub web interface
to create a new pull request from that new branch
'implement_new_lz4_initrd_compression_issue1218'
to the current ReaR upstream repository.

In general see
http://relax-and-recover.org/development/

@jsmeix
Copy link
Member

jsmeix commented Mar 6, 2017

@ProBackup-nl
assume you created a new pull request from your branch
and now I request changes, then you can push more commits
to that same branch and all your commits get automatically
included in your existing pull request of that branch, e.g.:
(on yor local git copy):

$ git checkout master

$ git checkout implement_new_lz4_initrd_compression_issue1218
Switched to branch 'implement_new_lz4_initrd_compression_issue1218'

further code hacking

$ git commit -am "improved lz4 initrd compression (issue 1218)"

$ git push origin implement_new_lz4_initrd_compression_issue1218

@jsmeix jsmeix self-assigned this Mar 6, 2017
@jsmeix jsmeix added enhancement Adaptions and new features fixed / solved / done labels Mar 6, 2017
@jsmeix jsmeix added this to the Rear v2.1 milestone Mar 6, 2017
@jsmeix
Copy link
Member

jsmeix commented Mar 6, 2017

With
#1217
merged, this issue should be fixed.

@ProBackup-nl
Copy link
Contributor Author

ProBackup-nl commented Mar 10, 2017

There is a bug in the code for this lz4 initramfs feature. When the initramfs of Arch Linux itself is build using mkinitcpio using lz4 compression, the kernel will boot ok.
REAR_INITRD_COMPRESSION="fast" boots OK too.
REAR_INITRD_COMPRESSION="lz4" results in error:

initramfs unpacking failed: junk in compressed archive

@jsmeix Should this issue be re-opened or a new issue created?

@ProBackup-nl
Copy link
Contributor Author

ProBackup-nl commented Mar 10, 2017

$ lsinitcpio -a /tmp/sdb1/initrd.cgz
/usr/bin/lsinitcpio: line 78: warning: command substitution: ignored null byte in input
/usr/bin/lsinitcpio: line 90: warning: command substitution: ignored null byte in input
/usr/bin/lsinitcpio: line 175: /tmp/lsinitcpio.Ru0WEp/VERSION: No such file or directory
/usr/bin/lsinitcpio: line 178: /tmp/lsinitcpio.Ru0WEp/config: No such file or directory
==> Image: /tmp/sdb1/initrd.cgz
==> Kernel: 4.9.11-1-ARCH
==> Size: 50.6 MiB
==> Compressed with: gzip
  -> Uncompressed size: 120.06 MiB (.421 ratio)
  -> Estimated extraction time: 3.126s

==> Included binaries:

$ lsinitcpio -a /tmp/sdb1/initrd.lz4
==> ERROR: Newer lz4 stream format detected! This may not boot!
/usr/bin/lsinitcpio: line 175: /tmp/lsinitcpio.RbVERF/VERSION: No such file or directory
/usr/bin/lsinitcpio: line 178: /tmp/lsinitcpio.RbVERF/config: No such file or directory
==> Image: /tmp/sdb1/initrd.lz4
==> Kernel: 4.9.11-1-ARCH
==> Size: 63.78 MiB
==> Compressed with: lz4
  -> Uncompressed size: 120.06 MiB (.531 ratio)
  -> Estimated extraction time: 3.503s

==> Included binaries:

$ lsinitcpio -a /boot/initramfs-linux.img
==> Image: /boot/initramfs-linux.img
==> Created with mkinitcpio 22
==> Kernel: 4.9.11-1-ARCH
==> Size: 6.41 MiB
==> Compressed with: lz4 -l
  -> Uncompressed size: 14.4 MiB (.445 ratio)
  -> Estimated extraction time: 0.248s
...

$ lz4 --help
...
 -l     : compress using Legacy format (Linux kernel compression)
...

@ProBackup-nl
Copy link
Contributor Author

ProBackup-nl commented Mar 10, 2017

Adding Linux legacy -l to lz4 results

  • Size increased from 66864362 to 66871053: negligible factor 1.0001
  • Estimated extraction time reduced from 3.503s to 0.239s: 14.6 times faster
  • Creating the compressed initramfs file is still in the 4-5 seconds range
  • The lsinitcpio "ERROR: Newer lz4 stream format detected! This may not boot!" is gone
$ lsinitcpio -a /tmp/sdb1/initrd.lz4
/usr/bin/lsinitcpio: line 175: /tmp/lsinitcpio.22JAqI/VERSION: No such file or directory
/usr/bin/lsinitcpio: line 178: /tmp/lsinitcpio.22JAqI/config: No such file or directory
==> Image: /tmp/sdb1/initrd.lz4
==> Kernel: 4.9.11-1-ARCH
==> Size: 63.77 MiB
==> Compressed with: lz4 -l
  -> Uncompressed size: 120.06 MiB (.531 ratio)
  -> Estimated extraction time: 0.239s

==> Included binaries:

And last but not least: it boots to ReaR

@jsmeix
Copy link
Member

jsmeix commented Mar 13, 2017

Reopening because it needs some enhancement, see
#1218 (comment)
and
#1235
and
#1236

@jsmeix jsmeix reopened this Mar 13, 2017
@jsmeix jsmeix added minor bug An alternative or workaround exists and removed fixed / solved / done labels Mar 13, 2017
@ProBackup-nl
Copy link
Contributor Author

The strange thing here is that Arch Linux on the source system boots even with an lz4 -9 compressed initrd file. No need for lz4 -l on the source system.

jsmeix added a commit that referenced this issue Mar 16, 2017
Create initrd.lz4 with lz4 -l compression
'-l' = legacy format is preferred because
otherwise it may fail to get uncompressed,
see #1218
jsmeix added a commit that referenced this issue Mar 16, 2017
Document initrd.lz4 with lz4 -l compression
and comparison with other compression methods,
see #1218
@jsmeix
Copy link
Member

jsmeix commented Mar 16, 2017

With
#1235
and
#1236
merged
this issue schould be again fixed/solved/done
(and if not we can reopen it again).

@jsmeix jsmeix closed this as completed Mar 16, 2017
@jsmeix
Copy link
Member

jsmeix commented Mar 16, 2017

@ProBackup-nl
regardless that I am not at all a Linux booting expert
here an offhanded vague idea regarding why
an lz4 -9 compressed initrd file works on the original system
but not in the ReaR recovery system:

As far as I understand it
it is the kernel that uncompresses the initrd
and the kernel must do that on its own "as is"
without any additional stuff like kernel modules
because as long as the contents of the initrd are not
accessible, the kernel cannot load a module.

Because the ReaR recovery system uses the exact same kernel
as the original system (provided the KERNEL_FILE value is really
the kernel that runs in the original system - check that if several
kernel files exist in /boot/) the difference that lets it fail versus
that makes it work cannot be in the kernel.

Because at the time when the kernel uncompresses the initrd
there is only the kernel and the initrd, the difference
that lets it fail versus that makes it work
must be in the initrd of the original system
versus the initrd of the ReaR recovery system.

That the difference must be in the initrds matches the fact
that the initrd of the original system is created differently
compared to the initrd of the ReaR recovery system.

A colleague told me that he thinks to remember in the past
for special initrd compressions one had to do special
additional stuff with the initrd to ensure the kernel
could later successfuly uncompress it - he was vaguely
talking about manually adjusting magic numbers at the
beginning of the initrd to help the kernel to correctly
autodetect the actual initrd compression or things like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adaptions and new features fixed / solved / done minor bug An alternative or workaround exists
Projects
None yet
Development

No branches or pull requests

2 participants