Search This Blog

Thursday, January 25, 2018

Linux: Change your hostname

A few different ways are possible to change your hostname in linux.


  • With hostnamectl:
As root: 
[root@toolz ~]# hostnamectl set-hostname NEW-HOSTNAME

Then login/logout to see effects

Postgres: Install Postgresql-server 9.2 on Centos 7.2


  • You search for the package you'll want to install
  • [root@toolz ~]# yum search postgres|grep server

  • To get more details:
  • [root@toolz ~]# yum info postgresql-server.x86_64

  • Then install it:
  • [root@toolz ~]# yum install postgresql-server.x86_64

  • Setup the postgres password:
  • [root@toolz ~]# passwd postgres

  • Init the postgres first DB
  • [root@toolz ~]# sudo postgresql-setup initdb

  • Setup your connections:
  • [root@toolz ~]# sudo vi /var/lib/pgsql/data/pg_hba.conf

  • Start postgresql service
  • [root@toolz ~]# systemctl start postgresql

  • And finaly enable it to start automatically at next boot
  • [root@toolz ~]# systemctl enable postgresql


What to do next:
  • pg_hba.conf
  • create databases and users
  • postgresql-server logging

Thursday, January 11, 2018

Linux: apt





Common errors:

gpg: keyserver receive failed: No dirmngr

The error will look like:
root@deb15:~# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0DF731E45CE24F27EEEB1450EFDC8610341D9410
Executing: /tmp/apt-key-gpghome.CQvyuFwlWI/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0DF731E45CE24F27EEEB1450EFDC8610341D9410
gpg: failed to start the dirmngr '/usr/bin/dirmngr': No such file or directory
gpg: connecting dirmngr at '/tmp/apt-key-gpghome.CQvyuFwlWI/S.dirmngr' failed: No such file or directory
gpg: keyserver receive failed: No dirmngr


To fix it, just install dirmngr:
root@deb15:~# apt install dirmngr


Now, all's fine:
root@deb15:~# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0DF731E45CE24F27EEEB1450EFDC8610341D9410 Executing: /tmp/apt-key-gpghome.zspnEwdIk3/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0DF731E45CE24F27EEEB1450EFDC8610341D9410 gpg: key EFDC8610341D9410: public key "Spotify Public Repository Signing Key " imported gpg: Total number processed: 1 gpg: imported: 1

Wednesday, November 15, 2017

Linux: Create a bootable usb key

It's pretty simple and straight forward to create bootable USB on linux.

dd if=image.iso of=/dev/sdX bs=4M && sync


with:

  • if: Input FIle (your ISO)
  • of: Output File. /dev/sdX represent your USB key. Replace X with the letter of your volume (can be found with fdisk -l)
  • bs: Block Size
  • sync: make sure all data in buffer are written to disk 

Tuesday, November 14, 2017

Linux: Change your lost root password

Careful, this doesn't work on Centos 7

On startup, go to rescue mode. e to edit the line.

Add int=/bin/bash in the linux/kernel line (depending if you're using grub or grub2). Start it.
When on the command line, mount your file system and change your password:
# mount -o rw, remount /
# passwd
# touch / .autorelabel
# /sbin/reboot -f


Now, you have a new root password ;)

Thursday, November 9, 2017

GRUB

Configuration


The default loader for many Linux distributions, including enterprise Red Hat 5 and 6 , is GRUB (Grand Unified Bootloader). It is highly configurable, in particular by accepting encrypted password protection, using shell or graphics mode. It is configured with a text file and there is no need to reinstall GRUB with each change. Although replaced by GRUB2 in all distributions, do not think that GRUB has disappeared. There are strong chances, if you use Amazon EC2 instances on Linux, that the used boot loader is its first version, called "legacy".
Here is an example of a configuration file assuming that the first partition of the first disk is /boot, and that the second contains a Windows installation:

timeout=10
default=0
title Red Hat
    root (hd0,0)
    kernel /vmlinuz-2.6.12-15 ro root=LABEL=/
    initrd /initrd-2.6.12-15.img
title Windows XP
    rootnoverify (hd0,1)
    chainloader +1


Syntax: 

GRUB Parameter
Description
chainloader +1Start the first sector or the root specified above
default nDefault boot (0=first title, 1=second title, etc.)
gfx menuPath to graphic menu
initrdInitial ramdisk. The kernel will load this file in memory to find configuration details and initial drivers.
kernelName of the kernel image, folowed by its parameters. The / doesn't represent the file system root, but the one of (hd0,0), so /boot/vmlinuz...
root(hdx, y)All the file accesses will be from this partition (explained below). Here, hd0,0 represent the first partition of the first disk detected by the BIOS. It's the /boot partition
rootnoverifythe specified root, not mounted by GRUB (it doesn't support NTFS)
timeoutTimeout before default boot
title xxxxStart of a section, entry in GRUB menu

Installation

GRUB configuration can be found in /etc/grub.conf or /boot/grub/menu.lst (symbolic link). GRUB can be install on the MBR (Master Boot Record, 512 first bits of a disk) or PBR (Partition Boot Record, 512 first bits of a partistion).
To install or re-install GRUB - in case of a corrupted MBR, for example on /dev/sda -, use:
#/sbin/grub-install /dev/sda

Start and Edit

Options on the GRUB menu
  • e: edit the line ( adding parameters to the kernel or init)
  • d: delete a line
  • o: add a line
  • b: start the image
If you press Esc there are a grub interpreter available.

Friday, July 21, 2017

Postgres SQL: pg_dump / pg_restore

Backup a specific table:
pg_dump --table TABLENAME -U postgres dbName -f /home/postgres/TABLENAME.sql


If there is a table with the same name in another schema, use the --schema SCHEMANAME option