Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save orodbhen/0833374f11c6cb820f46156f567914e8 to your computer and use it in GitHub Desktop.
Save orodbhen/0833374f11c6cb820f46156f567914e8 to your computer and use it in GitHub Desktop.
Create a rootfs tar archive for a CentOS 8.0 container (i.e. docker) base image

I needed a CentOS 8.0 image, and there isn't one on Dockerhub, so I had to create one myself.

The official instructions for creating CentOS container images Uses a kickstart file and a CentOS boot image with the livemedia-creator tool to generate a rootfs tar archive. This can then be passed to docker import to create the image.

However, because using the boot image requires running qemu, and I didn't have a physical Linux host, I used these alternative instructions to create the tar archive, with some modifications.

I modified the kickstart to use the 8.0 repos at http://vault.centos.org, and copied it into a VirtualBox VM, created from the 8.0 boot image. I then did the following inside the VM:

  • Disabled selinux and firewalld
  • Installed lorax and anaconda-tui with dnf, which are dependencies for running livemedia-creator in no-virt mode.
  • Hard-coded the baseurl in the BaseOS, AppStreams, and Extras, repo files, in /etc/yum.repos.d, to use the 8.0 packages from vault.centos.org. Just to keep the package DB consistent with 8.0. But I wanted the latest version of Lorax, so I installed that first.
  • Installed tar with dnf
  • Rebooted the VM, just to be safe

Then I logged back into the VM as the root user, and ran:

 livemedia-creator --no-virt --make-tar --ks centos-8-0.ks --image-name=rootfs_centos_8.0.1905.tar.xz --project "CentOS 8 Docker" --releasever "8"

On the first try, it reached the post install phase of the kickstart, and then raised these errors:

2020-05-21 15:14:57,278: Running post-installation scripts
2020-05-21 15:14:57,341: .
2020-05-21 15:14:57,341: Storing configuration files and kickstarts
2020-05-21 15:14:57,342: .
2020-05-21 15:14:57,812: Error in atexit._run_exitfuncs:
2020-05-21 15:14:57,812: Traceback (most recent call last):
2020-05-21 15:14:57,812: File "/usr/lib/python3.6/site-packages/blivet/threads.py", line 53, in run_with_lock
2020-05-21 15:14:57,812: return m(*args, **kwargs)
2020-05-21 15:14:57,813: File "/usr/lib64/python3.6/site-packages/pyanaconda/storage/osinstall.py", line 2063, in umount_filesystems
2020-05-21 15:14:57,813: self.fsset.umount_filesystems(swapoff=swapoff)
2020-05-21 15:14:57,813: File "/usr/lib64/python3.6/site-packages/pyanaconda/storage/osinstall.py", line 776, in umount_filesystems
2020-05-21 15:14:57,813: device.format.teardown()
2020-05-21 15:14:57,813: File "/usr/lib/python3.6/site-packages/blivet/threads.py", line 53, in run_with_lock
2020-05-21 15:14:57,813: return m(*args, **kwargs)
2020-05-21 15:14:57,813: File "/usr/lib/python3.6/site-packages/blivet/formats/__init__.py", line 649, in teardown
2020-05-21 15:14:57,813: self._teardown(**kwargs)
2020-05-21 15:14:57,813: File "/usr/lib/python3.6/site-packages/blivet/threads.py", line 53, in run_with_lock
2020-05-21 15:14:57,813: return m(*args, **kwargs)
2020-05-21 15:14:57,814: File "/usr/lib/python3.6/site-packages/blivet/formats/fs.py", line 611, in _teardown
2020-05-21 15:14:57,814: raise FSError("umount of %s failed (%d)" % (mountpoint, rc))
2020-05-21 15:14:57,814: blivet.errors.FSError: umount of /mnt/sysimage/run failed (32)
2020-05-21 15:14:57,942: Running setfiles on install tree failed: [Errno 2] No such file or directory: 'setfiles': 'setfiles'
2020-05-21 15:14:57,942: Shutting down log processing
xz: (stdin): Cannot allocate memory
tar: .: file changed as we read it
tar: ./dev: Cannot stat: No such file or directory
tar: ./proc: Cannot stat: No such file or directory
tar: ./run/cryptsetup: Cannot stat: No such file or directory
tar: ./run/lock: Cannot stat: No such file or directory
tar: ./run/lock/subsys: Cannot stat: No such file or directory
tar: ./run/setrans: Cannot stat: No such file or directory
tar: ./run/console: Cannot stat: No such file or directory
tar: ./run/faillock: Cannot stat: No such file or directory
tar: ./run/sepermit: file changed as we read it
tar: ./run/nologin: Cannot stat: No such file or directory
tar: ./run/systemd/ask-password: Warning: Cannot file_has_acl_at: No such file or directory
tar: ./run/systemd/seats: Cannot stat: No such file or directory
tar: ./run/systemd/sessions: Cannot stat: No such file or directory
tar: ./run/systemd/users: file changed as we read it
tar: ./run/systemd/machines: Cannot stat: No such file or directory
tar: ./run/systemd/shutdown: file changed as we read it
tar: ./run/log: Warning: Cannot file_has_acl_at: No such file or directory
tar: ./sys: Cannot stat: No such file or directory
tar: ./root/.bash_logout: Cannot stat: No such file or directory
tar: ./root/.bash_profile: Cannot stat: No such file or directory
2020-05-21 15:14:58,348: Install failed: novirt_install mktar failed: rc=1
2020-05-21 15:14:58,349: Removing bad disk image
2020-05-21 15:14:58,349: ERROR: Image creation failed: novirt_install mktar failed: rc=1
2020-05-21 15:14:58,349: Image creation failed: novirt_install mktar failed: rc=1

