Posts Tagged ‘ linux

Hetzner VPS: filesystem partitions

Sometimes I need to have separate partitions on VPS in Hetzner.

The simplest way to create a custom disk structure – use Cloud-init script

With commands:

#cloud-config

# we need to disable the initial call to "growpart" as otherwise the first partition would consume
# all space on the dist
#
# The final disk layout is:
# #0    0 - 10GB - ext4 on /
# #1 10GB - 100% - lvm
#
# The reason for this approach is that when using CentOS on Hetzner you cannot use
# the "disk_setup" mechanism from cloud-init, it simply is ignored.

growpart:
  mode: off

runcmd:
  - printf "fix\n" | parted ---pretend-input-tty /dev/sda print        # Fix parted error, first
  - [ parted, "/dev/sda", mkpart, primary, ext2, "10GB", "100%" ]  # create a new partition, starting at 10GB
  - [ parted, "/dev/sda", set, "2", lvm, on ]  # set LVM flag
  - [ growpart, "/dev/sda", "1" ]  # grow first partition to 10GB
  - [ partx, --update, "/dev/sda" ] # reload partition table
  - [ resize2fs, /dev/sda1 ] # resize first partition (/) to 10GB
  - [ pvcreate, "/dev/sda2" ] # create PV on /dev/sda2 (100%-10GB)
  - [ vgcreate, vg1, "/dev/sda2" ] # create VG, adding PV /dev/sda2

repo_update: true
repo_upgrade: all

packages:
  - lvm2  # missing in the Hetzner image

In this example, we have 10Gb for / and empty disk /dev/sdb

i915 0000:00:02.0: Device initialization failed (-12)

After upgrading the kernel to a newer kernel, OS won’t boot with a stacked message

pci 0000 : 00 : 07.0 : DPC : RP PIO log size 0 is invalid 
xhci_hcd 0000 : 00 : 0d.0 : can't setup : -12 
xhci hcd 0000 : 00 : 0d.0 : init 0000 : 00 : 0d.0 fail , -12 
thunderbolt 0000 : 00 : 0d.2 : failed to determine connection manager , aborting 
xhci hcd 0000 : 00 : 14.0 : can't setup : -12 
xhci_hcd 0000 : 00 : 14.0 : init 0000 : 00 : 14.0 fail , -12 
1801_smbus . 0000 : 00 : 1f.4 : Transaction timeout 
1801_smbus 0000 : 00 : 1f.4 : Failed terminating the transaction 
1801_smbus 0000 : 00 : 1f.4 : SMBus is busy , can't use it ! 
i915 0000 : 00 : 02.0 : [ drm ] * ERROR * Scratch setup failed 
i915 0000 : 00 : 02.0 : Device initialization failed ( -12 )
Read more

WireGuard on Kernel 5.6. Quick start

cd /tmp
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.6/linux-headers-5.6.0-050600_5.6.0-050600.202003292333_all.deb
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.6/linux-headers-5.6.0-050600-generic_5.6.0-050600.202003292333_amd64.deb
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.6/linux-image-unsigned-5.6.0-050600-generic_5.6.0-050600.202003292333_amd64.deb
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.6/linux-modules-5.6.0-050600-generic_5.6.0-050600.202003292333_amd64.deb

Install all downloaded deb’s

dpkg -i *.deb

Reboot server/PC by command reboot

After startup check the kernel version^

uname -a
Linux test-srv 5.6.0-050600-generic #202003292333 SMP Sun Mar 29 23:35:58 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Test Wireguard on server

ip link add dev wg0 type wireguard
ip address add dev wg0 192.168.2.1/24
#get current state:
ip a s wg0
--
3: wg0: <POINTOPOINT,NOARP> mtu 1420 qdisc noop state DOWN group default qlen 1000
    link/none 
    inet 192.168.2.1/24 scope global wg0
       valid_lft forever preferred_lft forever

Add repository for ubuntu 18.04

add-apt-repository ppa:wireguard/wireguard 
apt-get update
apt-get install wireguard-tools resolvconf

Make some changes to Firewall on server

# to enable kernel relaying/forwarding ability on bounce servers
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
echo "net.ipv4.conf.all.proxy_arp = 1" >> /etc/sysctl.conf
sudo sysctl -p /etc/sysctl.conf

# to add iptables forwarding rules on bounce servers
iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wg0 -o wg0 -m conntrack --ctstate NEW -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o eth0 -j MASQUERADE

Simple script for generating key pairs and base cofigs for server and client

#!/bin/bash

HOST=wg.reverse.org.ua
PORT=32001
S_IP=192.168.2.1/24
C_IP=192.168.2.3/32

#create Server key
`wg genkey | tee wg-s-private.key | wg pubkey > wg-s-public.key`
#create Client key
`wg genkey | tee wg-c-private.key | wg pubkey > wg-c-public.key`

S_PRIV_KEY=`cat wg-s-private.key`
S_PUB_KEY=`cat wg-s-public.key`
C_PRIV_KEY=`cat wg-c-private.key`
C_PUB_KEY=`cat wg-c-public.key`


