How to build the Photon OS ISO file - dcasota/photonos-scripts GitHub Wiki

  1. Prerequisites

    • cpu power e.g. Intel i9
    • 32GB ram and more
    • free disk space e.g. 120GB
  2. Prepare the builder environment

    • Builder environment
      • supported virtual environment: VMware Workstation, VMware ESXi and more
      • technical possible and tested: WSL2, baremetal, Azure VM GenV2
    • Builder os
      • Photon OS 3,4,5,6
      • Ubuntu
  3. preparation

    Login as root.

    swapfile

    # The build process of llvm-15 fails because of a ninja-15.0.7-4.ph5 fails with 'collect2: fatal error: ld terminated with signal 9 [Killed]'
    # Accordingly to https://stackoverflow.com/questions/46259776/collect2-fatal-error-ld-terminated-with-signal-9-killed this still is a
    # not-enough-ram issue. I've added a swapfile of 32gb.
    
    # Check if running as root
    if [ $EUID -ne 0 ](/dcasota/photonos-scripts/wiki/-$EUID--ne-0-); then
       echo "This script must be run as root" 
       exit 1
    fi
    
    # Define the swapfile entry
    SWAP_ENTRY="/swapfile swap swap defaults 0 0"
    
    # Check if entry already exists in fstab
    if grep -Fx "/swapfile" /etc/fstab; then
        echo "Swap entry already exists in /etc/fstab"
        exit 0
    else
       fallocate -l 32G /swapfile
       dd if=/dev/zero of=/swapfile bs=1024 count=33554432
       chmod 600 /swapfile
       mkswap /swapfile
       swapon /swapfile
    
       # Backup fstab before modifying
       cp /etc/fstab /etc/fstab.bak
       echo "Created backup of fstab at /etc/fstab.bak"
    
       # Add the swap entry to fstab
       echo "$SWAP_ENTRY" >> /etc/fstab
    
       # Verify the entry was added
       if grep -Fx "$SWAP_ENTRY" /etc/fstab; then
          echo "Swap entry successfully added to /etc/fstab"
          rm /etc/fstab.bak
       else
          echo "Failed to add swap entry to /etc/fstab"
       fi
    fi
    

    Necessary on Photon 3.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 the environment.

    tdnf makecache
    tdnf update tdnf
    tdnf distro-sync -y
    tdnf install -y kpartx git bc build-essential createrepo_c texinfo wget python3-pip tar dosfstools cdrkit rpm-build
    
    # December 31st 2024
    # The build process of llvm uses all ram and creates an out of memory situation.
    # After som research I've found out with respect to https://stackoverflow.com/questions/71992377/building-llvm-eats-up-all-the-ram,
    # that this misbehavior can be avoided by installing clang package before starting the make image process.
    tdnf install -y clang
    
    # January 13th 2025
    # The build process of arm64 linux-esx fails with a warning 'Could not canonicalize hostname'. Hence, install libevent package.
    tdnf install -y libevent
    
    
    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
    cd $HOME
    pip3 install git+https://github.com/vmware/photon-os-installer.git
    
    # download the common release
    git clone -b common https://github.com/vmware/photon.git ./common
    
    # specify the photon os branch
    PHOTON_RELEASE="6.0"
    git clone -b $PHOTON_RELEASE https://github.com/vmware/photon.git ./$PHOTON_RELEASE
    cd ./$PHOTON_RELEASE
    
    # Check if PHOTON_RELEASE is set to "6.0"
    tdnf install -y jq
    if [ "$PHOTON_RELEASE" = "6.0" ]; then
      echo "PHOTON_RELEASE is 6.0, updating build-config.json..."
      jq '.["branch-name"] = "6.0"' build-config.json > temp.json && mv temp.json build-config.json
      echo "Updated branch-name to 6.0 in build-config.json"
    else
      echo "PHOTON_RELEASE is not 6.0, no changes made to build-config.json"
    fi
    
    # new findings June 26th 2024
    sudo python3 -m venv .venv
    source .venv/bin/activate
    sudo pip3 install docker
    sudo pip3 install pyOpenSSL
    
    # new findings December 13th 2024
    PHOTONROOT=~/photon
    cp $PHOTONROOT/SPECS/openjdk/openjdk17.spec $PHOTONROOT/openjdk17.spec.tmp
    sed "s/--disable-warnings-as-errors/--disable-warnings-as-errors --build=x86_64-unknown-linux-gnu/" $PHOTONROOT/openjdk17.spec.tmp > \
    $PHOTONROOT/SPECS/openjdk/openjdk17.spec
    rm $PHOTONROOT/openjdk17.spec.tmp
    
    # new findings January 31st 2025
    PHOTONROOT=~/photon
    cp $PHOTONROOT/SPECS/openjdk/openjdk21.spec $PHOTONROOT/openjdk21.spec.tmp
    sed "s/--disable-warnings-as-errors/--disable-warnings-as-errors --build=x86_64-unknown-linux-gnu/" $PHOTONROOT/openjdk21.spec.tmp > \
    $PHOTONROOT/SPECS/openjdk/openjdk21.spec
    rm $PHOTONROOT/openjdk21.spec.tmp
    
  4. Start make build

    Sometimes the process breaks and can be restarted by a loop to finish a few more packages.
    # January 3rd 2025
    # The build process of nodejs on a system with only 8gb ram stops because of lack of free memory. This can be avoided accordingly to 
    # https://github.com/nodejs/node/issues/45949#issuecomment-1364561543. Add `LINK=flock /tmp $(CXX)` to the make command.
    
    for i in {1..10}; do make -j$((`nproc`-1)) image IMG_NAME=iso LINK=flock /tmp $(CXX) THREADS=$((`nproc`-1)); done
    

Troubleshooting

"Failed during building package"

This occured eg. on 'Building rpm is failed /usr/src/photon/SPECS/kafka.spec'. The workaround is to restart the process with less parallel threads. make -j4 image IMG_NAME=iso THREADS=4

"error: metadata-generation-failed"

This version conflict caused issue occured on pip3 install photon-os-installer.git and ended with error: invalid command 'egg_info'. Try this if not already applied:

python -m pip install --upgrade pip
pip3 install --upgrade pip
pip3 install setuptools ez_setup

error openjdk17 build during make build of Photon OS iso on WSL2

Package build openjdk17-17.0.8 fails when using Photon OS on WSL2 as make build environment. The logfile indicates the reason.

checking for cygpath... [not found]
checking for wslpath... [not found]
checking for cmd.exe... [not found]

Solution or workaround: none Remarks: The root cause hasn't been identified yet. /bin/wslpath is present. Accordingly to the logfile, the installation meccano can detect wsl, but identified the environment as wsl1.

update sources

To update the source e.g. Photon OS 4.0, run the following commands:

cd /photon
git fetch
git merge origin/4.0

Post-Installation issues