vmware / photon

Minimal Linux container host
https://vmware.github.io/photon
Other
3.06k stars 697 forks source link

Building Photon OS 5.0 Iso from source on Ubuntu 22.04 #1519

Closed mwoodpatrick closed 11 months ago

mwoodpatrick commented 1 year ago

Describe the bug

On the page: Building the ISO it documents how to build on Ubuntu and lists the additional packages needed to do the build which includes createrepo unfortunately, createrepo command which can create RPM repositories was removed in Ubuntu 20.04 LTS (see createrepo on Ubuntu 20.04. It would be helpful if the page reflected how to build on the current version of Ubuntu

Reproduction steps

  1. sudo apt-get -y install bison gawk g++ createrepo python-aptdaemon genisoimage texinfo python-requests libfuse-dev libssl-

Expected behavior

Packages are installed

Additional context

dev uuid-dev libreadline-dev kpartx git bc Reading package lists... Done Building dependency tree... Done Reading state information... Done E: Unable to locate package createrepo E: Unable to locate package python-aptdaemon E: Unable to locate package python-requests

dcasota commented 1 year ago

Hi @mwoodpatrick,

No doubt, the docs pages haven't advanced in the past months. As a Photon OS enthusiast, I will add a pull request these next days particularly for this issue.

Photon OS has different flavors. The current docker image version is 10/28/2023. Afaik there are no Ubuntu-like chiseled images for e.g. Java, .NET., etc. using the open-source version of Photon OS.

Meanwhile, as a suggestion, make build a current image directly on Photon OS.

Hope this helps. -Daniel

Make build on Photon OS older than 4.0

if [ `cat /etc/yum.repos.d/photon.repo | grep -o "packages.vmware.com/photon" | wc -l` -eq 0 ]; then
  cd /etc/yum.repos.d/
  sed -i 's/dl.bintray.com\/vmware/packages.vmware.com\/photon\/$releasever/g' photon.repo photon-updates.repo photon-extras.repo photon-debuginfo.repo
fi

Prepare make build

    tdnf install -y kpartx git bc build-essential createrepo_c texinfo wget python3-pip tar dosfstools cdrkit rpm-build
    python -m pip install --upgrade pip
    pip3 install --upgrade pip
    pip3 install setuptools ez_setup
    pip3 install docker==2.3.0
    # use latest photon-os-installer
    pip3 install git+https://github.com/vmware/photon-os-installer.git
    # specify the photon os branch
    git clone -b 5.0 https://github.com/vmware/photon.git
    cd ./photon

Make build

Start make image IMG_NAME=iso.

mwoodpatrick commented 1 year ago

I did manage to get to the point where it tried to install photon-iso-config and syslinux in a working directory that failed for me with since the build could not find the photon-iso-config package. I will dig further tomorrow. This may be because I'm running Ubuntu 22.04 under WSL-2. I did get Photon OS installed as a WSL-2 distribution.

oliverkurth commented 1 year ago

The current documented way of building images is going to be deprecated soon. We are developing a new way using containers. It's already in use for the dev branch, see https://github.com/vmware/photon/tree/dev/support/poi . You can look at https://github.com/vmware/photon-os-installer/tree/poi-container/docker for instructions - but that currently doesn't have instructions to build ISO images (so far only cloud images).

Steps to build an ISO:

Create the container as below or just pull: docker pull projects.registry.vmware.com/photon/installer

This is to create a repository with current 5.0 packages. If you have built Photon packages locally, you need to adjust the paths to use the local RPMS folder instead:

You should now have a new ISO: photon-5.0.iso (or use -n <name> to set another name)

dcasota commented 1 year ago

Hi @oliverkurth,

I have two questions.

I know that Microsoft Windows WSL isn't supported. Did you try to build the ISO outside VMware virtualization? For the new way with containers and considering support for products outside VMware virtualization, this would mean to add docs about configuring Github Workspaces, Docker Dev Environments, etc. See the use cases listed below.

The second question is about tools deprecation for building images. It makes it difficult to contribute with pull requests in good standing. E.g. Broadcom atomic automation and other divisions are keen on publishing 12-18 months roadmaps. Of course, this is open-source Photon OS and not the closed-source commercial version. That said, are there plans for introducing roadmaps? The last update is from 2022.

Kind regards, Daniel

mwoodpatrick commented 1 year ago

I was able to install & build the photon installer package on archlinux/WSL-2 without issue. I could not find the examples/iso directory in the photon-os-installer poi-container branch I only saw

ls examples ami azure ova rpi

@dcasota this is for personal work unrelated to my work at NVidia and in this case I need to use WSL-2

BTW is there a photon community forum (e.g. on slack) I could not find one. I'm looking to buy a Linux mini PC to connect to my laptop that can run headless and use for testing.

oliverkurth commented 1 year ago

I was able to install & build the photon installer package on archlinux/WSL-2 without issue. I could not find the examples/iso directory in the photon-os-installer poi-container branch I only saw

ls examples ami azure ova rpi

Oh sorry, I forgot to merge that into the poi-container branch. I just cherry-picked and pushed it, so just try a pull now and you should get 78756125f6d5f9eae675981164cc0c865e6769ff.

mwoodpatrick commented 1 year ago

That fixed the issue and I was able to build the iso.

mwoodpatrick commented 1 year ago

The link ks_config.md describing kickstart on page:

ks_config.md

appears to be broken, can we get it fixed?

dcasota commented 1 year ago

e.g. createrepo_c at https://github.com/vmware/photon/blob/photon-hugo/content/en/docs-v5/installation-guide/building%20images/build-custom-iso-from-source-code-for-photon-os-installer.md ?

From a double you’s or a double youth perspective, creating comprehensive docs at the level of en/content is a wish.

sshedi commented 12 months ago

How to build createrepo on newer Ubuntu versions?

Here you go:

#!/bin/bash

if [ "$EUID" -ne 0 ]; then
  echo "Should be run as root" 1>&2
  exit 1
fi

echo -e "\n*** WARNING: THIS SCRIPT IS TESTED AND MEANT TO BE USED FOR UBUNTU 20.04 (might work in higer versions) ***\n" 1>&2

if command -v createrepo_c &> /dev/null; then
  echo "Previous createrepo_c installation found, uninstall it and proceed further" 1>&2
  exit 1
fi

topdir="$PWD"
ver="0.20.1"
srcname="createrepo_c-${ver}"
url="https://github.com/rpm-software-management/createrepo_c/archive/refs/tags/$ver.tar.gz"
tarball="$(basename $url)"

pre_reqs=(tar wget libmagic-dev cmake libpopt-dev libbz2-dev libssl-dev)
pre_reqs+=(libcurl4-openssl-dev libxml2-dev libglib2.0-dev python3-dev)
pre_reqs+=(liblzma-dev libsqlite3-dev librpm-dev libzstd-dev make)

if ! dpkg -s ${pre_reqs[@]} &>/dev/null; then
  apt update
  apt install -y ${pre_reqs[@]}
fi

fini() {
  local ret=$?

  cd "$topdir"
  if [ $ret -eq 0 ]; then
    rm -rf "$srcname" "${tarball}"
  else
    rm -rf "$srcname"
  fi

  exit $ret
}

trap fini EXIT

if ! ls "${tarball}" &> /dev/null; then
  wget -nc "$url"
fi

if ! tar xf "${tarball}"; then
  echo "ERROR: failed to extract downloaded tarball" 1>&2
  exit 1
fi

cd "$srcname"

if ! cmake . -DWITH_ZCHUNK=OFF -DWITH_LIBMODULEMD=OFF; then
  echo "ERROR: cmake failed" 1>&2
  exit 1
fi

p="$(nproc)"

make -j$p

make uninstall -j$p
ldconfig

make install -j$p
ldconfig

ln -sv /usr/local/bin/createrepo_c /usr/local/bin/
ln -sv /usr/local/bin/createrepo_c /usr/local/bin/createrepo
mwoodpatrick commented 11 months ago

I'd like to test my generated image using qemu but can't seem to find a qemu command line the boots the generated iso.

When I run:

qemu-system-x86_64 -boot d -m 2G -cdrom my-photon-5.0-x86_64.iso \ -drive if=none,id=sata-disk,file=photon-5.0.qcow2 \ -device ahci,id=ahci \ -device ide-hd,bus=ahci.0,drive=sata-disk

The installer can't seem to find the drive. Anyone have any suggestions as to what I'm doing wrong?

oliverkurth commented 11 months ago

Can you follow the procedure outlined here https://github.com/vmware/photon-os-installer/pull/24 ? With the exception that you can checkout the poi-container branch of that project because that PR has been merged to that branch.

oliverkurth commented 11 months ago

Also, it should be possible to create a Photon image for qemu directly (without an ISO), following the instructions here: https://github.com/vmware/photon-os-installer/tree/poi-container/docker . You just need to convert the raw image file to qcow2 format, which you can do with qemu tools.

oliverkurth commented 11 months ago

The installer can't seem to find the drive. Anyone have any suggestions as to what I'm doing wrong?

I just tried the qemu-system command myself - I think I misunderstood - it's not finding the cdrom, and I thought you mean the hard drive. I think the problem is that qemu emulates an IDE CD drive, and that is no longer support in Photon 5.0. Try using a SATA drive instead. I am not familiar enough with qemu to find the correct options for that.

Alternatively, try testing the image with VMware Fusion/Workstation/Player or KVM.

oliverkurth commented 11 months ago

I figured it out - try this:

qemu-system-x86_64 -drive id=disk,file=photon-5.0.qcow2,if=none -drive id=cdrom,file=photon-5.0.iso,media=cdrom,if=none,read-only=on -device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 -device ide-cd,drive=cdrom,bus=ahci.1 -m 4096
mwoodpatrick commented 11 months ago

Yep that worked, many thanks.

dcasota commented 11 months ago

👏 awesome 😃 Recipe should be added to the docs.

oliverkurth commented 11 months ago

I think we can close this now, questions are answered.