#6 Fix for RHCOS / FCOS
Merged 4 years ago by ddd. Opened 4 years ago by fidencio.
rpms/ fidencio/kata-osbuilder wip/fix_installation_for_rhcos  into  master

@@ -3,8 +3,8 @@ 

  

  [Service]

  Type=oneshot

- ExecStart=/usr/libexec/kata-containers/fedora-kata-osbuilder.sh -c

- ExecReload=/usr/libexec/kata-containers/fedora-kata-osbuilder.sh

+ ExecStart=/usr/libexec/kata-containers/osbuilder/fedora-kata-osbuilder.sh -c

+ ExecReload=/usr/libexec/kata-containers/osbuilder/fedora-kata-osbuilder.sh

  

  [Install]

  WantedBy=multi-user.target

file modified
+16 -11
@@ -58,7 +58,10 @@ 

  Patch02: osbuilder-0002-image-builder-Add-NSDAX_BIN-for-passing-in-compiled-.patch

  # Don't clobber our pre-populated /sbin/init

  # https://github.com/kata-containers/osbuilder/pull/420

- Patch03: osbuilder-0002-rootfs-Don-t-overwrite-init-if-it-already-exists.patch

+ Patch03: osbuilder-0003-rootfs-Don-t-overwrite-init-if-it-already-exists.patch

+ # Force mount_dir to be created in $TMPDIR

+ # https://github.com/kata-containers/osbuilder/pull/436

+ Patch04: osbuilder-0004-image_builder-Force-mount_dir-to-be-created-in-TMPDI.patch

  

  

  BuildRequires: gcc
@@ -193,19 +196,21 @@ 

  %postun

  %systemd_postun kata-osbuilder-generate.service

  %post

- %systemd_post kata-osbuilder-generate.service
ddd commented 4 years ago

I must be confused, but this apparently used to be invoked, and now is not. I don't understand why. The log you shared shows errors that are not obviously related to this. Are they errors of the service starting, or logs of that build step.

If we don't generate the service, how does the image even get created? I thought the whole point of the service was to generate the image on read-only systems like CoreOS.

- 

- TMPOUT="$(mktemp -t kata-rpm-post-XXXXXX.log)"

- echo "Creating kata appliance initrd and filesystem image..."

- bash %{kataosbuilderdir}/fedora-kata-osbuilder.sh > ${TMPOUT} 2>&1

- if test "$?" != "0" ; then

-     echo "Building failed. Here is the log details:"

-     cat ${TMPOUT}

-     exit 1

+ # Skip running this on Fedora CoreOS / Red Hat CoreOS

+ if test -w %{katalocalstatecachedir}; then

+     %systemd_post kata-osbuilder-generate.service

+ 

+     TMPOUT="$(mktemp -t kata-rpm-post-XXXXXX.log)"

+     echo "Creating kata appliance initrd and filesystem image..."

+     bash %{kataosbuilderdir}/fedora-kata-osbuilder.sh > ${TMPOUT} 2>&1

+     if test "$?" != "0" ; then

+         echo "Building failed. Here is the log details:"

+         cat ${TMPOUT}

+         exit 1

+     fi

  fi

  

  

- 

  %files

  %license LICENSE

  %doc CODE_OF_CONDUCT.md CONTRIBUTING.md README.md

osbuilder-0003-rootfs-Don-t-overwrite-init-if-it-already-exists.patch osbuilder-0002-rootfs-Don-t-overwrite-init-if-it-already-exists.patch
file renamed
file was moved with no change to the file
@@ -0,0 +1,37 @@ 

+ From 4b9fbceaa3f6db76736489d9d00b74a3967112d2 Mon Sep 17 00:00:00 2001

+ From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>

+ Date: Mon, 23 Mar 2020 17:08:28 +0100

+ Subject: [PATCH] image_builder: Force mount_dir to be created in $TMPDIR

+ MIME-Version: 1.0

+ Content-Type: text/plain; charset=UTF-8

+ Content-Transfer-Encoding: 8bit

+ 

+ Immutable systems, as such Red Hat Core OS and Fedora Core OS, will not

+ allow mount_dir to be created in a location that's not read-write.

+ 

+ Let's ensure we use $TMPDIR (with /tmp as fallback) as base for mount_dir,

+ as it's a safe writable choice for any distro supported by kata.

+ 

+ Fixes: #437

+ 

+ Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>

+ ---

+  image-builder/image_builder.sh | 2 +-

+  1 file changed, 1 insertion(+), 1 deletion(-)

+ 

+ diff --git a/image-builder/image_builder.sh b/image-builder/image_builder.sh

+ index aa813d5..04c840c 100755

+ --- a/image-builder/image_builder.sh

