Skip to content

Instantly share code, notes, and snippets.

Created Mar 27, 2021
What would you like to do?
Script updated to make it work withROCm 4.1.x for Ubuntu 20.04 (tested with kernel 5.8.0-48). See context for older version at
# Original by tuxutku (
# Modified by haxpor (based also on older version tha work with ROcm 3.3 at
# This version with following changes
# - support ROCm 4.1.x for Ubuntu 20.04 (tested with kernel 5.8.0-48-generic)
# - improved to not re-download a driver package again unncessary
# - early exit with error if found error
# - refactor misc code
# check if file is already downloaded, then skip re-download
if [ ! -f "${target_file}" ]; then
# AMD website check whether you're from the donwloading page in order to successfully download a target driver file
echo "Downloading archive and extracting"
# download a package then save into a file (file is quite large, better download and save it locally before proceeding
# with extraction later.
wget --header="Referer:" --header="Host:" --header="User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0" --header="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" --header="Accept-Encoding: gzip, deflate, br" -N "${target_file}"
if [[ "$?" -ne 0 ]]; then
echo "Error downloading amdgpu-pro driver package file"
exit 1
# extract the file
tar xJf ${target_file}
if [[ "$?" -ne 0 ]]; then
echo "Error extracting ${target_file}"
exit 1
echo "Extraction complete, creating the files"
mkdir -p "opencl"
cd "opencl"
ar x "${srcdir}/${extracted_dir}/ocl-icd-libopencl1-amdgpu-pro_${major}-${minor}_amd64.deb"
tar xJf data.tar.xz
ar x "${srcdir}/${extracted_dir}/opencl-orca-amdgpu-pro-icd_${major}-${minor}_amd64.deb"
tar xJf data.tar.xz
cd "${shared}"
mkdir -p "${srcdir}/libdrm"
cd "${srcdir}/libdrm"
ar x "${srcdir}/${extracted_dir}/libdrm-amdgpu-amdgpu1_2.4.100-${minor}_amd64.deb"
tar xJf data.tar.xz
# create 'pkgdir'
mkdir -p "${pkgdir}"
# prep content inside pkgdir directory
mv "${srcdir}/opencl/etc" "${pkgdir}/"
mkdir -p ${pkgdir}/usr/lib
mv "${srcdir}/opencl/${shared}/" "${pkgdir}/usr/lib/"
mv "${srcdir}/opencl/${shared}/" "${pkgdir}/usr/lib/"
mv "${srcdir}/libdrm/opt/amdgpu/lib/x86_64-linux-gnu/" "${pkgdir}/usr/lib/"
mv "${srcdir}/libdrm/opt/amdgpu/lib/x86_64-linux-gnu/" "${pkgdir}/usr/lib/"
mkdir -p "${pkgdir}/opt/amdgpu/share/libdrm"
cd "${pkgdir}/opt/amdgpu/share/libdrm"
ln -s /usr/share/libdrm/amdgpu.ids amdgpu.ids
rm -r "${srcdir}/opencl"
rm -r "${srcdir}/libdrm"
cd "${pkgdir}"
echo "Done"
echo "Creating files complete, copying files to root. Enter sudo password when asked"
sudo cp -Rv * / # might need to use rsync instead if your /opt directory is symlinked
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment