Posts Tagged Linux

Jan 28 2022

To recursively give directories read&execute privileges:

find /path/to/base/dir -type d -exec chmod 755 {} +

To recursively give files read privileges:

find /path/to/base/dir -type f -exec chmod 644 {} +

Or, if there are many objects to process:

chmod 644 $(find /path/to/base/dir -type f)
chmod 755 $(find /path/to/base/dir -type d)

Find files with permissions

find /path -perm 755

Change directories permissions from 750 to 755

chmod 755 $(find /path -type d -perm 750)

Change files permissions from 740 to 644

chmod 644 $(find /path -type f -perm 740)

 
Jan 14 2022

.htaccess if statement

<If “%{REMOTE_ADDR} == ‘123.123.123.123’ || %{REMOTE_ADDR} == ‘456.456.456.456’”>

Options +Indexes

</If>

<Else>

Options -Indexes

</Else>

Dec 12 2021

resize RAID partitions

Ensure that the RAID array is consistent and synchronized by entering

cat /proc/mdstat

If your RAID array is still synchronizing according to the output of this command, you must wait until synchronization is complete before continuing.

sudo mdadm /dev/md0 --fail /dev/sda1 --remove /dev/sda1

To succeed, both the fail and remove actions must be specified.

Increase the size of the partition, using a disk partitioner

Re-add the partition to the RAID array. For example, to add /dev/sda1

sudo mdadm -a /dev/md0 /dev/sda1

….

Wait until the RAID is synchronized and consistent before continuing with the next partition.

Repeat these steps for each of the remaining component devices in the array. Ensure that you modify the commands for the correct component partition.

If you get a message that tells you that the kernel could not re-read the partition table for the RAID, you must reboot the computer after all partitions have been resized to force an update of the partition table.

Remove second disk’s paritions from the RAID array:

sudo mdadm /dev/md0 --fail /dev/sda1 --remove /dev/sdb1
sudo mdadm /dev/md1 --fail /dev/sda5 --remove /dev/sdb5
sudo mdadm /dev/md2 --fail /dev/sda6 --remove /dev/sdb6
sudo mdadm /dev/md3 --fail /dev/sda7 --remove /dev/sdb7

Check the size of the array and the device size known to the array by entering

sudo mdadm -D /dev/md0 | grep -e "Array Size" -e "Dev Size"

Increase the size of the array to the maximum available size by entering

sudo mdadm --grow /dev/md0 -z max --assume-clean

The array uses any space that has been added to the devices, but this space will not be synchronized. This is recommended for RAID 1 because the synchronization is not needed. It can be useful for other RAID levels if the space that was added to the member devices was pre-zeroed.

Recheck the size of your array and the device size known to the array by entering

sudo mdadm -D /dev/md0 | grep -e "Array Size" -e "Dev Size"

If your array was not resized as you expected, you must reboot, then try this procedure again.

You can increase the size of the file system to the maximum space available or specify an exact size. When specifying an exact size for the file system, ensure that the new size satisfies the following conditions:

  • The new size must be greater than the size of the existing data; otherwise, data loss occurs.
  • The new size must be equal to or less than the current RAID size because the file system size cannot extend beyond the space available.

Increase the size of the partition on second disk, using a disk partitioner

Re-add the partition to the RAID array. For example, to add /dev/sdb1..x enter:

sudo mdadm -a /dev/md0 /dev/sdb1
sudo mdadm -a /dev/md1 /dev/sdb5
sudo mdadm -a /dev/md2 /dev/sdb6
sudo mdadm -a /dev/md3 /dev/sdb7

Resize RAID partition to max size

sudo resize2fs -p /dev/md0
sudo resize2fs -p /dev/md1
sudo resize2fs -p /dev/md2
sudo resize2fs -p /dev/md3

WHEN ALL PARTITIONS ARE REBUILDED run:

mdadm --detail --scan >> /etc/mdadm.conf

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’;