Search This Blog

Sunday, October 25, 2015

How to Install Bumblebee and Latest Nvidia Drivers on Wily Werewolf Ubuntu 15.10


How to Install Bumblebee and Latest Nvidia Drivers on Wily Werewolf Ubuntu 15.10


The procedure for Installing Bumblebee and nvidia drivers on Ubuntu 15.10 is a bit different from what we have been using in the past. Hence the new post.

I have faced issue with using the xorg-edgers ppa and the graphics-drivers ppa together. All works well except after a couple of reboots the Xorg Breaks and I can't recover it no matter what. So I have decided to re-write this post to that my readers are aware of the changes and can enjoy a smooth experiences with Wily Werewolf, Ubuntu 15.10.

I have had my Xorg Crash and become totally not recoverable if I use both the Xorg-Edgers ppa and the Graphics-Drivers ppa.

My recommendation is to use only Graphics-Drivers ppa with Wily Werewolf Ubuntu 15.10

Without further delay, Here it is.

Run the following Commands in Sequence

1) sudo apt-get update && sudo apt-get upgrade

2) sudo apt-get dist-upgrade

3) sudo apt-add-repository ppa:graphics-drivers/ppa

4) sudo apt-get update && sudo apt-get dist-upgrade

5) sudo apt-get install bumblebee bumblebee-nvidia primus nvidia-settings nvidia-355

Once this is Installed, Below files need to be edited as shown.

1) sudo gedit /etc/modules

add

i915
bbswitch

2) sudo gedit /etc/modprobe.d/bumblebee.conf

Check for this

# 355
blacklist nvidia-355
blacklist nvidia-355-updates
blacklist nvidia-experimental-355
# Workaround to make sure nvidia-uvm is removed as well
remove nvidia rmmod nvidia-uvm nvidia

Ensure that this section shown above exists.

3) sudo gedit /etc/bumblebee/bumblebee.conf

replace

nvidia-current
with

nvidia-355 (Or whatever version of Driver is latest as per the Graphics Driver PPA)

Also Change

Driver = nvidia on Line Number 22


7) sudo gpasswd -a $USER bumblebee


8) sudo systemctl enable bumblebeed


9) Reboot

10) Install mesa utils if not already installed

sudo apt-get install mesa-utils

Check using

11) primusrun glxinfo | grep OpenGL

You shoud see a result like this.

primusrun glxinfo | grep OpenGL
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce 820M/PCIe/SSE2
OpenGL core profile version string: 4.4.0 NVIDIA 355.11
OpenGL core profile shading language version string: 4.40 NVIDIA via Cg compiler
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.5.0 NVIDIA 355.11
OpenGL shading language version string: 4.50 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:

This means all is well and  your bumblebee setup is working.

If you would like to see if bumblebee is actually working, try this

lsmod | grep bbswitch

You should see something similar to this

 bbswitch               16384  0
 The number in second column is Random and will vary.

also 

if you run.

cat /proc/acpi/bbswitch


You should see something like this

0000:03:00.0 OFF

This means that your Nvidia Card is OFF by default. Once you run an application using primusrun or optirun commands, while the program you run is running you can see that the OFF change to ON Like below.

primusrun glxgears

this runs the glxgears program using your Nvidia Card via bumblebee.


Open another terminal and run.

cat /proc/acpi/bbswitch

 You should see something like

0000:03:00.0 ON

Now Close the application which you launched via bumblebee earlier, in this Case glxgears.

again run

cat /proc/acpi/bbswitch

You should see something like this.

0000:03:00.0 OFF

If all is going like I have mentioned then you can be sure that bumblebee is configured correctly.

Please leave your feedback in the comments section. 

Thanks for your time!

Wednesday, August 12, 2015

Viruses and Linux


Viruses and Linux


This is a very famous saying and one of the biggest myths around Linux that there are no viruses on Linux. Almost everybody using Linux thinks that they don't need an antivirus. This is not the case though.

In order to understand this we first need to understand what a Virus/worm/trojan etc. Is. In very simple verbiage, anything on your computer that is causing unwanted behavior. Anything that you did not install by our own with complete knowledge an is causing harm. Something that has sneaked into your computer and is performing unwanted operations would fall under the broad term Virus.

A program which is trying to make copies of itself, trying to delete files from your system, trying to monitor your system and sending information to some remote hacker etc... There are many more things that so called Virus/Malware/Adware/Worms/Trojans/rootkits/keyloggers etc... can do. These are specifically engineered pieces of software, designed to stay disguised and remain untraced for the most part, i case of a 0 Day threat and do the activities they were designed to do.

So there is a general purpose definition and then there are more specific definitions of these programs that we classify as Viruses/Malware/Adware/Worms/Trojans/rootkits/keyloggers etc.. Their classification entirely depends on the way they operate and what part of the System they attack. All viruses don't operate in the same way, hence their definitions are different.

Now let us understand what an Anti-virus does?


An antivirus is a Program which is aware of the Operation of these programs, The specific areas of the OS/Application that the viruses target and the way these operate. Like I said, Once viruses are classified based on what they do and how they do, Once could write a signature program for the class and using the Antivirus program, Once could catch these programs by scanning the computer. We however first need to understand and study the Virus and tell the Antivirus program what a Virus looks like. We call these signatures as AV Definitions. These are maintained by the Company making the AV.

Anti-virus software relies on the Virus definitions to stay up to date with new kind of Viruses, These definitions are maintained by the maker of the Anti-virus and are delivered via updates to the Anti-virus program.

The Scan Engine on the Anti-Virus program is specially designed to read files on the system and even the memory some times and compare them against the know virus signatures and  alert the user, The user can then choose to delete the files or clean them of the hidden viruses if possible.


The are are hundreds of viruses being designed every day. Each with different purpose. Antivirus software is getting smarter and so are the Virus writers.

