Archive for the Linux Category

Jan 22 2021

KVM – create new virtual network

Create new bridge

sudo ip link add <bridge-name> type bridge

Add interface to bridge

sudo ip link set <ethX> up
sudo ip link set <ethX> master <bridge-name>

Add IP address to bridge and bring it up

sudo ip address add dev <bridge-name> 192.168.0.90/24

sudo ip link set dev <bridge-name> up

 

Create file bridged-network.xml

<network>
    <name>bridged-network</name>
    <forward mode="bridge" />
    <bridge name="<bridge-name>" />
</network>

Add bridged-network to our KVM

sudo virsh net-define bridged-network.xml

 

Activate network and set autostart

sudo virsh net-start bridged-network 
sudo virsh net-autostart bridged-network

Verify

virsh net-list --all
Jan 22 2021

KVM – Migrate VM to another host

  1. copy the VM’s disks from /var/lib/libvirt/images on src host to the same dir on destination host
  2. on the source host run virsh dumpxml VMNAME > domxml.xml and copy this xml to the destination host
  3. on the destination host run virsh define domxml.xml
  4. start the VM.
  • If the disk location differs, you need to edit the xml’s devices/disk node to point to the image on the destination host
  • If the VM is attached to custom defined networks, you’ll need to either edit them out of the xml on the destination host or redefine them as well
    1. On source machine virsh net-dumpxml NETNAME > netxml.xml
    2. copy netxml.xml to target machine
    3. On target machine virsh net-define netxml.xml && virsh net-start NETNAME & virsh net-autostart NETNAME
Jan 8 2021

resize img size for QEMU / KVM

STOP VM !

Add +5G do disk

qemu-img resize chr-7.2.img +5G

Change disk size to 20G

qemu-img resize chr-7.2.img 20G

This example will convert a raw image file named image.img to a qcow2 image file.

qemu-img convert -f raw -O qcow2 image.img image.qcow2

Rescan resized partition

partprobe /dev/vdb

or

growpart /dev/vdb 1

Resize partition

resize2fs /dev/vdb1

Useful commands

virsh destroy vm_name
virsh list
virsh edit vm_name

Set CPU resources

virsh vcpucount <vm_name>
virsh setvcpus <vm_name> <max-number-of-CPUs> --maximum --config
virsh setvcpus <vm_name> <number-of-CPUs> --config
virsh setvcpus <vm_name> <number-of-CPUs> --live
Aug 8 2020

Mount partition and chroot in rescue mode

Run linux from Linux Live (debian.ubuntu, slackware tec.)

Determine what is your main partition

fdisk -l

Example output:

Disk /dev/md2: 9.77 GiB, 10495328256 bytes, 20498688 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/md3: 221.88 GiB, 238236860416 bytes, 465306368 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/md1: 9.77 GiB, 10495328256 bytes, 20498688 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/md0: 3.91 GiB, 4203020288 bytes, 8209024 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

create mount point and mount root partition

mkdir /mnt/md0

mount /dev/md0 /mnt/md0

Mount the necessary file system directories by running the following commands:

mount -t proc /proc /mnt/md0/proc

mount –rbind /sys /mnt/md0/sys

mount –rbind /dev /mnt/md0/dev

Mount /usr and /var partition if necessary

mount /dev/md1 /mnt/md0/usr

mount /dev/md2 /mnt/md0/var

Chroot to md0

chroot /mnt/md0

Dec 21 2018

Wrong time when booting Linux Mint and Windows 10

timedatectl set-local-rtc 1
Nov 16 2018

nvidia on linux – new kernel

If you installed a new kernel, it is possible to even reconfigure the kernel module with the new driver. To do this, run the following command in the terminal:

sudo dpkg-reconfigure nvidia-390

Sep 14 2018

force debug on CakePHP

add forceEnable config into your config/bootstrap.php

if (Configure::read('debug')) {
    Configure::write('DebugKit', ['forceEnable' => true]);
    Plugin::load('DebugKit', ['bootstrap' => true]);
}

in config/app.php
in option "Datasources": create new sub option like this:
'debug_kit' => [
        'className' => 'Cake\Database\Connection',
        'driver' => 'Cake\Database\Driver\Mysql',
        'persistent' => false,
        'host' => DB_HOST,
        'port' => DB_PORT,
        //'port' => 'non_standard_port_number',
        'username' => DB_ACC,
        'password' => DB_PASS,
        'database' => DB_NAME,
        //'encoding' => 'utf8mb4',
        'timezone' => 'UTC',
        'flags' => [],
        'cacheMetadata' => true,
        'log' => false,'quoteIdentifiers' => false,
        'url' => env('DATABASE_URL', null),
    ]
upgrading debugKit
composer require --dev cakephp/debug_kit "~3.16.6"

loading debugKit
bin/cake plugin load DebugKit

Jul 19 2018

Certbot free SSL certs

For apache

sudo certbot –authenticator webroot –installer apache –webroot-path <path to served directory> -d <domain>

0 0,12 * * * /opt/certbot/bin/python -c ‘import random; import time; time.sleep(random.random() * 3600)’ && /usr/bin/certbot renew -q

just get a certificate with apache running

sudo certbot certonly --apache

just get a certificate (stop apache first)

sudo certbot certonly --standalone

just get a certificate on Slackware

sudo certbot certonly --apache --apache-server-root /etc/httpd --apache-vhost-root /etc/httpd/sites-enabled --apache-challenge-location /etc/httpd -d rotmanka.pl,www.rotmanka.pl

revoke a cetificate

sudo certbot revoke --cert-path /etc/letsencrypt/live/rotmanka.pl/fullchain.pem

Saving debug log to /var/log/letsencrypt/letsencrypt.log

Would you like to delete the certificate(s) you just revoked, along with all
earlier and later versions of the certificate?

(Y)es (recommended)/(N)o:

Sep 30 2017

Raspberry

  • sudo aptitude install debian-keyring debian-archive-keyring
  • Modify the file /etc/apt/sources.list – change “wheezy” to “jessie” in the first line, so it reads “deb
  • http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi”

  • Modify the file /etc/apt/sources.list.d/raspi.list – change “wheezy” to “jessie” in the first line and add “ ui” to the end of that line, so it reads “deb http://archive.raspberrypi.org/debian jessie main ui”
  • Create the directory /home/pi/.config/autostart by typing “mkdir /home/pi/.config/autostart” in a terminal. (Note the . in front of config.)
  • Type “sudo apt-get update” in a terminal to update the apt index files.
  • Type “sudo apt-get dist-upgrade” to start the upgrade process – this will take a couple of hours. Whenever prompted to update a file during this process, choose the Y option to accept the new file; if you don’t want to be bothered with these prompts, then call apt-get with the -y option – “sudo apt-get -y dist-upgrade”.
Jul 22 2016

postfixadmin – zmiana hasła administratora

doveadm pw -s MD5-CRYPT -p password | sed 's/{MD5-CRYPT}//'
update admin set password=’CRYPTED PASSWORD’ where username=’USERNAME’;