melato / lxops

Apache License 2.0
8 stars 0 forks source link

Extract disk devices from image #15

Closed melato closed 10 months ago

melato commented 11 months ago

Add a command to copy files from the root filesystem of an image to device directories.

For example:

lxops extract-devices -name alpine-nginx-202324-1518 nginx.yaml

This would:

Even better, instead of adding a new command, incorporate this functionality in the launch command:

lxops launch -name alpine-nginx-202324-1518 nginx.yaml

When it needs to create a disk device directory, launch could extract it from the image, instead of creating an empty one.

Rationale

Let's say I want to build an nginx container that has /var/log/ in an external disk device. When I build the corresponding image, until now, I've been building the image with /var/log/ in an external disk device too. The resulting image has an empty /var/log/ directory. The container depends on it being provided externally.

I would like to build the image with the nginx packages and files without any external disk devices. I can then use this image to extract the devices that I want to use as templates for my containers. That way the image has all the files that it was built with, and I can use it with different disk devices.

Implementation for launch

- create the container from the image without starting it
- find the origin of the container zfs filesystem.
  The origin will be a readonly snapshot of the image root filesystem.
- mount this snapshot to a temporary directory:
  sudo mount -t zfs .../images/...@readonly /tmp/...
- copy the device files from that mount:
  rsync -av /tmp/.../rootfs/var/log/ /.../log/
  umount /the temporary directory
melato commented 11 months ago

I ran into a problem of shifted uids: The image has unshifted uids/gids (root is 0). But I need to copy the shifted ids (root is 1000000) in the device directory.

melato commented 10 months ago

One way around the shifted ids problem is to shift them up. Add an "lxops shiftids" command that would shift the uid,gid of all files in a directory, recursively. Call it with sudo, so it can change file ownerehips. I am calling rsync anyway, calling another program to shift the ids is not a lot more overhead. It would be nice if rsync had an option to shift ids.

melato commented 10 months ago

Implemented "extract" command that extracts disk devices from an image. It would be nice to include this functionality in the "launch" command.