As we all know that Microsoft Windows is the biggest target of these so called Virus Writers, But do we know for sure that Viruses are not being written for Linux? Or if you are using Linux there are no Chances of getting virus infections on your computer?

Well this is a bit complicated to answer so let me try to break it down for you.

Since Windows has the largest user base in entire PC market, It is obvious that it is the most targeted platform. Linux on the desktop has a very small to negligible footprint in comparison with Windows. So there are very less attacks/viruses.

There are however viruses for Linux as well but not too many.

For example I scanned my Laptop today and I got this


rajat@trusty:/tmp/sophos-av$ sudo savscan /
SAVScan virus detection utility
Version 5.12.0 [Linux/AMD64]
Virus data version 5.15, May 2015
Includes detection for 9239070 viruses, Trojans and worms
Copyright (c) 1989-2015 Sophos Limited. All rights reserved.

System time 10:15:17 IST, System date 13 August 2015

Quick Scanning

Could not open /run/user/1000/gvfs
Could not open /usr/share/doc/python-pyexiv2-doc/_static/jquery.js
>>> Virus 'Andr/DroidRt-M' found in file /home/rajat/XXX/XXXX/XXXXX motochopper BY djrbliss on droidrzr.com/motochopper/pwn

114411 files scanned in 25 minutes and 24 seconds.
4 errors were encountered.
1 virus was discovered.
1 file out of 114411 was infected.
If you need further advice regarding any detections please visit our
Threat Center at: http://www.sophos.com/en-us/threat-center.aspx
2 encrypted files were not checked.

This is a virus that affects android OS. Which is technically Linux.

A virus can be written for any platform or any application, It is just that there are not too many for Linux yet. Linux on the Desktop is not popular enough to gain traction from Virus writers to write viruses for. As you see there was only One Virus found in the total scan.

Linux is inherently secure. It is very difficult to write a virus that affects Linux seriously. The Shellshock and Heartbleed bugs were vulnerabilities in the Bash and Openssl Programs which were fixed quickly. There has not been any virus that could kill your machine, because Linux is secure by design.

There could be viruses written even for Linux that could do some really nasty things, Most of these would leverage vulnerabilities in the Applications installed and not in the Linux Kernel itself or may be they could. I don't know. However as of now Linux is not affected by many viruses.

So what I am saying is that it is a Myth that you don't get viruses when you are on Linux. You do, you don't have too many of them affecting Linux. A file that may seem totally harmless on your Linux Machine may cause havoc on some other platforms because it had a virus which did not affect you because you were on Linux and it literally killed some one's machine because they were using an alternate OS and did not have their Anti-virus software catch it in time.

We all should be aware that Viruses are possible for Linux,or for any OS for that matter, It is just that Writing Virus for Linux is a pain, and a totally no profit job, especially on the Desktop Side of things.

So Please consider installing an Anti-virus software like Clam AV, Sophos Commodo etc.. which are free and provide at least basic protection on Linux.

Thanks for reading.

Tuesday, August 11, 2015

How to stop distro hopping?!


How to stop distro hopping?!


This is the million dollar question. There are many Linux users out there who have a habit of installing a new Linux distribution on their machines just to check out the new stuff. This is very good if you are new to Linux and are trying to get yourself comfortable with Linux. Many people just like to tinker with their systems so they switch Linux Distributions often. Since Linux gives you the freedom you deserve, you are free to use whatever you want, and modify anything about your system.

Switching to a new Linux distribution for some really genuine reason is great. For example you wanted the latest version of a software and you can't get get it in the repos of your current Distro nor could you find any third party repo for your software. You are not able to compile it as well since its dependencies are too many to rebuild you would rather rebuild the whole system. In this case switching to a new distro where things are better would make sense. I appreciate this kind of distro hop. I have done it in the beginning and so did most of us.

Distro hopping is not a problem in the start of your journey in the Linux world. It is just a way to find the best Option for you. There are however times when people would switch distributions just because they feel to. Or they feel something is not working in the current distro and they came to know from somewhere that things would be better if they used a different distro.

Distro hopping can be frustrating at times when you find out that the very reason you switched from your earlier distro is still there. You can't get rid of the issues even with the new distribution, or may be your perception of the new Distro was actually not true. There is really not much difference between your current Distro, and found this only after spend a good couple of hours installing and setting things up for yourself with this new distro.

Many times because things did not fix by distro hopping, many people begin thinking as to whether they should be using Linux in the first place. The reasons behind distro hopping are always justified by the user, mostly because they are not able to do their work because of an issue and their perception that distro hopping is the only solution is the motivating force behind this behaviour. If distro hopping does not solve the issues or causes new issues but resolves the old ones This kind of forms a vicious circle and the end result is frustration.I am saying this from personal experience. There were times when I almost lost hope and wanted to go back to using Windows which I had already paid for while buying the hardware.

I have been using Linux since past 5 years. I have seen Linux on the desktop evolve to what it is now. I have been distrohopping all along these years. I have been mostly attracted by the urge to use new software and then Try different desktop environments.. I have used almost all the top 50 distributions on distrowatch. I liked one thing or the other from each of these distributions. It took me time to understand the philosophy behind each distro and then to realize the same while using them on a day to day basis.

I have finally settled down with Ubuntu 14.04.3 LTS. Because of practical implications. It is stable and will be supported for a long time. I have no pressing need for getting the latest and greatest of all software I use. Most of my favourite software are on their most recent versions via 3rd party PPAs. Overall the System is stable and I love Unity Desktop Environment.

So How did I stop distro hopping?


My distro hopping was literally becoming my only OCD. I could' not stop thinking about how other Linux distros are better than my existing one. No matter I what distro I was using I always felt there was something better out there. I always thought I cloud do better with a different Desktop Environment and different Distribution.

I would format my Laptop almost every week. This happened for around 1 year. Over this period of time, my brain kept filtering the thoughts behind distro hoping. I was able to think only in terms of two distributions in the end. Ubuntu based and Arch Based.

