Tuesday, April 25, 2023

installing NVIDIA graphics card in Centos 7-6 linux

First download NVIDIA driver from official website.

Now blacklist "nouveau" driver shipped with Linux OS which is responsible for graphical display.  Disable it to install NVIDIA graphics card software. 

because "nouveau" is default driver for graphics card and is shipped with OS, it necessary to disable it. Otherwise OS does not allow to install our graphics card driver. In CentOS 6, to disable "nouveau" graphics driver, just change name of "nouveau.ko" to your choosen name as mine is "nouveau.ko.original.backup"

Path to "nouveau.ko"  graphics driver in Centos 6 is :-

dir : "/lib/modules/2.6.32-754.el6.x86_64/kernel/drivers/gpu/drm/nouveau/"

# mv nouveau.ko nouveau.ko.original.backup

You do not need to blacklist, because if you rename it, at boot time OS can not find it by its original name. After renaming that run "dracut" command as given below. Without it if you restart OS then OS will not boot even in emergency mode. So do as follows.

in centos 7 do only this to disable nouveau.ko

add "rdblacklist=nouveau" at last after "rhgb quiet" in grub.cfg.

as in this :-

linux16 /vmlinuz-3.10.0-862.el7.x86_64 root=UUID=0ec7e49f-5f1c-43db-be98-7f0d008a8514 ro crashkernel=auto rhgb quiet rdblacklist=nouveau


then run following commands :-

# dracut /boot/initramfs-$(uname -r).img $(uname -r) --force

# reboot 

boot in runlevel 3 mode, to do that :-

in boot menu highlight Linux 7 boot option then press "e", go down and add "3" after "rhgb quiet rdblacklist=nouveau" 

as :-


linux16 /vmlinuz-3.10.0-862.el7.x86_64 root=UUID=0ec7e49f-5f1c-43db-be98-7f0d008a8514 ro crashkernel=auto rhgb quiet rdblacklist=nouveau 3

and boot by pressing keys : Ctrl + X

 after getting command prompt login  as root then go to directory where NVIDIA driver is stored and run following command for driver :-

# ./NVIDIA-Linux-x86_64-352.30.run

here above is driver of your nvidia graphics card downloaded from internet.

# reboot

and NVIDIA-Linux is installed.

following command

 $ nvidia-xconfig 

will opens management window of NVIDIA card.

Most probably it may work.

you may add NVIDIA command in Main menu. This is I given already in previous blog.

You can add "nvidia.desktop" file in "/usr/share/applications/" folder to add nvidia shortcut in man menu. How to that I said it in one of previous blog search it.

Thursday, April 6, 2023

How to make iso to bootable usb & vise-versa in Centos 7 Linux

 if you are in linux you need to run following command to create bootable USB Stick from ISO of CEntOS.
In rpm linux run following commands :
in root account :-


1 # lsblk 

this will show you name, ..., size,...,..., MountPoint.
note down name of filwsystem from first collumn NAME. e.g. sde1
 

2 # umount /dev/sdx1
e.g. # umount /dev/sde1
 

3. The last step is to flash the CentOS ISO image to the USB drive. Make sure you replace /dev/sdx with your drive and do not append the partition number. Also, replace /path/to/CentOS-7-x86_64-DVD-1810.iso with the path to the ISO file. If you downloaded the file using a web browser , then it should be stored in the Downloads folder located in your user account. for ease of work you may copy ISO in /opt or /software folder or filesystem.
run command :-
 

# dd bs=4M if=/path/to/Centos7-Everthing.iso of=/dev/sde status=progress oflag=sync
 

here in "of=/dev/sde" name of "sde" is NAME of filesystem that we noted earlier as "sde1", also note that here we given "sde" not "sde1".
now you have bootable USB from ISO of Centos Linux.

You can build bootable USB from any bootable iso of any softrware. For example from redo-rescue-4.3.iso downloaded from internet. i.e. if iso is bootable  image then usb stick build will be bootable.

Run following command to build ISO from USB stick :-

# dd if=/dev/sdx1 of=/path/to/iso-file.iso 

this will create complete usb image to iso file. Here sdx1 in /dev/sdx1 is usb drive file system name and also here we given "sdx1" not "sdx" as for command for ISO to USB "dd" command.

Tuesday, April 4, 2023

gotoxy(int x, int y); and clrscr() in linux terminal (command prompt)

 

#include <sys/ioctl.h>
#include <unistd.h>
 

void gotoxy(int x,int y)
{
    printf("%c[%d;%df",0x1B,y,x);

-----------------------------------------------------------------------------

use above code to place cursor  any where in terminal e.g gotoxy(4, 10);

places (x, y) co-ordinate as (4, 10). 4th column and 10th row.

 example :-

#include <iostream>

#include <sys/ioctl.h>
#include <unistd.h>
  

using std::cout;

using std::cin;

void gotoxy(int x,int y)
{
    printf("%c[%d;%df",0x1B,y,x);

}

int main()

{

    gotoxy(5, 10);

    cout << "Here is Cursur : " ;

    cin >> x;

    return 0;

}

----------------------------------------------------------------------

example :-

#include <iostream>

#include <sys/ioctl.h>
#include <unistd.h>

#include <termio.h>
#include <cstdio>
#include <iomanip>



using std::cout;

using std::cin;

void gotoxy(int x,int y)
{
    printf("%c[%d;%df",0x1B,y,x);

}

static termios oldterm, newterm;
 void clrscr()
{
        gotoxy(0,0);

        struct winsize w;
        ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);

        for (int x = 0; x < w.ws_row; x++)
        {
            for(int y = 0; y < w.ws_col; y++)
            {
                cout << " ";
            }
        }
        gotoxy(0, 0);
}

void initTermios(bool echo)
{
    tcgetattr(0, &oldterm);
    newterm = oldterm;
    newterm.c_lflag &= ~ICANON;
    newterm.c_lflag &= echo ? ECHO : ~ECHO;
    tcsetattr(0, TCSANOW, &newterm);
}

void resetTermios()
{
    tcsetattr(0, TCSANOW, &oldterm);
}

char getch_(bool echo)
{
     char ch;
     initTermios(echo);
     ch = getchar();
     resetTermios();
     return ch;
}


char getch()
{
    return getch_(false);
}

char getche()
{
    return getch_(true);
}

int main()

{

    char x;
     clrscr();
    gotoxy(5, 10);

    cout << "Here is Cursur : " ;

    cin >> x;

    gotoxy(5, 11);
    cout << "you entered : " << x;


    getch();
    getch();
    clrscr();

    return 0;

}



getch and getche in Linux in both C++ and C

In C++ language :-

-----------------------------

 file : ClassGetch.h
-------------------------------

#ifndef ClassGetch_H
#define ClassGetch_H

#include <termio.h>
#include <cstdio>

#include <iostream>
#include <iomanip>
#include <unistd.h>

static struct termios oldterm, newterm;

class ClassGetch
{
public:
    ClassGetch();
    virtual ~ClassGetch();

    char getch();
    char getche();
    void initTermios(bool echo);
    void resetTermios(void);



protected:

private:

    termios   oldterm;
    termios   newterm;
    char getch_(bool echo);

};

#endif // ClassGetch_H

---------------------------------------------------------------
// file :- ClassGetch.cpp

-------------------------------------------------
#include "ClassGetch.h"

ClassGetch::ClassGetch()
{
    //ctor
}

ClassGetch::~ClassGetch()
{
    //dtor
}

void ClassGetch::initTermios(bool echo)
{
    tcgetattr(0, &oldterm);
    newterm = oldterm;
    newterm.c_lflag &= ~ICANON;
    newterm.c_lflag &= echo ? ECHO : ~ECHO;
    tcsetattr(0, TCSANOW, &newterm);
}

void ClassGetch::resetTermios()
{
    tcsetattr(0, TCSANOW, &oldterm);
}

char ClassGetch::getch_(bool echo)
{
     char ch;
     initTermios(echo);
     ch = getchar();
     resetTermios();
     return ch;
}


char ClassGetch::getch()
{
    return getch_(false);
}

char ClassGetch::getche()
{
    return getch_(true);
}

-----------------------------------------------------------------------------------

Include class and write above code then use getche() and getch() as where you want in your program.

getche() wait for echo of char i.e. prints a character and then returns, while getch() doesn't wait for echo of char and returns without print of char.

 -----------------------------------------------------------------------------------
file : main.cpp
-----------------------
#include "ClassGetChoice.h"
#include <iostream>


using std::cout;
using std::endl;

int main()
{
    char c;

    ClassGetch * cg = new ClassGetch;

    cout << "getche() example : " << endl;
    cout << "Enter any character : ";
 

    c = cg->getche();

    cout << "\nyou entered : " << c <<endl;

    cout << "getch() Example : "<< endl;
    cout << "Enter any character : ";
 

    c = cg->getch();


    cout << "\nYou entered : " << c << endl;

    return 0;
}

/* 

output :-

-------------

[rahul@C-Client Debug]$ ./getche-getch
getche() example :
Enter any character : w
you entered : w
getch() Example :
Enter any character :
You entered : w
[rahul@C-Client Debug]$
*/
----------------------------------------------------------------------------

In C language : -

-------------------------

file : getche-getc.h :-
-----------------------

#ifndef GETCHE-GETCH_H_INCLUDED
#define GETCHE-GETCH_H_INCLUDED

#include <stdio.h>
#include <termios.h>
#include <unistd.h>

struct termios   oldterm;
struct termios   newterm;

void initTermios(int echo);

void resetTermios();

char getch_(int echo);

char getch();

char getche();

#endif // GETCHE-GETCH_H_INCLUDED
------------------------------------------

file : getche-get.c :-
----------------------
#include "getche-getch.h"

void initTermios(int echo)
{
    tcgetattr(0, &oldterm);
    newterm = oldterm;
    newterm.c_lflag &= ~ICANON;
    newterm.c_lflag &= echo ? ECHO : ~ECHO;
    tcsetattr(0, TCSANOW, &newterm);
}

void resetTermios()
{
    tcsetattr(0, TCSANOW, &oldterm);
}

char getch_(int echo)
{
     char ch;
     initTermios(echo);
     ch = getchar();
     resetTermios();
     return ch;
}


char getch()
{
    return getch_(0);
}

char getche()
{
    getch_(1);
}
-----------------------------------------------
file : main.c :-
----------------
#include <stdio.h>
#include <stdlib.h>
#include "getche-getch.h"


int main(void)
{
    char c;
    printf("(getche example) please type a letter: ");


    c = getche();
 

    printf("\nYou typed: %c\n", c);

    printf("(getch example) please type a letter...");
 

    c = getch();
 

    printf("\nYou typed: %c\n", c);
    return 0;
}
-------------------------------------------------
/*
output :-
---------
[rahul@C-Client Debug]$ ./getch-getche-c
(getche example) please type a letter: w
You typed: w
(getch example) please type a letter...
You typed: w
[rahul@C-Client Debug]$
*/

----------------------------------------------------