cat >wg0.server <<EOF
[Interface]
Address = ${S_IP}
ListenPort = ${PORT}
PrivateKey = ${S_PRIV_KEY}
DNS = 1.1.1.1,8.8.8.8

[Peer]
# Name = notebook
PublicKey = ${C_PUB_KEY}
AllowedIPs = ${C_IP}
EOF

cat >wg0.client <<EOF
[Interface]
# Name = laptop
Address = ${C_IP}
PrivateKey = ${C_PRIV_KEY}
DNS = 1.1.1.1,8.8.8.8
# If you have additional local networks, add static routes for it
#PostUp = ip route add 10.97.0.0/16 via 10.0.1.1; 
#PreDown = ip route delete 10.97.0.0/16

[Peer]
Endpoint = ${HOST}:${PORT}
PublicKey = ${S_PUB_KEY}
# routes traffic to itself and entire subnet of peers as bounce server
AllowedIPs = ${S_IP},0.0.0.0/0,::/0
PersistentKeepalive = 25

EOF

Or download here:

Put wg0.server as /etc/wireguard/wg0.conf on Server side and wg0.client on Client side in the same place

Startup interface on machines

wg-quick up wg0

For Android clients you can use config file as QR code

qrencode -t ansiutf8 < wg0.client

ESP8266 first launch in Linux Mint

esp8266-01 pin

esp8266-01 pin


For flashing firmware you need connect GPIO0 to GND and CH_PD to VCC
I have this TTL converter

Bus 003 Device 026: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

But they have 5v output, so i used 5v to 3.3v converter

5v-to-3.3v

5v-to-3.3v

Prepare notebook for flashing
Go to https://github.com/themadinventor/esptool
and download esptool

wget https://github.com/themadinventor/esptool/archive/master.zip

install Python pip

apt-get -y install python-pip

Inzip our master.zip

unzip esptool-master.zip

Run installing dependency

python setup.py install

Read more

Git: запомнить пароль на день

Чтобы в течении рабочего дня не воодить постоянно пароль при доступе в Git в версии 1.7.9 и выше появилась возможность кеширования введенных данных

git config --global credential.helper cache

это заставит держать данные авторизации в памяти
По умолчанию 15минут.
Но можно выставить свое время
Read more

Zentyal Server

Щоб не забути погратись:

Zentyal (раніше відомий під ім’ям eBox Platform) — серверний дистрибутив Linux, побудований на пакетній базі Ubuntu LTS з довготривалою підтримкою, і орієнтований на створення серверів для обслуговування локальних мереж підприємств середнього та малого бізнесу. Zentyal постачається як у вигляді окремого установного Live-дистрибутиву, так і у вигляді набору пакунків для Ubuntu.

Сирцевий код проекту доступний на умовах ліцензії GNU General Public License, а також (частково) під різними власницькими угодами. Zentyal є власністю і спонсорується іспанською комерційною компанією eBox Technologies SL, яка володіє авторськими правами на кодову базу. Примітно, що розробка дистрибутива ведеться у співпраці з проектом Ubuntu і, починаючи з випуску Ubuntu 12.04, пакунки з компонентами Zentyal постачаються у штатному репозиторії Universe.

Керування всіма аспектами роботи дистрибутива проводиться через веб-інтерфейс, в рамках якого об’єднано близько 40 різних модулів для керування мережею, мережевими сервісами, офісним сервером та компонентами інфраструктури підприємства. Розвиток проекту орієнтовано на створення відкритої альтернативи продуктам для управління мережевою інфраструктурою підприємства від компанії Microsoft, таким як Windows Small Business Server, Windows Server, Microsoft Exchange, Microsoft Forefront.

(c) http://uk.wikipedia.org/wiki/Zentyal

Забавный traceroute

Отправка трасировки

traceroute 216.81.59.173 -m 100

вывод:
Read more

При выполнении mysqldump такая ошибка: Warning: Skipping the data of table mysql.event

Перестал отрабпдывать mysqldump на более свежем mysql, вываливается с таким warning

-- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly

Утвеждая, что не нужно бэкапить таблицу mysql.event
Эта таблица появилась с версии Mysql 5.1.6 . В ней находится расписание всяких действий самого демона.
Read more

Быстро удалить много миллионов файлов из директории

rsync -p -a --delete --dry-run --verbose --exclude-from 'niht' empty/ /var/log/

Обновление ядра в Linux Mint

На дефолтном ядре 3.11 не захотел взлетать мой Wi-Fi
dmesg:

....
[ 396.531946] ieee80211 phy0: rt2x00queue_flush_queue: Warning - Queue 2 failed to flush
....

Сетевка:

03:00.0 Network controller: Ralink corp. RT3290 Wireless 802.11n 1T/1R PCIe

Судя по bug-треккеру на ядре 3.12 токого нет.
Обновим )
Read more

Узнать внешний ip-адрес, находясь за NATом, из консоли bash

По некоторым причинан нужно узнать свой внешний ip-адрес находясь за NAT. Через браузер это сделать легко: открываем Гуголь(Яндекс, Бинг) и пишем “what is my ip” кликаем в понравившееся и готово.
А вот когда есть только консоль bash подход иной. Хотя можно и с помощью Links зайти в поисковик.
Варианты
Read more