I love Arch Linux and Ubuntu 14.04 LTS, I have been hopping from one to another over the past year. I must say both have their strengths and weaknesses. I don't want to compare both however I want to lay down a few points which could help you stop hopping distros.

Here is how this worked in my case

-- Since you have been distro hopping already for some time you should be able to write down the top reasons for switching from the current distro.

-- Then you should be able to figure out top reasons for switching to the new distro.

-- You should know your favourite Desktop Environment, In my case I like Unity and KDE.

-- You should know how comfortable you are around adding and removing software from a system. I mean whether or not you are more than a new Linux user. Do you understand the inner working of the distribution you are on currently and the new one you plan to switch to .

--Do you know your way around the System, package management etc.

--Does your current distro have all software you need in their repos, or is it easy to get a third party repo for it or even compile it from source?

-- Do you prefer a stable less changing system like I do or do you like to have the latest an greatest of everything and are not afraid of occasional breakages.

However the Only big question to ask yourself is this.

WHAT IS WRONG WITH THE CURRENT SYSTEM ?

And if there is , should you not rather fix the issue than changing to a new distribution? You would learn more things about the distribution while fixing your issues than installing a new distribution.

And if there are no ways to fix the issue, Should you not reinstall the same OS again and try, if not what is the assurance that the new distro will not give you the the same pain.

At the end of the day, We need our computers to do some work, Like I am writing this post, If I had to do a new Linux Distro installation every day, or every week, When would I be able to do productive work? I say no, Because so far I have only been formatting my system every week. sometimes 2-3 times a week, It was total madness !!

ARE ALL LINUX DISTRIBUTIONS NOT JUST THE SAME THING AT THE CORE! JUST GNU/LINUX ?

Considering all of the above I made a decision to use Ubuntu 14.04 until Ubuntu 16.04 comes out. I am sure that I will not switch OS anytime soon.

I would however miss GENTOO!!

Thanks for reading and I hope this helps you in stopping distro hopping.

Sunday, August 9, 2015

How to Increase the battery backup of your Laptop under Ubuntu

How to Increase the battery backup of your Laptop under Ubuntu


Ubuntu and its derivatives form the major chunk of Linux on Desktop/Laptop. Ubuntu forms a very solid base for other distributions and that is why it is the most forked distro out there.If you want to start someone on Linux you would probably hand them over something like a Linux Mint or a Zorin OS. Linux has come a long way and it is not a difficult to use Linux on the Desktop/Laptop. The hardware compatibility has improved to a great extent. Most of the hardware these days supports Linux, The support for Graphics Cards has improved, Almost all hardware on all branded laptops and desktops supports Linux out of the box. Big names like Dell, HP and Lenovo are coming up with some systems with Linux preloaded, Even if Linux is not preloaded, there is a good Chance that you would get Linux to work on most of the Systems these companies make.

I am currently using a Lenovo, Z50-70 Laptop which came pre loaded with Windows 8.1. I installed Linux on it and everything worked out of the box with no problem what so ever, WIFI, Bluetooth, Touch pad, etc.. all worked well.

However there are two major problems with Linux on Laptops like mine, One is Hybrid Graphics and the other is battery Life. Battery life on Linux is generally very low in comparison with Windows, This could be a deal breaker at times.

With Bumblebee technology at our disposal, Hybrid Graphics can be managed and used  with a great degree of success. I have written a couple of blogs around the same. You can read those in detail and the concepts are presented with respect to Ubuntu as a base distribution. The way it works is same across all distributions.

I have been struggling for some time with the battery backup. The machine I am referring to is a mid variant with Intel Ci5 processor and Nvidia GT 820 M for my games. Even with windows the machine does not give enough backup. It hardly lasts 2 -2.5 hours of regular use, Web surfing email, chat etc.

When I switched to Linux the battery backup was reduced by 45 Minutes. I would only get 1.45 hours to 2 hours at max. I began wondering if there was a way to get this equal to Windows. I kept searching all over the place and found that one could use laptop-mode-tools and it would get you  almost at par with Windows as far as battery backup goes. However the options which you can tweak are not a lot in number. You could tweak it to some extent but not a lot.

Then I found TLP. I have been testing TLP across various versions of Ubuntu, Mint, Arch, Manjaro, OpenSuse etc... and I found the tool to be very effective, I got the same battery backup as I was getting with Windows and  I could get it to extend more than 3 hours by tweaking a few parameters.

Without further delay, let me provide you steps to get TLP installed and configured properly under Ubuntu.

Assumption:- You have a laptop with Intel CPU. If not then you should rather use laptop-mode tools or just don't edit the TLP configuration.

Steps:-


1) Add the TLP Repository and Install TLP

sudo apt-add-repository ppa:linrunner/tlp
sudo apt-get update && sud apt-get install tlp tlp-rdw -y

2) Start TLP

sudo tlp start

The default configuration should work for most cases and should get your battery performance up to what you get under Windows.

Location of config file is /etc/default/tlp

However you could tweak a few more parameters to make it better. One could do that however the implications should be clearly understood before making changes


First Option.


#Select a CPU frequency scaling governor:

This Option basically controls how the CPU on the machine responds to load conditions with respect  to power conditions.

This is not enabled by default in the configuration.  It gives a bit of an explanation around what it does. It has two states powersave and performance.

It is obvious that one would expect the best performance while connected to AC power, However when on battery power one would want some powersaving. Hence one needs to set the below.

CPU_SCALING_GOVERNOR_ON_AC=ondemand
CPU_SCALING_GOVERNOR_ON_BAT=powersave

By running sudo gedit /etc/defaut/tlp one can edit and setup these options.


Second Option


Like the first Option, this is also not setup by default. This should be setup manually.

# Set the min/max frequency available for the scaling governor.

