Hi,

Am Montag, den 06.01.2020, 07:52 +0100 schrieb Johannes Schauer:
> Hi,
> 
> On Wed, 13 Nov 2019 19:37:04 +0100 Benjamin Drung <
> benjamin.dr...@cloud.ionos.com> wrote:
> > Am Mittwoch, den 13.11.2019, 19:22 +0100 schrieb Johannes Schauer:
> > > Quoting Benjamin Drung (2019-11-13 19:03:31)
> > > > One hook is missing: A clean hook that is run after the
> > > > cleanup, which
> > > > would be run at last step of the setup function.
> > > What kind of stuff would you run there instead of putting it into
> > > the
> > > customize hook?
> > My cleanup script contains two things:
> > 
> > 1) Removal of different stuff like /etc/resolv.conf,
> > /etc/udev/rules.d/70-persistent-net.rules,
> 
> why can these two things not go into the customize hook?

They can probably go at the end of the customize hooks.

> > 2) Adjusting the timestamp of files/directories, e.g.:
> > 
> > find "$0/etc/" "$0/var/" -newermt "@${SOURCE_DATE_EPOCH}" \
> >     \( -type f -o -type l \) -print0 | \
> >     xargs -0r touch -hm -d "@${SOURCE_DATE_EPOCH}"
> 
> Why is the customize hook too late for this snippet?
> 
> I assume you are not creating a tarball then, because tar would take
> care of clamping the mtime for you?

I wasn't aware of the mtime clamping. So this mtime adjustment can be
removed completely.

> > > > I have only one issue related to the hooks: There is no easy,
> > > > safe, and
> > > > reliable way to copy stuff out of the image to an existing
> > > > directory.
> > > > Use case: copy the kernel+initrd out of the image for PXE
> > > > booting.
> > > I agree and I have needed this myself several times already. I'm
> > > still
> > > thinking of a good way to implement this because it does not only
> > > involve
> > > copying the data itself but also assuring right permission and
> > > ownership
> > > information.  Furthermore, it should be possible to copy files in
> > > and out
> > > of the chroot at any point where hook are currently run.
> > > 
> > > Currently I'm doing a lot of this in my own scripts:
> > > 
> > > --customize-hook='cp -a tmpfile "$1/target/directory"'
> > > --customize-hook='echo foobar > "$1/target/file"'
> > > 
> > > I have been considering adding another option that allows
> > > extracting
> 
> As you know from my private mail, there are now some basic special
> hooks to
> copy stuff in and out of the chroot. Just like with guestfish hooks,
> globbing
> is not (yet) supported. This could be fixed but would require
> implementing a
> full shell quoting parser as well as a symlink resolver which the
> current
> solution is working around by utilizing /bin/sh inside the chroot. If
> you want
> globbing, then create one hook that utilizes globbing in sh to create
> a tarball
> of the files you want and a second hook to move that tarball out of
> the chroot.
> Like this:
> 
> --customize-hook='chroot "$1" sh -c "cd /boot && tar -cf
> /tmp/boot.tar vmlinuz* initrd.img*"'
> --customize-hook='copy-out /tmp/boot.tar .'
> --customize-hook='rm "$1"/tmp/boot.tar'
> 
> Or like this:
> 
> --customize-hook='chroot "$1" sh -c "mkdir /tmp/boot && cp
> /boot/vmlinuz* /boot/initrd.img* /tmp/boot"'
> --customize-hook='copy-out /tmp/boot .'
> --customize-hook='rm -r "$1"/tmp/boot'

I tried this solution and are fine with using it. Compared to
implementing globbing in mmdebstrap, this solution adds two more hooks
and copies the files twice (should not have a big performance impact).

The only remaining issues is that copy-out copies the directory as-is
instead of copying the content of the directory. So in this your
example above, the current directory would contain a directory 'boot'
containing the kernel and initrd, but I like to have the kernel and
initrd in the current directory (instead of the 'boot' subdirectory).
Any good idea how to do that?

-- 
Benjamin Drung

System Developer and Debian & Ubuntu Developer
Platform Engineering Compute (IONOS Cloud)

1&1 IONOS SE | Greifswalder Str. 207 | 10405 Berlin | Germany
E-mail: benjamin.dr...@cloud.ionos.com | Web: www.ionos.de

Hauptsitz Montabaur, Amtsgericht Montabaur, HRB 24498
Vorstand: Dr. Christian Böing, Hüseyin Dogan, Hans-Henning Kettler,
Matthias Steinberg, Achim Weiß
Aufsichtsratsvorsitzender: Markus Kadelke
Member of United Internet

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to