Skip to content

Building CloudStack

linuxonz edited this page Jan 23, 2025 · 5 revisions

Building Apache CloudStack

The instructions provided below specify the steps to build Apache CloudStack version 4.19.1.1 on Linux on IBM Z for the following distributions:

  • RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
  • SLES 15 SP6
  • Ubuntu (20.04, 22.04, 24.04, 24.10)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

We currently support only KVM hypervisor on Apache CloudStack for Linux on IBM Z.

Note: Apache CloudStack(4.19.1.1) was verified with management-server, agent, UI and KVM(4.18.0-553.22.1) at the time of creation of these instructions.

1. Build using script

If you want to build Apache CloudStack using manual steps, go to STEP 2.

Use the following commands to build Apache CloudStack using the build script. Please make sure you have wget installed.

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/CloudStack/4.19.1.1/build_cloudstack.sh

# Build Apache CloudStack
bash build_cloudsatck.sh [The script will use the distro provided Python version (i.e., Python 3.6.8 on RHEL 8.10 and Python 3.10 on RHEL 9).]

In case of error, check logs for more details or go to STEP 2 to follow manual build steps.

2. Install Dependencies

export SOURCE_ROOT=/<source_root>/
export PYTHON2_VERSION=2.7.18
export NVM_DIR="$SOURCE_ROOT/.nvm"
export ARCH="s390x"
export PACKAGE_VERSION="4.19.1.1"
export PATCH_URL="https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/CloudStack/${PACKAGE_VERSION}/patch"

2.1. Install Basic Dependencies

  • RHEL
    sudo yum groupinstall -y "Development Tools"
    sudo yum install -y git python3 python3-pip java-11-openjdk-devel maven genisoimage mysql mysql-server createrepo \
    nfs-utils qemu-img ipmitool python3-devel python3-libvirt libvirt perl qemu-kvm \
    rng-tools dhcp-server httpd syslinux-tftpboot tftp-server libffi-devel ant curl chkconfig
    
  • SLES
    zypper -n install sudo wget git java-11-openjdk-devel ant ant-junit python3-libvirt-python libvirt selinux-tools dhcp-server qemu-img qemu-kvm dhcp \
        python3 python2 ipmitool python3-pip unzip cryptsetup ethtool ipset python3-setuptools mkisofs tftp mariadb mysql httpd qemu-tools timezone-java nfs-utils libffi-devel libopenssl-devel rpm-build python3-devel
    
  • Ubuntu
    sudo apt-get install -y dpkg-dev debhelper openjdk-11-jdk genisoimage build-essential python3 python3-setuptools python3-mysql.connector \
        maven ant libjna-java nodejs npm mysql-client augeas-tools mysql-client qemu-utils rng-tools python3-dnspython qemu-kvm libvirt-daemon-system \
        ebtables vlan ipset python3-libvirt ethtool iptables cpu-checker libffi-dev
    

2.2. Install Python2 (Ubuntu 24.x)

curl -O https://www.python.org/ftp/python/${PYTHON2_VERSION}/Python-${PYTHON2_VERSION}.tgz
sudo tar -xvf Python-${PYTHON2_VERSION}.tgz
cd Python-${PYTHON2_VERSION} || exit
sudo bash configure && sudo make && sudo make install
cd ..
sudo rm /usr/local/bin/python
sudo ln -s /usr/bin/python3 /usr/local/bin/python
sudo apt-get install -y python3-pip |& tee -a "$LOG_FILE"

2.3. Install Nodejs

  • RHEL , Ubuntu (20.04, 22.04)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash

