Pages

Tuesday 30 August 2022

Docker post install steps on linux

Create group and add your user to it:

sudo groupadd docker

sudo gpasswd -a $USER docker

Then fix sock permissions:

sudo setfacl --modify user:<user name or ID>:rw /var/run/docker.sock




Monday 13 April 2020

Change linux hostname Cent OS/RHEL/Oracle Linux (proper way)

While requesting linux virtual machine at a vps provider I forgot to set the hostname I wanted it to have. As a result it got a default hostname which was a combination of date and time. Following google findings I changed the hostname in /etc/hosts and by executing hostname NEW_HOSTNAME. I tried hostnamectl set-hostname NEW_HOSTNAME too. That didn't work! I didn't have any other choice as going to the documentation. Then I realised I should have set the type of hostname I am setting up. Quick note from docs:

The static (configured) host name is the one configured in /etc/hostname or a similar file. It is chosen by the local user. It is not always in sync with the current host name as returned by the gethostname() system call. If no host name is configured this property will be the empty string. Setting this property to the empty string will remove /etc/hostname. This hostname should be an internet-style hostname, 7bit ASCII, no special chars/spaces, lower case.

The transient (dynamic) host name is the one configured via the kernel's sethostbyname(). It can be different from the static hostname in case DHCP or mDNS have been configured to change the name based on network information. This property is never empty. If no host name is set this will default to "localhost". Setting this property to the empty string will reset the dynamic hostname to the static host name. If no static host name is configured the dynamic host name will be reset to "localhost". This hostname should be an internet-style hostname, 7bit ASCII, no special chars/spaces, lower case.

The pretty host name is a free-form UTF8 host name for presentation to the user. UIs should ensure that the pretty hostname and the static hostname stay in sync. I.e. when the former is "Lennart's Computer" the latter should be "lennarts-computer". If no pretty host name is set this setting will be the empty string. Applications should then find a suitable fallback, such as the dynamic hostname.



Here I used static type: hostnamectl set-hostname NEW_HOSTNAME --static

Friday 27 March 2020

Open WRT as local DNS server to speed up internet

1. Set own DNS servers. Do this by adding config options in WAN section in /etc/config/network. Here I use Open DNS

uci set network.wan.dns="208.67.222.222 208.67.220.220"
uci commit
ifup wan

This only adds new servers. If we want to use only them do following:

uci set network.wan.dns="208.67.222.222 208.67.220.220"
uci set network.wan.peerdns=0
uci commit network
ifup wan

Here peerdns=0 means to ignore ISP delivered DNS

2. Force using router as DNS server.

It may happen that the client does not use DHCP but has manually set the IP address or set up another DNS server. DNS queries usually (see note below) are sent to port number 53, so if all the client traffic goes through our router then we can force our router to be used regardless of what the client has set. To do this, route all requests to the destination port 53 / tcp and 53 / udp to your router (assuming: the router has the address 192.168.1.1 and its LAN subnet is 192.168.1.0/24, which is the default OpenWrt configuration).


iptables -t nat -I PREROUTING -s 192.168.1.0/24 -p udp --dport 53 -j DNAT --to 192.168.1.1
iptables -t nat -I PREROUTING -s 192.168.1.0/24 -p tcp --dport 53 -j DNAT --to 192.168.1.1

(this can be added to the /etc/firewall.user file). Please note that your internet provider may also force the use of specific DNS servers, although it usually doesn't. While port 53 is the "standard" DNS service port, it happens that name servers can also listen on other ports. An example is the dnscrypt service which communicates on port 443. In networks using Tor, DNS is usually redirected to the built-in client anonymizing network.

Monday 23 March 2020

Strapi MongoError: not master and slaveOk=false

I tried using Strapi with cloud.mongodb.com and I got an error:

yarn run v1.19.1
$ strapi develop
[2020-03-23T19:00:55.263Z] error An index error happened, it wasn't applied.
        - not master
[2020-03-23T19:00:55.507Z] error An index error happened, it wasn't applied.
        - not master
[2020-03-23T19:00:55.509Z] error An index error happened, it wasn't applied.
        - not master
[2020-03-23T19:00:55.791Z] debug ⛔️ Server wasn't able to start properly.
[2020-03-23T19:00:55.795Z] error MongoError: not master and slaveOk=false

All I was able to find out is that it has something to do with cluster configuration. I didn't see option to set slaveOk parameter anywhere in Strapi documentation. I'm sure there are better solutions to this but still I didn't want to spend too much time on this.

My fix was to add in database.json all 3 hosts within host line:

"host": "xxx-shard-00-00-rxyat.mongodb.net,xxx-shard-00-01-rxyat.mongodb.net,xxx-shard-00-02-rxyat.mongodb.net",

Friday 13 March 2020

Clear Linux available in Clover bootloader

I was struggling to get my Mac OS laptop boot also Clear Linux using Clover EFI loader. Making it tripple boot with Mac OS, Windows 10 and Clear Linux it would require following a sequence.

- First thing is to install Mac OS and make it boot via Clover.
- Second is to install (or restore Windows 10). Here make sure that Clover boots correctly both Mac OS and Windows.
- Third is to install Clear Linux. So create required primary partitions CLR_BOOT, CLR_SWAP and CLR_ROOT and proceed with the installation. When installation is completed make a copy of output from command blkid and reboot to Mac OS.

Now, in Clover Configurator mount EFI partition and load config which you use to boot Mac OS. Next go to GUI section, add new Custom Entry and enter only UUID of the CLR_BOOT partition and name which you want to see in Clover boot menu. When that's done, reboot and check if it worked.

Following pictures are for reference hoping they clearly ilustrate what to put and where.




Thursday 27 February 2020

How to send command to specific pane in tmux

I was looking for a way of launching process in tmux split screen mode where one part of the terminal shows log entries and another starting sequence. I found a script in internet but was having problems locating a pane. So first I had to figure out correct pane locations. To do this execute following command:


tmux list-panes –a

This gave me indication that window id is equal 1 and not 0 as indicated in tmux status bar.

Then it went easy, just go with following bash script:

#!/bin/bash
session="my name"
window=${session}:1
pane=${window}.1
echo $pane
tmux send-keys -t "$pane" C-z 'test cmd 1' Enter
tmux send-keys -t "$pane" 'test cmd 2' Enter

Thursday 20 February 2020

Linux how to check progress of DD

Few days ago I decided to install linux on Lenovo Yoga 1051f which is a Windows 10 tablet. First I wanted to create backup of existing system. This tablet has only 1 micro USB port so I had to use USB hub. I executed DD command for entire disk, that was about 32GB.

dd if=/dev/sdb of=/dev/sdc
After an hour or so I became curious about the progress. I expected this to be quick thing while it was very slow. Probably I should have done something like this:
dd if=/dev/sdb of=/dev/sdc status=progress
Copying was in progress and I didn't want to abort it. After doing some research I found a comment saying that I can open another terminal window and execute kill command there, then terminal where DD is running would show the progress. This indeed worked. In theory this should work too:
sudo kill -USR1 $(pgrep ^dd)

Happy dd-ing!