This is something that I would set up very carefully. Using these settings you control how the CPU cycles. Setting up too low values may cause degradation in performance beyond bearable limit. I have done some calculations and Here are my configured values.

CPU_SCALING_MIN_FREQ_ON_BAT=500
CPU_SCALING_MAX_FREQ_ON_BAT=1000

My CPU is 1.7 GHZ with turbo boost up to 2.4. When on battery I don't play games or run any CPU intensive tasks, I mostly read and write , for my purpose it works great and I get great backup. I plug in the charger when I need it to do heavy lifting.

Third Option


# Set Intel P-state performance: 0..100 (%)

This one is again related to CPU and it sets the maximum performance of the Intel Pstate driver on your Laptop
I have set it up as below.

CPU_MIN_PERF_ON_AC=0
CPU_MAX_PERF_ON_AC=100
CPU_MIN_PERF_ON_BAT=0
CPU_MAX_PERF_ON_BAT=30

On battery It goes up to only 30 % of the Max performance. I ab basically causing the CPU to under perform on Battery so that the battery life extends more.

Fourth Option


This is related to turbo boost technology from Intel. If you have an Intel processor capable of turbo boost you need to set this up for saving battery life.

CPU_BOOST_ON_AC=1
CPU_BOOST_ON_BAT=0

This means that on battery turbo boost feature stays disabled.

These are the only 4 Options In addition to what TLP sets up by default which can save you precious battery life.

Please bear in mind that by setting up these options there will be a performance hit to some extent however in exchange you will get more juice out of the battery.

Please exert caution while Implementing these or else just use the defaults.

I hope this will help many people.

Thanks for reading.

Friday, May 29, 2015

SWAP! Problem and Solutions


SWAP! Problem and Solutions

Swap such a lovely and a very well known word in the Linux world. Something everyone who has ever used Linux in any form should be aware of.

Swap is an area of the Hard Disk which is used as a temporary storage of files by the Linux kernel. While using any program on a computer, the binaries of the program must be loaded into the system memory/RAM so that the processor can execute the code. This is a standard and almost all Operating systems were designed to work like this. Linux is no exception. Linux Kernel as an inbuilt algorithm that calculates the code that could be safely put to the Swap area thereby saving some RAM.

The history of computers tells us that the most valuable system resource for a computer for executing any program after the CPU is the RAM. And history also tells us that this very resource has always been scarce.RAM was very scarce and expensive hence this affected many important design choices for Operating Systems. The very architecture of Operating Systems especially Linux was hence put forth with an Idea to conserve as much RAM as possible for more immediate tasks, and use RAM only for code in constant use by programs.Use it less and try using an alternative resource for code which gets loaded into the Memory but is not used all that frequently. So a separate partition was created the SWAP partition.

The Swap partition was traditionally that specific area of the Hard Disk which was allocated while installing a Linux System for Swapping purpose. Swapping is essentially temporarily moving less used code from a running program to a Hard Disk area. This reduced pressure on the RAM resource and also ensured that the system was able to run and do its job. Linux as an OS always has respected RAM by design, Linux Memory Management is the best because of that. Linux tends to put little Pressure on RAM and only load up code in RAM which is constantly being used by the running programs. It quickly moves the less frequently used code on to the Swap are.

Well Swapping is fine and indeed something that should happen when you are using Linux on a headless server. All you use to connect to the server is a ssh connection. The Server is most likely serving web pages or sending emails. Using headless server means you are making the best use of the System Resources. The Operating System takes very less resources to run while almost all system resources are allocated for doing the more Important tasks like serving your web pages or transferring emails. Such systems have no user interface. The end user is not directly interacting with the server and all the user cares about is the web pages and emails they use. So technically swapping is not going to slow down your system. It will in fact help in case the system load increases beyond what you expected. This is one of the reasons why Linux is so successful in Servers and Mainframes.

The Scenario on a Desktop on the other hand is completely different that this. For Starters, a user is constantly interacting with the desktop. Applications are launched and closed. A complete Graphical subsystem is run on a Desktop. This is something that is not typical of a Linux Use case, However since Linux is free and Open Source, there are people who are passionate about making Linux Desktop a success. Consequently there is a large number of projects tackling this in their own way. Hence we have a choice of different desktop environments.

So where does Swap Stand in this. Although we have so many Desktop Environment and distributions, the Linux Kernel is still the Same as it was years ago. Support for new hardware is added all the time so the Experience on the Desktop has gotten better over the years. SWAP however remains almost the same concept. Swap is still swap and the way Linux Kernel uses swap is still the same. Linux will still try and conserve RAM by using swap. This is the way Linux is designed. This is fine for Server Use Case. In case of the Server use, Swap is a boon and a lifesaver at times. The users using the Services from the server never see any Impact. They never feel that the Server is swapping. Using Swap this is a very normal phenomena in Server Space. With the Desktop however, the software that runs is different the way system is used is different. So If we go by they way Linux uses swap, there may be certain parts of the code loaded into the memory that the system may not access that frequently but they are needed to be in RAM for an acceptable experience. Linux kernel is agnostic to this an carries on with the memory management algorithms it was designed with. The swapping on a Desktop can create more issues than it solves. Swapping makes the Desktop Environment and the application graphics less responsive. This potentially degrades the user experience. System feels a lot slow.

Luckily though we can control the degree of swappiness, We can control the severity of swapping. We can tell the Linux kernel to either not use swap at all or use swap when a certain threshold is reached on the RAM consumption. We could tweak the percentage after which swapping to disk should happen. This at least guarantees some level of performance and you know exactly when your system would start swapping out to Disk. This make things a lot better, however we are still not near the Ideal solution.

This is a well known fact that Swapping could kill your desktop experience however there are certain advantages which you definitely get with having a swap partition on the disk. Suspend/resume and Hibernation work really well with Swap on disk. This is a feature which a lot of users using Linux on Desktop appreciate.