+ +++ b/image-builder/image_builder.sh

+ @@ -372,7 +372,7 @@ create_rootfs_image() {

+  	fi

+  

+  	info "Mounting root partition"

+ -	readonly mount_dir=$(mktemp -d osbuilder-mount-dir.XXXX)

+ +	readonly mount_dir=$(mktemp -p ${TMPDIR:-/tmp} -d osbuilder-mount-dir.XXXX)

+  	mount "${device}p1" "${mount_dir}"

+  	OK "root partition mounted"

+  

+ -- 

+ 2.26.0.rc2

+ 

This series contains a few fixes in order to have kata-osbuilder package installed and its script running on FCOS/RHCOS.

1/ I would use the --tmpdir option of mktemp. That seems safer in the long run than -p ${TMPDIR:-/tmp}.

2/ I don't understand why you disable the service
%systemd_post kata-osbuilder-generate.service

Isn't that also necessary on CoreOS?

Why not also use --tmpdir for the log output there?

Let me reply in parts:

1/ I would use the --tmpdir option of mktemp. That seems safer in the long run than -p ${TMPDIR:-/tmp}.

Please, add this comment to the upstream issue: # https://github.com/kata-containers/osbuilder/pull/436
But the reason I went for the short option instead of the long one was to keep consistence with the "-d" option already used (instead of using "--directory");

2/ I don't understand why you disable the service
%systemd_post kata-osbuilder-generate.service

Isn't that also necessary on CoreOS?

This would just fail on RHCOS, causing the package to not be installed at all;
Unfortunately I don't have the logs handy here.

Why not also use --tmpdir for the log output there?

This was not introduced by my patches. Would be confusing to just change it during a non-related change. If you prefer, we can add another patch for that, which would be cleaner.

Ah, got the logs:

Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                                                                                                                                                             [5/1893]
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.            
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                  
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: Could not calculate the required disk size                     
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: INFO: Creating raw disk with size 126M    
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: INFO: Creating raw disk with size 126M                               Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: [OK] Image file created
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: INFO: Creating partitions                                            Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: [OK] Partitions created
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: losetup: cannot find an unused loop device                           Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: Error: Could not stat device  - No such file or directory.
Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: File p1 is not a block device                                 Mar 23 13:10:40 worker-0 rpm-ostree(kata-osbuilder.post)[3725365]: ERROR: Could not setup loop device

I must be confused, but this apparently used to be invoked, and now is not. I don't understand why. The log you shared shows errors that are not obviously related to this. Are they errors of the service starting, or logs of that build step.

If we don't generate the service, how does the image even get created? I thought the whole point of the service was to generate the image on read-only systems like CoreOS.

With the explanations given on IRC, I think that I understand now. Merging.

Pull-Request has been merged by ddd

4 years ago

IRC discussion for the record:
crobinso c3d: the service is the only way initrd generation can happen 'automatically' on coreos, so I don't see how we can drop it. or am I misunderstanding? 16:58
c3d That is precisely the question. 16:59
c3d But fidencio, IIUC, seems to point out that the service is failing anyway 16:59
c3d fidencio: Hope I understood what you meant correctly 16:59
c3d If that's the case, we should fix the service, not suppress it 16:59
crobinso c3d: yeah the service was busted. but where is it being suppressed? 17:00
fidencio c3d: crobinso: we cannot run the service during the %post, as the %post is executed inside a "chroot", right? 17:00
fidencio so, the service will be installed and after you reboot you'll be able to generate the images as expected 17:00
fidencio by having the service enabled / activated by systemd 17:01
fidencio anyways, I'll reply to the bug 17:01
crobinso fidencio: right. %post is not an option on coreos. so host needs a reboot, and service will be generated images on boot up. (when fedora-release package is sufficiently up to date to allow the service to be enabled by default) 17:01
fidencio c3d: ^ and that's exactly what my patch does, removes the %post part on coreos 17:02
crobinso that's the theory. I haven't successfully tested this on coreos. my attempts at testing were hitting issues weeks back that were unrelated to kata though. 17:02
c3d OK: Understood now. I'll consider that good, then 17:02
fidencio crobinso: I did test that on CreOS 17:02
dgilbert c3d: I passed the aarch stuff onto drjones and qemu's stsquad 17:02
c3d dgilbert: Good call 17:02
fidencio c3d: so, I won't reply to the issue :-) 17:03
crobinso fidencio: ah that's right, I recall now. 17:03
fidencio crobinso: I tested on CoreOS Yesterday and then ended up with the patch for upstream osbuilder + the changes on kata-osbuilder package 17:03
fidencio c3d: also, about the macros, don't take my commit as "let's avoid using them", please. just take my commit as "let's avoid using them now and let's use them all across the kata-* packages soon"