Sunday, February 9, 2014

[Linux] HOW TO: Official NVIDIA drivers installation guide for Optimus graphic cards. (Linux MINT 16)

Hello guys, Last guide was a quite deprecated... There were a lot of people having problems with it so I wrote another tutorial for current version of MINT.

(Tested on Linux MINT 16 - Cinnamon 64bit edition)

- Xorg   >= 1.13.4
- xrandr >= 1.3.5
- kernel  >= 3.9

NOTE: To get rid of the black screen problem at the end, you can set your OS to autologin your user, so you don't have to put your username and password!

1) Perform a clean install linux.

2) Add repository for X-server updates and install all updates!

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

3) As in linux MINT 16 is already kernel >= 3.9, there is no need to update it anymore...

4) Use repository to install nvidia drivers.
NOTE: You can maybe install nvidia-331, but I didn't test it!
sudo apt-get install nvidia-319

5) Download xorg.conf to /etc/X11/ folder.
NOTE: There are already filled PCI numbers! At 90% you have the same, but check it with "lspci | grep vga" and change it, if needed!

sudo wget -O /etc/X11/xorg.conf-new

6) REBOOT system. After boot enter tty1 (Ctrl + Alt + F1). Stop mdm and move xorg.conf.
NOTE: mdm is in Linux MINT. In Ubuntu use gdm instead. In other distributions it can be even lightgdm or kdm.
NOTE: If something goes wrong, and you will have problem running, or this guide will just won't work for you, just remove this xorg.conf file, and reboot. Everything should be OK then.

sudo service mdm stop
sudo mv /etc/X11/xorg.conf-new /etc/X11/xorg.conf

7) Get your xrandr IDs. Startx on tty1(you get blackscreen), then switch to tty2 and write down your IDs.

a) tty1:
b) tty2:
xrandr -d :0 --listproviders

You should get output like this:

Provider 0: id: 0x2cb cap: 0x1, Source Output crtcs: 0 outputs: 0 associated providers: 1 name:NVIDIA-0
Provider 1: id: 0x46 cap: 0x2, Sink Output crtcs: 3 outputs: 4 associated providers: 1 name:modesetting

as you can see, my IDs are 0x2cb for NVIDIA and 0x46 for intel.

8) Create file .xseesionrc, make it executable and open it for edditing.

touch .xsessionrc
chmod +x .xsessionrc
nano .xsessionrc

9) Write those line into .xsessionrc, but replace my IDs with yours!

xrandr --setprovideroutputsource 0x46 0x2cb
xrandr --auto

10) Now, when you restart, you should get black screen, don't worry there is login screen, you just can't see it. Just wait for a sec, write your login, wait another sec, write you pass and hit enter. Be careful! Sometimes it want only password, if you have just one user. Now you should see desktop. Also you can set autologin to get rid of this.

UPDATE: As one Anonymous noted, the black screen can be avoided by putting those lines in step 9) into script that's run BEFORE the display manager. 

For lightdm it can be done by editing /etc/lightdm/lightdm.conf and un-comment the line display-setup-script=/path/to/the/script. Where /path/to/the/script is path to the script that contains code from step 9). 

For mdm it can be done by editing file /etc/mdm/Init/Default and adding code from step 9) to the end of file, right before "exit 0" code. 

This is not tested so please proceed carefully!

Thats it!

To check if NVIDIA is running:

inxi -GSx

you should see something like this:

System: Host: Sierra Kernel: 3.11.0-12-generic x86_64 (64 bit, gcc: 4.8.1) Desktop: Gnome Distro: Linux Mint 16 Petra

Card-1: Intel 3rd Gen Core processor Graphics Controller bus-ID: 00:02.0
Card-2: NVIDIA GF108M [GeForce GT 630M] bus-ID: 01:00.0

X.Org: 1.14.5 driver: nvidia Resolution: 1366x768@60.0hz
GLX Renderer: GeForce GT 630M/PCIe/SSE2 GLX Version: 4.4.0 NVIDIA 331.38 Direct Rendering: Yes
Please let me know, if something goes wrong :)

Saturday, February 1, 2014

[Linux] HOW TO: Backup your linux installation with TAR.

Hello again!

Today, I will show you how to backup your Linux installation using tar, step by step.

I am not responsible for any data damage!

(Tested on Linux MINT 16 - CINNAMON 64bit edition)


To backup system partition, we will use tar. Tar can store all files on disk into one file. Another good thing is that tar can preserve file permissions as well as user/group ownership. To save space, we will use gzip comprimation.
It is good to know that you don't have to make backup from live CD. But it is necessary to restore it from CD, if you can't boot your system. Don't put output file on the same partition! In this example, I save my backup file to second disk, connected to /media/Backup-Disk/.
Here is the command:

tar -zcpf /media/Backup-Disk/fullbackup.tar.gz --directory=/ --exclude=proc --exclude=dev --exclude=sys --exclude=mnt --exclude=media .
 tar parameters explained -> click

We exclude dev, proc and sys directories because system will restore them automatically.

Also, we exclude media and mnt directory because there is nothing to backup, and you can have connected device here to save your backup.

That's it, your backup file is now ready :)


If your system still works, you don't have to boot liveCD, to restore your backup. But remember that restoring backup won't remove any files! Only overwrite same files, and copy missing files. In my opinion, this only messes-up your system, and I don't really see any point in this.

Easiest way to restore is boot the live CD or USB stick, formate partition and restore backup. With this you get nice clean system as you had when you backed up.

1) First connect system partition you want to restore. For example I will use /dev/sda6 where is my linux partition located.

sudo mount /dev/sda6 /media/mounted-partition-to-restore/

2) Format partition
!!!WARNING!!!: This will erase all data on the partition! So be careful about it!

sudo rm -rf /media/mounted-partition-to-restore/*

3) Restore from backup.
NOTE: This will overwrite all files with same names on this partition!

sudo tar -xpzvf /path/to/backup.tar.gz -C /media/mounted-partition-to-restore --numeric-owner
tar parameters explained -> click

4) Create back missing directories in restored partition

cd /media/mounted-partition-to-restore
sudo mkdir proc
sudo mkdir sys
sudo mkdir dev
sudo mkdir mnt
sudo mkdir media
sudo mkdir /var/tmp
sudo chmod a+rwxt /tmp

5) If you need to restore grub, follow my "how to" here:

[Linux] HOW TO: Grub update / repair.

Hello again!

In this tutorial, you will learn how to repair or update grub on your system.

(Tested on Linux MINT 16 - CINNAMON 64bit edition)

1) Chose partition for grub installation. For list of partition use lsblk:

My output -> click

In this tutorial, I will use /dev/sda6.

2) Mount chosen partition:

sudo mount /dev/sda6 /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /sys /mnt/sys
sudo mount --bind /proc /mnt/proc

3) Make chroot for /mnt, update grub and exit chroot:

sudo chroot /mnt
sudo update-grub

4) Un-mount at the end:

sudo umount /mnt/dev
sudo umount /mnt/sys
sudo umount /mnt/proc
sudo umount /mnt/

5) You are done. Just restart system, grub should be there :)