[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Install and use Node.js version 12
nvm install 12
nvm use 12
  • SLES, Ubuntu 24.x
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash

[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Install and use Node.js version 10
nvm install 10
nvm use 10

2.4. Install Java

  • RHEL
    sudo yum -y install java-11-openjdk java-11-openjdk-devel
    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
    export PATH="${JAVA_HOME}/bin:${PATH}"
    
  • SLES
    sudo zypper -y install java-11-openjdk java-11-openjdk-devel
    export JAVA_HOME=/usr/lib64/jvm/java-11-openjdk
    export PATH="${JAVA_HOME}/bin:${PATH}"
    
  • Ubuntu
    sudo apt -y install openjdk-11-jdk
    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-s390x
    export PATH="${JAVA_HOME}/bin:${PATH}"
    

2.5. Install Maven

  • RHEL
    sudo yum -y install maven
    
    sudo update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 40
    sudo update-alternatives --set java $JAVA_HOME/bin/java
    sudo update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 40
    sudo update-alternatives --set javac $JAVA_HOME/bin/javac
    
    java -version
    javac -version
    
  • SLES
    wget https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz
    tar -xvzf apache-maven-3.8.8-bin.tar.gz
    sudo mv apache-maven-3.8.8 /opt/maven
    echo -e "\nexport M2_HOME=/opt/maven\nexport MAVEN_HOME=/opt/maven\nexport PATH=\$PATH:\$M2_HOME/bin" | sudo tee -a /etc/environment > /dev/null
    source /etc/environment
    
  • Ubuntu
    sudo apt -y install maven
    
    sudo update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 40
    sudo update-alternatives --set java $JAVA_HOME/bin/java
    
    sudo update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 40
    sudo update-alternatives --set javac $JAVA_HOME/bin/javac
    
    java -version
    javac -version
    

2.6. Build and Install libvirt-java

  • Clone libvirt-java

    mkdir -p /${SOURCE_ROOT}/.m2/repository/org/libvirt/libvirt/0.5.3/
    cd $SOURCE_ROOT
    
    git clone -b v0.5.3 https://github.com/libvirt/libvirt-java.git
    cd libvirt-java
    
  • Only for SLES

    mkdir -p lib && cd lib
    wget -O jna.jar https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.5.0/jna-5.5.0.jar
    wget -O junit.jar https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar
    cd ..
    sed -i '0,/\${jar.dir}/s/\${jar.dir}/lib/; 0,/\${jar.dir}/s/\${jar.dir}/lib/' build.xml
    
  • Apply patch and build libvirt-jar

    curl -sSL $PATCH_URL/libvirt_0_5_3_java_s390x.patch | git apply -
    sudo bash autobuild.sh
    
    sudo cp -f target/libvirt-0.5.3.jar /${SOURCE_ROOT}/.m2/repository/org/libvirt/libvirt/0.5.3/
    

3. Installation

3.1. Clone and apply patch

cd $SOURCE_ROOT
git clone -b $PACKAGE_VERSION https://github.com/apache/cloudstack.git
cd cloudstack
curl -sSL $PATCH_URL/master.patch | git apply -

3.2 Modify Build Config

replace_line_in_file() {
    if [[ ! -f "$1" ]]; then
        echo "Error: File '$1' not found!"
        return 1
    fi

    sed -i.bak "/$2/c\\$3" "$1"
    if [[ $? -eq 0 ]]; then
        echo "Line replaced successfully in $1."
        rm -f "$1.bak"
    else
        echo "Error: Failed to replace the line in $1."
    fi
}
  • RHEL 8.x and SLES

    replacement_line='cd ui && sudo rm -rf /${SOURCE_ROOT}/cloudstack/dist/rpmbuild/BUILD/cloudstack-${PACKAGE_VERSION}/ui/node_modules && npm install --force && NODE_OPTIONS="--max-old-space-size=4096" npm run build && cd ..'
    
  • RHEL 9.x

    replacement_line='cd ui && sudo rm -rf /${SOURCE_ROOT}/cloudstack/dist/rpmbuild/BUILD/cloudstack-${PACKAGE_VERSION}/ui/node_modules && npm install --force && NODE_OPTIONS="--max-old-space-size=4096 --openssl-legacy-provider" npm run build && cd ..'
    
  • RHEL, SLES

    replace_line_in_file '${SOURCE_ROOT}/cloudstack/packaging/centos8/cloud.spec' "cd ui && npm install && npm run build && cd .." "$replacement_line"
    replace_line_in_file '${SOURCE_ROOT}/cloudstack/packaging/centos8/cloud.spec' "BuildRequires: nodejs" "#BuildRequires: nodejs"
    
  • Ubuntu

    replacement_line="$(printf '\t')cd ui && npm install --force && NODE_OPTIONS=\"--max-old-space-size=4096\" npm run build && cd .."
    search="Depends: \${misc:Depends}, \${python3:Depends}, genisoimage, nfs-common, python3-pip, python3-distutils \| python3-distutils-extra, python3-netaddr, uuid-runtime"
    
    replace_line_in_file debian/control " nodejs (>= 12), lsb-release, dh-systemd | debhelper (>= 13)" " lsb-release, dh-systemd | debhelper (>= 13)"
    replace_line_in_file debian/control " python (>= 2.7) | python2 (>= 2.7), python3 (>= 3), python-setuptools, python3-setuptools," " python3 (>= 3), python3-setuptools,"
    replace_line_in_file debian/control "$search" "Depends: \${misc:Depends}, \${python3:Depends}, genisoimage, nfs-common, python3-netaddr"
    replace_line_in_file debian/control "Depends: \${misc:Depends}, python3-pip, python3-dev, libffi-dev" "Depends: \${misc:Depends}, libffi-dev"
    replace_line_in_file debian/rules "$(printf '\t')cd ui && npm install && npm run build && cd .." "$replacement_line"
    

3.3. Build and Install

  • RHEL, SLES

    cd ${SOURCE_ROOT}/cloudstack/packaging/
    sudo ./package.sh -d centos8
    cd ${SOURCE_ROOT}/cloudstack/dist/rpmbuild/RPMS/s390x/
    
    • Host Machine
      sudo rpm --nodeps -i cloudstack-common-${PACKAGE_VERSION}-1.${ARCH}.rpm cloudstack-agent-${PACKAGE_VERSION}-1.${ARCH}.rpm
      
    • Management Server
      sudo rpm --nodeps -i cloudstack-common-${PACKAGE_VERSION}-1.${ARCH}.rpm cloudstack-management-${PACKAGE_VERSION}-1.${ARCH}.rpm cloudstack-ui-${PACKAGE_VERSION}-1.${ARCH}.rpm cloudstack-usage-${PACKAGE_VERSION}-1.${ARCH}.rpm
      
  • Ubuntu

    # Ubuntu-24.04
    nvm exec 10 sudo -E dpkg-buildpackage -d
    # Ubuntu 20.04, 22.04
    nvm exec 12 sudo -E dpkg-buildpackage -d
    
    cd $SOURCE_ROOT
    
    • Host Machine
      sudo dpkg -i ./cloudstack-common_${PACKAGE_VERSION}_all.deb cloudstack-agent_${PACKAGE_VERSION}_all.deb
      
    • Management Server
      sudo dpkg -i ./cloudstack-common_${PACKAGE_VERSION}_all.deb ./cloudstack-management_${PACKAGE_VERSION}_all.deb ./cloudstack-ui_${PACKAGE_VERSION}_all.deb ./cloudstack-usage_${PACKAGE_VERSION}_all.deb
      

Note: Apache CloudStack build is resource intensive and will take time to build

4. Verification (optional)

  • RHEL, SLES
    version=$(echo "$(rpm -qa cloudstack-agent*)" | grep -oP '\d+\.\d+\.\d+\.\d+')
    if [ "$version" == "${PACKAGE_VERSION}" ]; then
        printf -- "CloudStack ${version} Successfully Installed .\n"
    fi
    
  • Ubuntu
    installed_version=$(dpkg -l | grep cloudstack-agent)
    version=$(echo "$installed_version" | grep -oP '\d+\.\d+\.\d+\.\d+')
    if [ "$version" == "${PACKAGE_VERSION}" ]; then
        printf -- "CloudStack ${version} Successfully Installed .\n"
    fi
    

Notes:

  • Follow this quick installation guide for setup
  • Make sure sql server is setup before installation of cloudstack-management
  • Once installed check status of cloudstack-management using systemctl status cloudstack-management
  • Verify UI on <management-server-ip:8080> login and add Host Machine in Hosts

5. SystemVM Image Setup

5.1. Create a VM on KVM Hypervisor

# Create disk image
cd $SOURCE_ROOT
qemu-img create -f qcow2 <systemvm-image-name.img> 20G

# wget -q https://cdimage.debian.org/mirror/cdimage/archive/11.10.0/s390x/iso-cd/debian-11.10.0-s390x-netinst.iso 
wget -q <s390x-based-image.iso>

virt-install --name=<systemvm-template-name> --ram=2048 --vcpus=2 --disk path=<systemvm-image-name.img>,size=20 --os-type=linux --os-variant=<os-variant> --network bridge=<bridge-name> --console pty,target_type=serial --location <s390x-based-image.iso> --import

5.2. Copy Tools and SystemVM

virsh console <systemvm-template-name>
# login as root
scp -r <user>@<host-ip>:/path-to-cloudstack-repo-home/tools .
scp -r <user>@<host-ip>:/path-to-cloudstack-repo-home/systemvm .

5.3. Configure SystemVM

cd tools/appliance/systemvmtemplate/scripts
chmod +x build_s390x_systemvm.sh
./build_s390x_systemvm.sh

5.4. Convert Image

virsh shutdowm <systemvm-template-name>
cd <image-path>
qemu-img convert -O qcow2 <systemvm-image-name.img> /<output-path>/<systemvm-template-name.qcow2>

Notes:

  • Output .qcow2 file is system vm template for s390x and can be registered on CloudStack UI > Images > Templates
  • Follow the steps mentioned under KVM in this link to configure this template as default systemvm template
  • For creating Guest Templates go through this link

6. Cleanup

rm -rf $SOURCE_ROOT/libvirt-java $SOURCE_ROOT/rpmbuild

References:

Clone this wiki locally