The files it said it couldn't find at the end varied each time I tried it. It turned out the setupfiles error message is just a red herring, as can be seen from the lorax source code. As is the blivet exception about not being able to unmount /mnt/sysimage/run, which didn't seem to exist.

The important error was this one: xz: (stdin): Cannot allocate memory.

I had given the VM 2G of memory, which I thought would be more than enough for what I was trying to do. But it seemed that tar data was being piped to xz via stdin, and running out of memory.

The VM had no swap partition, so I created a 4G swap file, and tried again. This time it succeeded, with:

2020-05-22 08:19:02,940: Performing post-installation setup tasks
2020-05-22 08:19:02,953: .
2020-05-22 08:19:02,954:
2020-05-22 08:19:02,954: Configuring installed system
2020-05-22 08:19:03,247: ..........
2020-05-22 08:19:03,247: Creating users
2020-05-22 08:19:03,247: ....
2020-05-22 08:19:03,247: Configuring addons
2020-05-22 08:19:03,250: .
2020-05-22 08:19:03,250: Generating initramfs
2020-05-22 08:19:03,356: .
2020-05-22 08:19:03,357: Running post-installation scripts
2020-05-22 08:19:03,420: .
2020-05-22 08:19:03,420: Storing configuration files and kickstarts
2020-05-22 08:19:03,420: .
2020-05-22 08:19:03,580: Error in atexit._run_exitfuncs:
2020-05-22 08:19:03,580: Traceback (most recent call last):
2020-05-22 08:19:03,580: File "/usr/lib/python3.6/site-packages/blivet/threads.py", line 53, in run_with_lock
2020-05-22 08:19:03,580: return m(*args, **kwargs)
2020-05-22 08:19:03,580: File "/usr/lib64/python3.6/site-packages/pyanaconda/storage/osinstall.py", line 2063, in umount_filesystems
2020-05-22 08:19:03,580: self.fsset.umount_filesystems(swapoff=swapoff)
2020-05-22 08:19:03,580: File "/usr/lib64/python3.6/site-packages/pyanaconda/storage/osinstall.py", line 776, in umount_filesystems
2020-05-22 08:19:03,580: device.format.teardown()
2020-05-22 08:19:03,581: File "/usr/lib/python3.6/site-packages/blivet/threads.py", line 53, in run_with_lock
2020-05-22 08:19:03,581: return m(*args, **kwargs)
2020-05-22 08:19:03,581: File "/usr/lib/python3.6/site-packages/blivet/formats/__init__.py", line 649, in teardown
2020-05-22 08:19:03,581: self._teardown(**kwargs)
2020-05-22 08:19:03,581: File "/usr/lib/python3.6/site-packages/blivet/threads.py", line 53, in run_with_lock
2020-05-22 08:19:03,581: return m(*args, **kwargs)
2020-05-22 08:19:03,581: File "/usr/lib/python3.6/site-packages/blivet/formats/fs.py", line 611, in _teardown
2020-05-22 08:19:03,581: raise FSError("umount of %s failed (%d)" % (mountpoint, rc))
2020-05-22 08:19:03,581: blivet.errors.FSError: umount of /mnt/sysimage/run failed (32)
2020-05-22 08:19:03,709: Running setfiles on install tree failed: [Errno 2] No such file or directory: 'setfiles': 'setfiles'
2020-05-22 08:19:03,709: Shutting down log processing

2020-05-22 08:20:26,140: Disk Image install successful
2020-05-22 08:20:26,145: SUMMARY
2020-05-22 08:20:26,145: -------
2020-05-22 08:20:26,145: Logs are in /root
2020-05-22 08:20:26,145: Disk image is at /var/tmp/rootfs_centos_8.0.1905.tar.xz
2020-05-22 08:20:26,145: Results are in /var/tmp

Then I copied the rootfs archive over to another VM with docker installed, and created the image with:

docker import rootfs_centos_8.0.1905.tar.xz centos:8.0.1905
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment