Issues in installing NVIDIA 390/396 driver on Ubuntu 18.04

Met some strange problems when following this instruction to install NVIDIA-396 driver on Ubuntu 18.04 (kernel 4.15.0-33-generic x86_64). It tells the driver is successfully installed. But when I run:

nvidia-smi

to check the status. It tells me:

NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

Tried another command:

lsmod | grep nvidia

Nothing is printed out. Definitely, something is wrong. I remove the installed drivers using:

sudo apt remove –purge *nvidia*

Rerun the installation command:

sudo ubuntu-drivers autoinstall

Finally, I found in the log that the installation encountered an error building event :

Error! Bad return status for module build on kernel: 4.15.0-33-generic (x86_64)

Apt suggests to check the make file /var/lib/dkms/nvidia/396.54/build/make.log for details. The tail 300 lines of this file is as follows:

cc -Wp,-MD,/var/lib/dkms/nvidia/396.54/build/nvidia/.nv-frontend.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-linux -gnu/4.8/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arc h/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -Iubuntu /include -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wch ar -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2 -mno-3 dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mtune =generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNA L_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno- asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -DRETPOLINE -fno-delete-null-po inter-checks -O2 -Wno-maybe-uninitialized –param=allow-store-data-races=0 -DCC_HAVE_ASM_GOTO -Wframe-larger-than=10 24 -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -pg -I/var/lib/dkms/nvidia/396.54/bu ild/common/inc -I/var/lib/dkms/nvidia/396.54/build -Wall -MD -Wno-cast-qual -Wno-error -Wno-format-extra-args -D__KE RNEL__ -DMODULE -DNVRM -DNV_VERSION_STRING=\”396.54\” -Wno-unused-function -Wuninitialized -fno-strict-aliasing -mno -red-zone -mcmodel=kernel -DNV_UVM_ENABLE -I/var/lib/dkms/nvidia/396.54/build/nvidia -DNV_BUILD_MODULE_INSTANCES=0 – DNVIDIA_UNDEF_LEGACY_BIT_MACROS -UDEBUG -U_DEBUG -DNDEBUG -DMODULE -DKBUILD_BASENAME='”nv_frontend”‘ -DKBUILD_MOD NAME='”nvidia”‘ -c -o /var/lib/dkms/nvidia/396.54/build/nvidia/nv-frontend.o /var/lib/dkms/nvidia/396.54/build/nvidi a/nv-frontend.c
cc -Wp,-MD,/var/lib/dkms/nvidia/396.54/build/nvidia/.nv-instance.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-linux -gnu/4.8/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arc h/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -Iubuntu /include -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wch ar -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2 -mno-3 dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mtune =generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNA L_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno- asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -DRETPOLINE -fno-delete-null-po inter-checks -O2 -Wno-maybe-uninitialized –param=allow-store-data-races=0 -DCC_HAVE_ASM_GOTO -Wframe-larger-than=10 24 -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -pg -I/var/lib/dkms/nvidia/396.54/bu ild/common/inc -I/var/lib/dkms/nvidia/396.54/build -Wall -MD -Wno-cast-qual -Wno-error -Wno-format-extra-args -D__KE RNEL__ -DMODULE -DNVRM -DNV_VERSION_STRING=\”396.54\” -Wno-unused-function -Wuninitialized -fno-strict-aliasing -mno -red-zone -mcmodel=kernel -DNV_UVM_ENABLE -I/var/lib/dkms/nvidia/396.54/build/nvidia -DNV_BUILD_MODULE_INSTANCES=0 – DNVIDIA_UNDEF_LEGACY_BIT_MACROS -UDEBUG -U_DEBUG -DNDEBUG -DMODULE -DKBUILD_BASENAME='”nv_instance”‘ -DKBUILD_MOD NAME='”nvidia”‘ -c -o /var/lib/dkms/nvidia/396.54/build/nvidia/nv-instance.o /var/lib/dkms/nvidia/396.54/build/nvidi a/nv-instance.c
cc: error: unrecognized command line option ‘-fstack-protector-strong’
scripts/Makefile.build:332: recipe for target ‘/var/lib/dkms/nvidia/396.54/build/nvidia/nv-frontend.o’ failed
make[2]: *** [/var/lib/dkms/nvidia/396.54/build/nvidia/nv-frontend.o] Error 1
make[2]: *** Waiting for unfinished jobs….
cc -Wp,-MD,/var/lib/dkms/nvidia/396.54/build/nvidia/.nv.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/ include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/inc lude/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -Iubuntu/include -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -Werro r-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno -avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG _AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchron ous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -DRETPOLINE -fno-delete-null-pointer-che cks -O2 -Wno-maybe-uninitialized –param=allow-store-data-races=0 -DCC_HAVE_ASM_GOTO -Wframe-larger-than=1024 -fstac k-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -pg -I/var/lib/dkms/nvidia/396.54/build/commo n/inc -I/var/lib/dkms/nvidia/396.54/build -Wall -MD -Wno-cast-qual -Wno-error -Wno-format-extra-args -D__KERNEL__ -D MODULE -DNVRM -DNV_VERSION_STRING=\”396.54\” -Wno-unused-function -Wuninitialized -fno-strict-aliasing -mno-red-zone -mcmodel=kernel -DNV_UVM_ENABLE -I/var/lib/dkms/nvidia/396.54/build/nvidia -DNV_BUILD_MODULE_INSTANCES=0 -DNVIDIA_U NDEF_LEGACY_BIT_MACROS -UDEBUG -U_DEBUG -DNDEBUG -DMODULE -DKBUILD_BASENAME='”nv”‘ -DKBUILD_MODNAME='”nvidia”‘ -c -o /var/lib/dkms/nvidia/396.54/build/nvidia/nv.o /var/lib/dkms/nvidia/396.54/build/nvidia/nv.c
cc: error: unrecognized command line option ‘-fstack-protector-strong’
scripts/Makefile.build:332: recipe for target ‘/var/lib/dkms/nvidia/396.54/build/nvidia/nv-instance.o’ failed
make[2]: *** [/var/lib/dkms/nvidia/396.54/build/nvidia/nv-instance.o] Error 1
cc: error: unrecognized command line option ‘-fstack-protector-strong’
scripts/Makefile.build:332: recipe for target ‘/var/lib/dkms/nvidia/396.54/build/nvidia/nv.o’ failed
make[2]: *** [/var/lib/dkms/nvidia/396.54/build/nvidia/nv.o] Error 1
Makefile:1552: recipe for target ‘_module_/var/lib/dkms/nvidia/396.54/build’ failed
make[1]: *** [_module_/var/lib/dkms/nvidia/396.54/build] Error 2
make[1]: Leaving directory ‘/usr/src/linux-headers-4.15.0-33-generic’
Makefile:79: recipe for target ‘modules’ failed
make: *** [modules] Error 2

What is “‘-fstack-protector-strong’“? My instinct tells me it is related to the gcc or g++. After searching in Google, I decide to upgrade the current gcc/g++ from 4.8 to 4.9. Since 4.9 is not available in Ubuntu 18.04 repository yet, I temporarily add the 16.04 repository to the apt source list.

First, add xenial to /etc/apt/sources.list temporarily : sudo gedit /etc/apt/sources.list

deb http://dk.archive.ubuntu.com/ubuntu/ xenial main
deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe

and do sudo apt update && sudo apt install g++-4.9See stackflow for details.

Remember to remove the xenial from the sources.list after the installation is done.

Then, remove the old NVIDIA driver

sudo apt remove –purge *nvidia*

and re-install it.

sudo ubuntu-drivers autoinstall

Everything looks fine. Try nvidia-smi, the output is correct this time:

WeChat Screenshot_20180823122141

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s