While suspend and resume are important to people however I personally feel that the downside of excessive swapping is way more than the advantages of being able to swap and hibernate to the disk. I personally don't use swap on my Laptop/Desktop unless I have an SSD where the Swap resides. Swapping to an SSD can considerably reduce the lag that could result from swapping to a spinning disk.

So there must be a solution to this problem. We all know that the Linux Kernel needs a swap area, That is how the Kernel was designed. So we needed to device a solution which would provide swap space and still would not kill the performance and responsiveness of the desktop. We indeed achieved that with recent versions of Linux Kernel. We now have support for ZSWAP and ZRAM in the Linux kernel. However these are still not enabled by default. Based on your distribution of choice and whether or not you are running from a SSD, you could tweak these to achieve best results.

ZSWAP :- This technology basically compresses the SWAP pages in memory before writing to the Disk. Consequently the CPU is taxed a bit. However instead of writing say 1 GB to the swap area which is essentially the same disk used traditionally, It would now write say 500MB. Which means it is using less swap. This could be very helpful in improving the system response on the desktop. Since the swap is on disk, you can still enjoy Suspend/Resume/Hibernation features of Linux on the Desktop.

ZRAM:- Zram is similar to Zswap except it does not use Disk at all to swap. It uses a portion of RAM instead and stores Swap pages there in compressed format. Since there is no disk involved, Everything is running out of RAM. This means the performance is going to be the best with this solution. It really works well. The compression is done well and Kernel is still able to swap but RAM is used instead. This will tax your CPU a bit because of the compression it does, however the experience is just fantastic. One caveat though, Since Disk is not used at all, You can't Suspend/Resume/Hibernate. That is one disadvantage you need to live with, This however gives you the best possible performance even though your system uses Swap.

On top of Zswap and Zram, One must tweak vm.swappiness to ensure that swapping is the last thing that happens on your Desktop. Linux Kernel must wait till maximum amount of RAM is consumed before starting to swap. So once RAM is scarce, Swapping happens however it either happens to RAM in a compressed format or it happens to an already allocated block of RAM.

I woud personally set vm.swappiness=0 or at the most vm.swappiness=10
Hope you liked this and you can now choose between ZRAM and ZWAP and not use just swap!!

Monday, May 4, 2015

How to Install the latest Nvidia Driver in Ubuntu 14.04.2/14.10/15/04 via Bumblebee

How to Install the latest  Nvidia Driver in Ubuntu 14.04.2/14.10/15/04 via Bumblebee    

This is a followup post to one of my earlier posts which was appreciated by the community and I felt like I was able to help people with my work. I would like to carry on with this. I know for a fact that the only problem with installing Ubuntu on a Laptop with Optimus Nvidia Graphic Cards is that people get black screen after installing the Proprietary Nvidia Drivers. I would like to step up and be a source of help for Getting bumblebee installed and configured on these laptops so people could continue using Ubuntu.

OK first things first. If you want to understand how Bumblebee Works? How it handles the Hybrid Graphics? Please read this first.


This is my earlier blog post which provides some clarity on what Bumblebee is and how it works

Now lets get down to business. I am going to focus on getting the Latest Nvidia Driver 349.16 on Ubuntu 14.04 and later.

The official Repository of Ubuntu has only old and dated drivers. I don't use that myself and would suggest you do the same if you want the latest Nvidia Driver without any problems.

Steps:-

1) First step after installing Ubuntu is to install all updates. You may use the software updater or simply run sudo apt-get update && sudo apt-get upgrade

2) Add the Xorg-edgers ppa using

sudo apt-add-repository ppa:xorg-edgers/ppa and then sudo apt-get update

Update :- There is just one more PPA which you need to add to get the Nvidia-Drivers now.

ppa:graphics-drivers/ppa, Please add this PPA as well only then will you be able to install latest Nvidia Drivers.
 
3) Run sudo apt-get upgrade && sudo apt-get dist-upgrade

This is the most Important step. If you miss this you will see a black screen after reboot. Please do this as we are using the xorg-edgers ppa. We need to ensure all packages required for bumblebee and nvidia are taken from the ppa.

4) Now Install bumblebee and Nvidia drivers using

sudo apt-get install bumblebee bumblebee-nvidia primus nvidia-349

5) Add the current user to the bumblebee security group.

sudo gpasswd -a $USER bumblebee

for Ubuntu 15.04 only you need to manually enable to bumblebee daemon using

sudo systemctl enable bumblebeed

6) This will take care of the Installing the required software on your system. We need to configure it.

I can assure you if you followed these steps so far then configuring should be a breeze.

We start by enabling bbswitch and intel i915 Driver.

7) sudo gedit /etc/modules 

Ubuntu 15.04 the file is /etc/modules-load.d/modules.conf

add these two lines to it

i915
bbswitch

8) Edit the bumblebee configuration file.
sudo gedit /etc/bumblebee/bumblebee.conf

1. line 22:

Driver=nvidia

2. line 55:

KernelDriver=nvidia-349

3. line 58:

LibraryPath=/usr/lib/nvidia-349:/usr/lib32/nvidia-349

4. line 61:

XorgModulePath=/usr/lib/nvidia-349/xorg,/usr/lib/xorg/modules

In addition to this there is another file that needs to edited.

9) sudo gedit /etc/modprobe.d/bumblebee.conf

Add the below lines to end.

#349
blacklist nvidia-349

Now you may reboot. After reboot.

Check using

sudo apt-get install mesa-utils if mesa-utils is not already installed.

primusrun glxinfo | grep OpenGL

This should tell you that nvidia-349.16 driver in use.
Please note that nvidia-349 is the latest driver at the time of writng this. Please check the launchpad page for xorg-edgers ppa an accordingly replace nvidia-349 with the latest version if any.

Let me know if this works for you.


Tuesday, March 24, 2015

