Ubuntu – Freezing of screen on Ubuntu 16.04


I have recently installed Ubuntu 16.04 and it seems to freeze randomly. I tried to check out the the solutions at Ubuntu 15.10 and 16.04 keep freezing randomly but on installing these kernels, I got a kernel panic at boot, so I furthur looked for solutions at Ubuntu 16.04 constantly freezing leading to kernel panic but couldn't figure out how to resolve the problem. Can anyone tell me which exact kernels to install so that both issues (kernel panic and random freezing) is resolved?
The kernel that came preinstalled with 16.04 was 4.4.0-21-generic and these are some extra details:

Distributor ID: Ubuntu
Description:    Ubuntu 16.04 LTS
Release:    16.04
Codename:   xenial
Processor: Intel® Pentium(R) CPU N3540 @ 2.16GHz × 4 
Graphics:  Gallium 0.4 on llvmpipe (LLVM 3.8, 128 bits)
Ram : 4Gb
Os type - 64 bit architecture 

Do tell me if I need to provide any other details.

Edit – 1 )

saisumit@saisumit-Inspiron-3551:~$ sudo dpkg -l | grep  linux-headers-4.7*.deb 
[sudo] password for saisumit: 
saisumit@saisumit-Inspiron-3551:~$ sudo dpkg -l |grep  linux-image-4.7*.deb
saisumit@saisumit-Inspiron-3551:~$ sudo update-grub
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.7.0-040700rc3-generic
Found initrd image: /boot/initrd.img-4.7.0-040700rc3-generic
Found linux image: /boot/vmlinuz-4.4.0-21-generic
Found initrd image: /boot/initrd.img-4.4.0-21-generic
Adding boot menu entry for EFI firmware configuration

I installed using this method

   wget kernel.ubuntu.com/~kernel-ppa/mainline/v4.7-rc3-yakkety/linux-headers-4.7.0-040700rc3_4.7.0-040700rc3.201606121131_all.deb 
    wget kernel.ubuntu.com/~kernel-ppa/mainline/v4.7-rc3-yakkety/linux-headers-4.7.0-040700rc3-generic_4.7.0-040700rc3.201606121131_i386.deb 
    wget kernel.ubuntu.com/~kernel-ppa/mainline/v4.7-rc3-yakkety/linux-image-4.7.0-040700rc3-generic_4.7.0-040700rc3.201606121131_i386.deb
    sudo dpkg -i linux-headers-4.7*.deb linux-image-4.7*.deb

EDIT – 2
( installed grub customizer )

  sudo add-apt-repository ppa:danielrichter2007/grub-customizer
  sudo apt-get update
  sudo apt-get install grub-customizer

Best Answer

Your processor is affected by the c-state bug which causes total freezes when the CPU tries to enter an unsupported sleep state. It's a problem for many Bay Trail devices especially with newer (4.*) kernels.

There is a simple workaround for this until it gets properly fixed upstream. You just need to pass a kernel boot parameter and the random freezing stops completely.

You do this by editing the configuration file for GRUB:

Boot Ubuntu and open a terminal by pressing ctrl+alt+t then type

sudo nano /etc/default/grub

Find the line GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

This needs to be changed to include intel_idle.max_cstate=1

So after your edit it reads

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_idle.max_cstate=1"

If you have other boot parameters already besides quiet and splash, just leave them alone.

Now save the file by pressing ctrl+o then enter and exit by pressing ctrl+x

Now type

sudo update-grub

Then reboot

To revert to an older kernel from a higher version installed manually, reboot the system and enter the GRUB menu by pressing shift. At the GRUB screen select Advanced Options For Ubuntu and select the kernel you want to boot (4.4.0-21-generic in your case)

When the system has booted, before deleting anything check uname -r to be sure you have booted the correct kernel.

The system will boot the highest kernel by default, so you need to delete the newer one yourself. All you need to do is delete the files that relate to it, so find the version string of the kernel you want to delete... if you installed by the debian method:

dpkg -l | grep linux-image

if you installed with make install do ls /boot to see installed kernel versions

Let's say the kernel you want to remove has the release string 4.7.0-040700rc3-generic. You can find all the files relating to this kernel:

sudo updatedb && locate -b -e 4.7.0-040700rc3-generic

to delete them you can use xargs (assuming you've already run sudo updatedb)

locate -b -e 4.7.0-040700rc3-generic | xargs -p sudo rm -r

-p makes xargs ask for confirmation before executing rm -r on the located files. It will throw errors for files which are not directories because you are trying to delete them recursively, but it will still work. Finally run

sudo update-grub