úterý 21. března 2023

Rescan sata port (hot-swap)

Short:

First: identify and delete the old drive (identify HCTL, which is Host:Channel:Target:Lun (viz ))

$ lsscsi
[0:0:0:0]    cd/dvd  HL-DT-ST BD-RE  BH10LS30  1.02  /dev/sr0
[1:0:0:0]    disk    ATA      APPLE SSD TS256C 0201  /dev/sdd
[2:0:0:0]    disk    ATA      WDC WD6002FRYZ-0 1M03  /dev/sdb
[3:0:0:0]    disk    ATA      WDC WD5001F9YZ-0 1E03  /dev/sdc
[N:0:1:1]    disk    WDC PC SN520 SDAPNUW-512G-1002__1          /dev/nvme0n1
$ lsscsi -g
[0:0:0:0]    cd/dvd  HL-DT-ST BD-RE  BH10LS30  1.02  /dev/sr0   /dev/sg0
[1:0:0:0]    disk    ATA      APPLE SSD TS256C 0201  /dev/sdd   /dev/sg1
[2:0:0:0]    disk    ATA      WDC WD6002FRYZ-0 1M03  /dev/sdb   /dev/sg2
[3:0:0:0]    disk    ATA      WDC WD5001F9YZ-0 1E03  /dev/sdc   /dev/sg3
[N:0:1:1]    disk    WDC PC SN520 SDAPNUW-512G-1002__1          /dev/nvme0n1  -  
$ lsblk -o NAME,MODEL,HCTL
NAME             MODEL                          HCTL
sdb              WDC WD6002FRYZ-01WD5B1         2:0:0:0
└─sdb1                                          
  └─data-bigdata                                
sdc              WDC WD5001F9YZ-09YUWL1         3:0:0:0
└─sdc1                                          
  └─data-bigdata                                
sdd              APPLE SSD TS256C               1:0:0:0
sr0              HL-DT-ST BD-RE BH10LS30        0:0:0:0

and also:

readlink /sys/block/sdX

To find the physical SATA port number, add one to the given host number.

2:0:0:0 -> H=2, sdb == ata3
 

Or use this command:

# find -L /sys/bus/pci/devices/*/ata*/host*/target* -maxdepth 3 -name "sd*" 2>/dev/null |\
egrep block |egrep --colour '(ata[0-9]*)|(sd.*)'
/sys/bus/pci/devices/0000:00:18.0/ata1/host0/target0:0:0/0:0:0:0/block/sda
/sys/bus/pci/devices/0000:00:18.0/ata2/host1/target1:0:0/1:0:0:0/block/sdb
/sys/bus/pci/devices/0000:00:18.0/ata3/host2/target2:0:0/2:0:0:0/block/sdc
  ...   

As a first step, the old drive has to be deleted (see), and (see):

echo 1 > /sys/block/sda/device/delete

Then rescan the host bus:

echo "- - -" >/sys/class/scsi_host/host<n>/scan

or

for i in /sys/class/scsi_host/host* ; do echo "- - -" > $i/scan ; done

also here.

pátek 3. března 2023

Debian 11

Staticka IP adresa

(pred  systemctl restart networking je obcas nutne rucne smazat IP adresy zarizeni, jinak se zmeny v /etc/network/interfaces neprojevi)


Aktivace rc.local

(podle https://blog.wijman.net/enable-rc-local-in-debian-bullseye/ )

Create a file /etc/rc.local

#!/bin/sh
  # ...
  # By default this script does nothing.
  /etc/rc.firewall
  touch /var/lock/subsys/local
  exit 0
  
chmod +x /etc/rc.local

Then we need to reload the systemd manager configuration:

systemctl daemon-reload

Then we start the rc-local daemon:

systemctl start rc-local

And then we check the status of rc-local to confirm it ran OK:


systemctl status rc-local 

Pokud definice sluzby chybi: (podle https://www.cyberciti.biz/faq/how-to-enable-rc-local-shell-script-on-systemd-while-booting-linux-system/

[Unit]
Description=/etc/rc.local
ConditionPathExists=/etc/rc.local
 
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
 
[Install]
WantedBy=multi-user.target

anebo delsi a ukecanejsi soubor (ale musi mit sekci [Install]):

  
# /etc/systemd/system/rc-local.service
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
 
# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target
 
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
StandardOutput=journal+console
StandardError=journal+console
[Install]
WantedBy=multi-user.target
 [Install]
WantedBy=multi-user.target

Iptables firewall

iptables negate: (https://www.cyberciti.biz/faq/iptables-invert-ip-or-protocol-with/) 

Narozdil od starsi implementace, negace se dava pred "option" (viz man iptables): --option ! this is deprecated in favour of ! --option this

--------------