How does Bumblebee work with Optimus NVIDIA GPU

How does Bumblebee work with Optimus NVIDIA GPU


What is bumblebee? Sounds like the name of an Insect or perhaps you would recognize it with the Transformer Series of Movies. The yellow Car which uses the voices from the Car's Audio system, to talk to people. Well all this is true, However What I am referring to is entirely different and it concerns Linux. Especially Linux on Computers with the Optimus Graphic Cards from Nvidia. These systems are very different from the traditional single graphics Card systems. In Traditional systems what would happen on the desktop and laptop computers is that, you would have only one graphics card. Either an Integrated graphics card or a dedicated graphics card.

What if your system had the option of having both types of cards. I mean if a computer had an Integrated graphics card capable enough of running most of the graphics stack on your computer, and onother dedicated Card to handle the heavy duty gaming stuff, How would things be then ? How would one manage the graphics cards and their settings then?

This is mostly achieved in modern hardware by using a combination of an Intel Integrated GPU and a secondary discrete NVIDIA gpu. The technology is called as Optimus. Well most of the latops these days come with the NVIDIA/INTEL Optimus setup. However having the technology at the hardware level only is not sufficient. We need to have a software stack which would then use the technology within the Operating Systems. How do we achieve this? and Quite Frankly Microsoft Windows leads in this area as the most widely used Desktop operating system hence with windows, The Optimus Technology is quite well supported out of the box wth almost zero effort on the user's part. Whenever a graphics intensive application is launched the system automatically switches to the more powerful NVIDIA GPU. Which is great as the user gets great performance without having to worry about anything. When there is no need for the NVIDIA GPU, the System automatically switches back to the Intel Integrated GPU. The result being more efficient utilization of the system resources and Improved battery life with optimum performance for you graphic intensive applications.

Well that is how it was supposed to work. However that is true only on the windows side of the world. We know MS Windows is not the end of the world. So we now talk a bit about Linux. With Linux the road is a bit bumpy, however we also have a perfect solution for Linux. We rather have two solutions to the same problem. I will cover both in this POST.

We need to understand one basic fact that with Linux, the automatic switching from Intel to NVIDIA GPU and Vice Versa is not yet supported. We can switch however user intervention is needed. Apart from this there is no other caveat to this.

The First Option is called NVIDIA PRIME. Under NVIDIA Prime, One Installs nvidia drivers alongwith the nvidia prme and nvidia-settings. In this method Nvidia-Settings program is used to switch between the driver. One can use only on GPU at one time. The Entire System will use on GPU at one time. We can Change and choose Which GPU we want however after selecting we need to logout of the session and start a new session. So this is a soluion requiring the least amount of configuration and consequently we have to live with the fact that we need to switch he graphic Card for the whole system and start a new session to use the newly selected GPU.(This works only with Nvidia Closed Source Drivers supplied by NVIDIA)

The Second Option is called the Bumblebee !! you hear it .. It is indeed called Bumblebee. Well I am not going to go into why it is called so, the fact of the matter is that it is a great solution to use in case you have the Optimus based hardware like I have. It allows you to select the GPU at run time by selecting which application you would want to run on the dedicated GPU. Yes it is true. You can launch applications to use a the high power NVIDIA GPU. By default the system always uses the Integrated Intel GPU. However when needed you can launch a application specifically targeting the NIDIA GPU.Not only that this works well with NVIDIA Closed Source Drivers but with the nuoveau Open Source Drivers as well.

I am going to be elaborating a more on the Bumblebee Stuff as there is still a lot of confusion for the new users to Linux as to how it exactly works. Bumblebee is a very Interesting piece of software. It is however often misunderstood and hence not everyone prefers it. But I strongly recommend it. Almost all Linux Distros have a small wiki dedicated to how to get Bumblebee working. There is a special case of Ubuntu and anything based on Ubuntu that I would like to point this article to.

If there is a new user ever starting the switch from Other Operating Systems to Linux, there is a high chance that he will land on to a Ubuntu or Ubuntu Spin. If the user has an Optmus Laptop then things become really Interesting. The user is used to out of box experiences and Linux in this case does not offer one. So there needs so be a specific wiki/documentation for this. There is however i personally believe it is not sufficient. There are some specfics which I think are still not covered in any Wiki for Ubuntu. I am going to focus on Ubuntu beause I fee Ubuntu documentation on bumblebee is poor.

Ok let us Understand the Operation and how it to be correctly configured.

While using Bumbelee to control the Optimus/Hybrid graphics on a laptop we must understand that Bumblebee takes total control of the Driver or the Nvidia Graphics Card. This means that Bumblebee Daemon controls the loading and unloading of the Driver. The Module for Loading the Graphics Drivers for Nvidia Cards, Namely Nouveau and nvidia-XXX driver is to be controlled by Bumblebee.

So here is a few things one needs to ensure while configuring bumblebee on Ubuntu. We need to ensure that the Driver/Kernel Module for the NVIDIA CARD is completely Blacklisted so that it never loads automatically. We want bumblebee to completely control this card.
This can be done as below.

  1. Blacklist Noueau Driver so it does not load automatically. (This is generally done Automatically by the Bumblebee Install.) Config Files to look at. /etc/modprobe.d/nvidia-XXX_hybrid.conf in case you Installed your Nvidia Proprietary Drivers alongwith Bumblebee. If you do not plan on using only Noveau, Then you must manually create a /etc/modprobe.d/blacklist-nouveau.conf and add one line to it, blacklist nouveau.
  2. Blacklist the NVIDIA-XXX Driver , We need to ensure that the NVIDIA-XXX driver needs to stay blacklisted as well. This most likely shoul happen automatically however if you are using any driver newer thatn Nvidia-331, Then it is a good option to look in /etc/modprobe.d/bumblebee.conf. This file is automatically generated while Installing Nvidia Graphics Drivers after installing Bumblebee. If you do not see the driver you are using in the file, you must add it manually. 
  3. Automatically load i915 Driver for Intel card. We need to add bbswitch and i195 to the /etc/modules file. This is because we want the bbswitch module to load automatically, this is what actually turns on and off the Nvidia Graphics Card. We also want that the Intel Integrated Card to be in use always so we add that to the file.

The above three steps ensure that we have only Intel Card enabled by default and Nvidia Drivers completely removed from getting automatically loaded. We also are loading he bbswitch module automatically which will actually switch the Nvidia Gaphics Cad ON and OFF when launching any program using optirun or primusrun prefix from the terminal. These two are the commands that need to be prefixed while launching wine or Steam depending on which of these you use or gaming. Or any other program which needs some Juice from the Nvidia Graphics Card.

Configure Bumblebee to use your Nivida-Drivers

The Only other piece of configuration that needs to be done is as below.

sudo gedit /etc/bumblebee/bumblebee.conf

1. line 22:

Driver=nvidia

2. line 55:

KernelDriver=nvidia-331

3. line 58:

LibraryPath=/usr/lib/nvidia-331:/usr/lib32/nvidia-331

4. line 61:

XorgModulePath=/usr/lib/nvidia-331/xorg,/usr/lib/xorg/modules

5. Reinstall bbswitch-dkms:

sudo apt-get install --reinstall bbswitch-dkms

6. Reboot

Note:- Just ensure that you replace nvidia-331 with the driver you have Installed.

If you are planing to use Nouveau driver then you don't need the above configuration, I will automatially work with Nouveay driver.

I now hope that after readin this post, many Ubuntu Users will understand the Bumblebee Concepts Clearly.

Friday, March 13, 2015

How to install Bumblebee on Ubuntu 15.04/14/04 and Derivatives on Laptops with Optimus Nvidia Cards


How to install Bumblebee on Ubuntu 15.04/14/04 and Derivatives on Laptops with Optimus Nvidia Cards

Nvidia Optimus technology is something that is not completely supported out of the box. I have recently purchased a Lenovo Z50 laptop which has a 2GB NVIDIA GE FORCE GT820M. This is an entry level gaming card but can play most games without issues.

So I was happy with my purchase. Since I am a Linux Power User I immediately got rid of Windows and installed Ubuntu on it. However to my surprise I always got a black screen after installing Nvidia proprietary drivers.

Bumblebee would also throw errors . After 2 weeks or breaking my head against the wall an formatting my laptop 5 times now I am back. I have been able to successfully install the nvidia drivers and configure bumblebee as well.

I LOVE LINUX..

Below are the steps I took to get things working for myself. I am sharing this to make things easier for others.


1) Install Bumblebee from the Official Ubuntu Repositories.

Sudo apt-get install bumblebee bumblebee-nvidia  --– This installs bumblebee.
dkms status-- This tels whch ersion of bbswitch and kernel is installed
sudo apt-get install bbswitch-dkms - Install bbswitch dkms
sudo apt-get install primus
sudo systemctl enable bumblebeed ( Ubuntu 15.04 Since it uses systemd now)
sudo gpasswd -a $USER bumblebee

2) Add the following lines to the /etc/modules file
i915
bbswitch

I am using Ubuntu 15.04 beta and it has switched to Systemd so I have added these two into this file.
/etc/modules-load.d/modules.conf

3) Now We need to blacklist nouveau module, we need to do it event though we might need to use it later. This is important we want only bbswitch to load either the nouveau or nvidia drivers
/etc/modprobe.d/nouveau.conf OR /etc/modprobe.d/blacklist-nouveau.conf
just add one line to any of these files

blacklist nouveau

4) Reboot and then run
sudo cat /proc/acpi/bbswitch this shoud give a result as OFF

sudo echo ON > /proc/acpi/bbswitch

sudo cat /proc/acpi/bbswitch This should now give a result of ON

This confirms that BBSWITCH works.

6) One more reboot

Once rebooted if you run the command
primusrun glxinfo | grep OpenGL

You would see the OpenGL String points to
OpenGL vendor string: nouveau

This confirms that bumblebee is working fine and able to load the nouveau driver fine.

NOTE no need to edit the /etc/bumblebee/bumblebee.conf file as of yet as it is already configured for using nouveau drivers.


7) Now the really tricky part. Which means We need to install the Proprietary NVIDIA Drivers which Will override the nuoveau drivers.
IMPORTANT TO NOTE THAT THERE IS A BUMBLEBEE BLACKLIST FILE BY DEFAULT IN THE FOLDER.

/etc/modprobe.d/

bumblebee.conf

Contents of this file are

sudo cat /etc/modprobe.d/bumblebee.conf
# installed by bumblebee-nvidia
# to be used by kmod / module-init-tools, and installed in /etc/modprobe.d/
# or equivalent

# do not automatically load nouveau as it may prevent nvidia from loading
blacklist nouveau
# do not automatically load nvidia as it's unloaded anyway when bumblebeed
# starts and may fail bumblebeed to disable the card in a race condition.
blacklist nvidia
blacklist nvidia-current
blacklist nvidia-current-updates
# 304
blacklist nvidia-304
blacklist nvidia-304-updates
blacklist nvidia-experimental-304
# 310
blacklist nvidia-310
blacklist nvidia-310-updates
blacklist nvidia-experimental-310
# 313
blacklist nvidia-313
blacklist nvidia-313-updates
blacklist nvidia-experimental-313
# 319
blacklist nvidia-319
blacklist nvidia-319-updates
blacklist nvidia-experimental-319
# 325
blacklist nvidia-325
blacklist nvidia-325-updates
blacklist nvidia-experimental-325
# 331
blacklist nvidia-331
blacklist nvidia-331-updates
blacklist nvidia-experimental-331
# 334
blacklist nvidia-334
blacklist nvidia-334-updates
blacklist nvidia-experimental-334
# 337
blacklist nvidia-337
blacklist nvidia-337-updates
blacklist nvidia-experimental-337
# 340
blacklist nvidia-340
blacklist nvidia-340-updates
blacklist nvidia-experimental-340
#343
blacklist nvidia-343
blacklist nvidia-343-updates
blacklist nvidia-experimental-343

This is a problem specific to Ubuntu and its derivatives only.(Sorry for this earlier I posted that one needs to uncomment the Driver in above file which is not true.)

So if you see the contents of this file reveal that no matter what you do you can't get succes in getting bumbleebee work with any of the nvidia drivers unless you Ensure that your Driver is listed above and blacklisted.

This will ensure that the driver Is not loaded automatically. If it loads automatically, you will have a BLACK SCREEN at boot.

Bumblebee needs to be controlling the Loading and Unloading of the NVIDIA DRIVER MODULE.

Or example i am using the 340 series of drivers so My drivers were already blacklisted.

blacklist nvidia-340
blacklist nvidia-340-updates
blacklist nvidia-experimental-340

Now you can edid the bumblebee.conf as below.

Sudo gedit /etc/bumblebee/bumblebee.conf

1. line 22:

Driver=nvidia

2. line 55:

KernelDriver=nvidia-331

3. line 58:

LibraryPath=/usr/lib/nvidia-331:/usr/lib32/nvidia-331

4. line 61:

XorgModulePath=/usr/lib/nvidia-331/xorg,/usr/lib/xorg/modules

5. Reinstall bbswitch-dkms:

sudo apt-get install --reinstall bbswitch-dkms

6. Reboot

NOTE :- You neeed to make sure that you place the nvidia-331 with whatever driver version you have installed in previous steps and the one you uncommented from the bbswitch.conf file under /etc/modprobe.d/bumblebee.conf

In my case below is what my bumblebee.conf looks like.



# Configuration file for Bumblebee. Values should **not** be put between quotes

## Server options. Any change made in this section will need a server restart
# to take effect.
[bumblebeed]
# The secondary Xorg server DISPLAY number
VirtualDisplay=:8
# Should the unused Xorg server be kept running? Set this to true if waiting
# for X to be ready is too long and don't need power management at all.
KeepUnusedXServer=false
# The name of the Bumbleblee server group name (GID name)
ServerGroup=bumblebee
# Card power state at exit. Set to false if the card shoud be ON when Bumblebee
# server exits.
TurnCardOffAtExit=false
# The default behavior of '-f' option on optirun. If set to "true", '-f' will
# be ignored.
NoEcoModeOverride=false
# The Driver used by Bumblebee server. If this value is not set (or empty),
# auto-detection is performed. The available drivers are nvidia and nouveau
# (See also the driver-specific sections below)
Driver=nvidia
# Directory with a dummy config file to pass as a -configdir to secondary X
XorgConfDir=/etc/bumblebee/xorg.conf.d

## Client options. Will take effect on the next optirun executed.
[optirun]
# Acceleration/ rendering bridge, possible values are auto, virtualgl and
# primus.
Bridge=auto
# The method used for VirtualGL to transport frames between X servers.
# Possible values are proxy, jpeg, rgb, xv and yuv.
VGLTransport=proxy
# List of paths which are searched for the primus libGL.so.1 when using
# the primus bridge
PrimusLibraryPath=/usr/lib/x86_64-linux-gnu/primus:/usr/lib/i386-linux-gnu/primus
# Should the program run under optirun even if Bumblebee server or nvidia card
# is not available?
AllowFallbackToIGC=false


# Driver-specific settings are grouped under [driver-NAME]. The sections are
# parsed if the Driver setting in [bumblebeed] is set to NAME (or if auto-
# detection resolves to NAME).
# PMMethod: method to use for saving power by disabling the nvidia card, valid
# values are: auto - automatically detect which PM method to use
# bbswitch - new in BB 3, recommended if available
# switcheroo - vga_switcheroo method, use at your own risk
# none - disable PM completely
# https://github.com/Bumblebee-Project/Bumblebee/wiki/Comparison-of-PM-methods

## Section with nvidia driver specific options, only parsed if Driver=nvidia
[driver-nvidia]
# Module name to load, defaults to Driver if empty or unset
KernelDriver=nvidia-340
PMMethod=auto
# colon-separated path to the nvidia libraries
LibraryPath=/usr/lib/nvidia-340:/usr/lib32/nvidia-340
# comma-separated path of the directory containing nvidia_drv.so and the
# default Xorg modules path
XorgModulePath=/usr/lib/nvidia-340/xorg,/usr/lib/xorg/modules
XorgConfFile=/etc/bumblebee/xorg.conf.nvidia

## Section with nouveau driver specific options, only parsed if Driver=nouveau
[driver-nouveau]
KernelDriver=nouveau
PMMethod=auto
XorgConfFile=/etc/bumblebee/xorg.conf.nouveau

=======================================================================
So please make changes to your files accordingly..

Now the final Reboot.

After the reboot you can now test

Run the command

primusrun glxinfo | grep OpenGL


primusrun glxinfo | grep OpenGL
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce 820M/PCIe/SSE2
OpenGL core profile version string: 4.4.0 NVIDIA 340.76
OpenGL core profile shading language version string: 4.40 NVIDIA via Cg compiler
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.4.0 NVIDIA 340.76
OpenGL shading language version string: 4.40 NVIDIA via Cg compiler
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:

So now my Laptop is using the Nvidia Optimus technology with the 340 Series Nvidia Proprietary Driver.

I Hope this helps people..

I have used the below two articles to reach this solution.


My OS :- Ubuntu 14.04.2

Laptop :- Lenovo Z50
Nvidia:- GE GFORCE GT 820M
COREI5 4th gen with Haswell graphics.
4GB RAM

Regards
Rajat Pandita