Linux - Disks and Filesystems and OpenWRT: Difference between pages

From Smithnet Wiki
(Difference between pages)
Jump to navigation Jump to search
 
 
Line 1: Line 1:
== Regulatory Domains ==


== iSCSI ==
iw reg set GB
iw reg get


* Block storage provider: iSCSI Target
Regulatory domains defined in:
* Storage client: iSCSI Initiator
  /lib/firmware/regulatory.db
* Dynamic Discovery: Initiator sends 'SendTargets' request to a single IP/port and if the target listens on multiple names and addresses, all of them are sent in a form of TargetName and TargetAddress (IP:port#).
* See [https://en.wikipedia.org/wiki/ISCSI here] for background and IQN naming.


=== Target ===
* [https://git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git Regulatory Database Github]


* Install package (and dependencies: targetcli
See [https://openwrt.org/docs/guide-user/network/wifi/wifi_countrycode here] for explanation of format.
* Choose/create local area for disk images: /iscsi_disks


Start admin utility:
To build:
targetcli
* Install: python-m2crypro
/> cd /backstores/fileio
* Edit db.txt as required
/backstores/fileio> create disk01 /iscsi_disks/disk01.img 10G
* python db2bin.py regulatory.db db.txt
/backstores/fileio> cd /iscsi
/iscsi> create iqn.2000-01.com.example:storage.target01
/iscsi> cd iqn.2000-01.com.example:storage.target01/tpg1/luns
/iscsi/iqn.20...t01/tpg1/luns> create /backstores/fileio/disk01
/iscsi/iqn.20...t00/tpg1/luns> cd ../acls
/iscsi/iqn.20...t00/tpg1/acls> create iqn.2000-01.com.example:initiator01
/iscsi/iqn.20...t00/tpg1/acls> cd iqn.2000-01.com.example:initiator01
/iscsi/iqn.20...an-server01> set auth userid=someuser
/iscsi/iqn.20...an-server01> set auth password=somepass
exit


Other commands within targetcli:
== Channels ==
ls
delete [object]
help


systemctl enable target
Taken from output of:
  systemctl start target
  iw list


If necessary, open firewall for 3260:
=== 2.4 GHz ===
firewall-cmd --add-service=iscsi-target --permanent
firewall-cmd --reload


See also [https://www.lisenet.com/2016/iscsi-target-and-initiator-configuration-on-rhel-7/ here]
CA
* '''2412 MHz [1] (30.0 dBm)'''
* 2417 MHz [2] (30.0 dBm)
* 2422 MHz [3] (30.0 dBm)
* 2427 MHz [4] (30.0 dBm)
* 2432 MHz [5] (30.0 dBm)
* 2437 MHz [6] (30.0 dBm)
* 2442 MHz [7] (30.0 dBm)
* 2447 MHz [8] (30.0 dBm)
* 2452 MHz [9] (30.0 dBm)
* 2457 MHz [10] (30.0 dBm)
* 2462 MHz [11] (30.0 dBm)
* 2467 MHz [12] (disabled)
* 2472 MHz [13] (disabled)
* 2484 MHz [14] (disabled)


=== Initiator ===
IN, SA
* 2412 MHz [1] (20.0 dBm)
* 2417 MHz [2] (20.0 dBm)
* 2422 MHz [3] (20.0 dBm)
* 2427 MHz [4] (20.0 dBm)
* 2432 MHz [5] (20.0 dBm)
* 2437 MHz [6] (20.0 dBm)
* 2442 MHz [7] (20.0 dBm)
* 2447 MHz [8] (20.0 dBm)
* 2452 MHz [9] (20.0 dBm)
* 2457 MHz [10] (20.0 dBm)
* 2462 MHz [11] (20.0 dBm)
* 2467 MHz [12] (20.0 dBm)
* 2472 MHz [13] (20.0 dBm)
* 2484 MHz [14] (disabled)


Install package: iscsi-initiator-utils
TW
* 2412 MHz [1] (24.0 dBm)
* 2417 MHz [2] (24.0 dBm)
* 2422 MHz [3] (24.0 dBm)
* 2427 MHz [4] (24.0 dBm)
* 2432 MHz [5] (24.0 dBm)
* 2437 MHz [6] (24.0 dBm)
* 2442 MHz [7] (24.0 dBm)
* 2447 MHz [8] (24.0 dBm)
* 2452 MHz [9] (24.0 dBm)
* 2457 MHz [10] (24.0 dBm)
* 2462 MHz [11] (24.0 dBm)
* 2467 MHz [12] (disabled)
* 2472 MHz [13] (disabled)
* 2484 MHz [14] (disabled)


In /etc/iscsi/initiatorname.iscsi specify the iSCSI target:
UK
InitiatorName=iqn.2000-01.com.example:initiator01
* 2412 MHz [1] (20.0 dBm)
* 2417 MHz [2] (20.0 dBm)
* 2422 MHz [3] (20.0 dBm)
* 2427 MHz [4] (20.0 dBm)
* 2432 MHz [5] (20.0 dBm)
* 2437 MHz [6] (20.0 dBm)
* 2442 MHz [7] (20.0 dBm)
* 2447 MHz [8] (20.0 dBm)
* 2452 MHz [9] (20.0 dBm)
* 2457 MHz [10] (20.0 dBm)
* '''2462 MHz [11] (20.0 dBm)'''
* 2467 MHz [12] (20.0 dBm)
* 2472 MHz [13] (20.0 dBm)
* 2484 MHz [14] (disabled)


In /etc/iscsi/iscsid.conf:
=== 5 GHz ===
node.session.auth.authmethod = CHAP
node.session.auth.username = username
node.session.auth.password = password


Discover target:
CA
# iscsiadm -m discovery -t sendtargets -p san-server01
* 5180 MHz [36] (23.0 dBm)
san-server01:3260,1 iqn.2000-01.com.example:storage.target01
* 5200 MHz [40] (23.0 dBm)
* 5220 MHz [44] (23.0 dBm)
* 5240 MHz [48] (23.0 dBm)
* 5260 MHz [52] (24.0 dBm) (radar detection)
* 5280 MHz [56] (24.0 dBm) (radar detection)
* 5300 MHz [60] (24.0 dBm) (radar detection)
* 5320 MHz [64] (24.0 dBm) (radar detection)
* 5500 MHz [100] (24.0 dBm) (radar detection)
* 5520 MHz [104] (24.0 dBm) (radar detection)
* 5540 MHz [108] (24.0 dBm) (radar detection)
* 5560 MHz [112] (24.0 dBm) (radar detection)
* 5580 MHz [116] (24.0 dBm) (radar detection)
* 5600 MHz [120] (disabled)
* 5620 MHz [124] (disabled)
* 5640 MHz [128] (disabled)
* 5660 MHz [132] (24.0 dBm) (radar detection)
* 5680 MHz [136] (24.0 dBm) (radar detection)
* 5700 MHz [140] (24.0 dBm) (radar detection)
* 5720 MHz [144] (24.0 dBm) (radar detection)
* 5745 MHz [149] (30.0 dBm)
* 5765 MHz [153] (30.0 dBm)
* 5785 MHz [157] (30.0 dBm)
* 5805 MHz [161] (30.0 dBm)
* 5825 MHz [165] (30.0 dBm)
* 5845 MHz [169] (disabled)
* 5865 MHz [173] (disabled)


More info:
IN
iscsiadm -m node -o show
* 5180 MHz [36] (30.0 dBm)
...
* 5200 MHz [40] (30.0 dBm)
* 5220 MHz [44] (30.0 dBm)
* 5240 MHz [48] (30.0 dBm)
* 5260 MHz [52] (24.0 dBm)
* 5280 MHz [56] (24.0 dBm)
* 5300 MHz [60] (24.0 dBm)
* 5320 MHz [64] (24.0 dBm)
* 5500 MHz [100] (24.0 dBm)
* 5520 MHz [104] (24.0 dBm)
* 5540 MHz [108] (24.0 dBm)
* 5560 MHz [112] (24.0 dBm)
* 5580 MHz [116] (24.0 dBm)
* 5600 MHz [120] (24.0 dBm)
* 5620 MHz [124] (24.0 dBm)
* 5640 MHz [128] (24.0 dBm)
* 5660 MHz [132] (24.0 dBm)
* 5680 MHz [136] (24.0 dBm)
* 5700 MHz [140] (24.0 dBm)
* 5720 MHz [144] (24.0 dBm)
* 5745 MHz [149] (30.0 dBm)
* 5765 MHz [153] (30.0 dBm)
* 5785 MHz [157] (30.0 dBm)
* 5805 MHz [161] (30.0 dBm)
* 5825 MHz [165] (30.0 dBm)
* 5845 MHz [169] (30.0 dBm)
* 5865 MHz [173] (30.0 dBm)


Login:
SA
iscsiadm -m node --login
* 5180 MHz [36] (20.0 dBm)
* 5200 MHz [40] (20.0 dBm)
* 5220 MHz [44] (20.0 dBm)
* 5240 MHz [48] (20.0 dBm)
* 5260 MHz [52] (20.0 dBm) (radar detection)
* 5280 MHz [56] (20.0 dBm) (radar detection)
* 5300 MHz [60] (20.0 dBm) (radar detection)
* 5320 MHz [64] (20.0 dBm) (radar detection)
* 5500 MHz [100] (27.0 dBm) (radar detection)
* 5520 MHz [104] (27.0 dBm) (radar detection)
* 5540 MHz [108] (27.0 dBm) (radar detection)
* 5560 MHz [112] (27.0 dBm) (radar detection)
* 5580 MHz [116] (27.0 dBm) (radar detection)
* 5600 MHz [120] (27.0 dBm) (radar detection)
* 5620 MHz [124] (27.0 dBm) (radar detection)
* 5640 MHz [128] (27.0 dBm) (radar detection)
* 5660 MHz [132] (27.0 dBm) (radar detection)
* 5680 MHz [136] (27.0 dBm) (radar detection)
* 5700 MHz [140] (27.0 dBm) (radar detection)
* 5720 MHz [144] (disabled)
* 5745 MHz [149] (disabled)
* 5765 MHz [153] (disabled)
* 5785 MHz [157] (disabled)
* 5805 MHz [161] (disabled)
* 5825 MHz [165] (disabled)
* 5845 MHz [169] (disabled)
* 5865 MHz [173] (disabled)


Confirm session:
TW
iscsiadm -m session -o show
* 5180 MHz [36] (23.0 dBm)
* 5200 MHz [40] (23.0 dBm)
* 5220 MHz [44] (23.0 dBm)
* 5240 MHz [48] (23.0 dBm)
* 5260 MHz [52] (23.0 dBm) (radar detection)
* 5280 MHz [56] (23.0 dBm) (radar detection)
* 5300 MHz [60] (23.0 dBm) (radar detection)
* 5320 MHz [64] (23.0 dBm) (radar detection)
* 5500 MHz [100] (23.0 dBm) (radar detection)
* 5520 MHz [104] (23.0 dBm) (radar detection)
* 5540 MHz [108] (23.0 dBm) (radar detection)
* 5560 MHz [112] (23.0 dBm) (radar detection)
* 5580 MHz [116] (23.0 dBm) (radar detection)
* 5600 MHz [120] (23.0 dBm) (radar detection)
* 5620 MHz [124] (23.0 dBm) (radar detection)
* 5640 MHz [128] (23.0 dBm) (radar detection)
* 5660 MHz [132] (23.0 dBm) (radar detection)
* 5680 MHz [136] (23.0 dBm) (radar detection)
* 5700 MHz [140] (23.0 dBm) (radar detection)
* 5720 MHz [144] (23.0 dBm) (radar detection)
* 5745 MHz [149] (30.0 dBm)
* 5765 MHz [153] (30.0 dBm)
* 5785 MHz [157] (30.0 dBm)
* 5805 MHz [161] (30.0 dBm)
* 5825 MHz [165] (30.0 dBm)
* 5845 MHz [169] (disabled)
* 5865 MHz [173] (disabled)


Confirm new device added (eg sdc):
UK
cat /proc/partitions
* 5180 MHz [36] (23.0 dBm)
* 5200 MHz [40] (23.0 dBm)
* 5220 MHz [44] (23.0 dBm)
* 5240 MHz [48] (23.0 dBm)
* 5260 MHz [52] (20.0 dBm) (radar detection)
* 5280 MHz [56] (20.0 dBm) (radar detection)
* 5300 MHz [60] (20.0 dBm) (radar detection)
* 5320 MHz [64] (20.0 dBm) (radar detection)
* 5500 MHz [100] (26.0 dBm) (radar detection)
* 5520 MHz [104] (26.0 dBm) (radar detection)
* 5540 MHz [108] (26.0 dBm) (radar detection)
* 5560 MHz [112] (26.0 dBm) (radar detection)
* 5580 MHz [116] (26.0 dBm) (radar detection)
* 5600 MHz [120] (26.0 dBm) (radar detection)
* 5620 MHz [124] (26.0 dBm) (radar detection)
* 5640 MHz [128] (26.0 dBm) (radar detection)
* 5660 MHz [132] (26.0 dBm) (radar detection)
* 5680 MHz [136] (26.0 dBm) (radar detection)
* 5700 MHz [140] (26.0 dBm) (radar detection)
* 5720 MHz [144] (26.0 dBm) (radar detection)
* 5745 MHz [149] (20.0 dBm) (radar detection)
* 5765 MHz [153] (20.0 dBm) (radar detection)
* 5785 MHz [157] (20.0 dBm) (radar detection)
* 5805 MHz [161] (20.0 dBm) (radar detection)
* 5825 MHz [165] (20.0 dBm) (radar detection)
* 5845 MHz [169] (20.0 dBm) (radar detection)
* 5865 MHz [173] (20.0 dBm) (radar detection)


Then, partition, format and mount /dev/sdc as normal.
ZA
* 5180 MHz [36] (20.0 dBm)
* 5200 MHz [40] (20.0 dBm)
* 5220 MHz [44] (20.0 dBm)
* 5240 MHz [48] (20.0 dBm)
* 5260 MHz [52] (20.0 dBm) (radar detection)
* 5280 MHz [56] (20.0 dBm) (radar detection)
* 5300 MHz [60] (20.0 dBm) (radar detection)
* 5320 MHz [64] (20.0 dBm) (radar detection)
* '''5500 MHz [100] (30.0 dBm)'''
* 5520 MHz [104] (30.0 dBm)
* 5540 MHz [108] (30.0 dBm)
* 5560 MHz [112] (30.0 dBm)
* '''5580 MHz [116] (30.0 dBm)'''
* 5600 MHz [120] (30.0 dBm)
* 5620 MHz [124] (30.0 dBm)
* 5640 MHz [128] (30.0 dBm)
* 5660 MHz [132] (30.0 dBm)
* 5680 MHz [136] (30.0 dBm)
* 5700 MHz [140] (30.0 dBm)
* 5720 MHz [144] (disabled)
* 5745 MHz [149] (disabled)
* 5765 MHz [153] (disabled)
* 5785 MHz [157] (disabled)
* 5805 MHz [161] (disabled)
* 5825 MHz [165] (disabled)
* 5845 MHz [169] (disabled)
* 5865 MHz [173] (disabled)


Logout of iSCSI (after unmounting used filesystems):
== Devices ==
iscsiadm -m node --logout


== Disk Management ==
=== TP-Link Archer C2600 ===


=== Grub ===
* [https://openwrt.org/toh/tp-link/archer_c2600_v1 Device page]
* 1.4 GHz CPU, 32 MiB flash, 512 MiB RAM
* Currently Installed: 22.03.3


When installing on a RAID 1 mirror for the OS grub boot loader only installs on the first disk, so it that fails you can't boot off the second. To copy loader to the second disk:
=== TP-Link Archer C7 v4 ===


grub> find /grub/stage1
* [https://openwrt.org/toh/tp-link/archer_c7 Device page]
* 775 MHz CPU, 16 MiB flash, 128 MiB RAM
* Currently Installed: 22.03.3


This should find (hd0,0) and (hd1,0) which correspond for /dev/sda and /dev/sdb. Then temporarily make sdb the first disk and install:
=== HooToo TripMate Nano (HT-TM02) ===


device (hd0) /dev/sdb
* [https://openwrt.org/toh/hootoo/tripmate-nano Device page]
root (hd0,0)
* 360 MHz CPU, 8 MiB flash, 32 MiB RAM
setup (hd0)
* Currently Installed: 19.07.10
* Initial installation [https://forum.archive.openwrt.org/viewtopic.php?id=53014 here]
* Can remove kernel PPP packages


=== HD Parameters ===
==== Mode on Startup ====


Show settings/features:
Read status of buttons:
hdparm -I /dev/sda


Test transfer rate:
root@wifi-ht:~# cat /sys/kernel/debug/gpio
  hdparm -t --direct /dev/sda
  gpiochip0: GPIOs 0-21, parent: platform/10000600.gpio, 10000600.gpio:
  gpio-7  (                    |ht-tm02:blue:wlan  ) out lo   
  gpio-10  (                    |reset              ) in  hi   
  gpio-12 (                    |ht-tm02:green:lan  ) out lo   
  gpio-14  (                    |modeswitch          ) in  lo   
root@wifi-ht:~#


Show power management setting:
For modeswitch, "lo" is Wired, "hi" is WiFi position.
hdparm -B /dev/sda


=== MD RAIDs ===
Could also use [https://github.com/jefferyto/openwrt-slide-switch slide-switch] package. Biggest advantage of this is that it triggers at boot time, not just a switch change.
opkg install slide-switch


Create an array of 2 disks in a RAID1 (mirror):
On startup On mode (button) change, copy files from /etc/config/config-wired or config-wireless to /etc/config with:
mdadm --create /dev/md0 -l 1 -n 2 /dev/sdb1 /dev/sdc1
* etc/rc.d/S15config-mode -> /etc/config/config-mode


Monitor status with:
#!/bin/sh
  mdadm --detail /dev/md0
#
  cat /proc/mdstat
# Set mode according to slide switch
#
  CONFIG=/etc/config
  state=$(grep modeswitch /sys/kernel/debug/gpio | sed 's/.*\(lo\|hi\).*/\1/')
case "$state" in
        lo)
                mode="wired"
                ;;
        hi)
                mode="wireless"
                ;;
        *)
                echo "unknown"
                return 1
                ;;
esac
message="Using config mode: $mode"
echo $message
logger $message
config="$CONFIG/config-$mode"
for file in $(ls $config)
do
        echo $file
        cp "$config/$file" $CONFIG
done


Ensure RAID is detected at boot time:
== Package Management ==
mdadm -Es >> /etc/mdadm.conf


Remove a device from an array:
opkg update
  mdadm --remove /dev/md0 /dev/sdb1
opkg list
  opkg list-installed
opkg install blah
opkg remove blah


Fail a drive in an array:
== Reset ==
mdadm --fail /dev/md0 /dev/sdb1


Add a device to an array:
* Controlled by /etc/rc.button/reset
mdadm --add /dev/md0 /dev/sdb1
* Quick press of reset button reboots
* Failsafe (long press) forces network to:
** 192.168.1.1 / 255.255.255.0
** SSH open with root / no password
** "firstboot" command to revert to factory defaults
** Hard factory reset (to 192.168.1.1.): umount /overlay && jffs2reset && reboot now
** "mount_root" to mount root partition


The /etc/cron.weekly/99-raid-check script can sometimes report:
== Configuration and Commands ==
WARNING: mismatch_cnt is not 0 on /dev/md1


The actual mismatch count can be found:
=== Misc ===
cat /sys/block/md1/md/mismatch_cnt


A repair and rebuild can be:
* [https://busybox.net/downloads/BusyBox.html Busybox]
echo repair > /sys/block/md1/md/sync_action
* [https://openwrt.org/docs/guide-user/base-system/uci UCI Configuration System]
echo check > /sys/block/md1/md/sync_action
* Show logging: logread -f
* wifi up


=== Partitioning ===
In /etc/config:
* wireless
* dhcp
* system
* network
* firewall


==== FDisk ====
Custom startup scripts:
* /etc/rc.local


Supports MBR partitions
In /etc:
* sysupgrade.conf


==== Parted ====
=== DHCP ===


Supports MBR and GPT
Custom options may be given per network, eg: for NTP:
* 42, 192.168.1.1


See [https://www.gnu.org/software/parted/manual/html_chapter/parted_2.html#SEC8 Manual]
=== DNS ===


=== LVM ===
* resolv.conf symlinked to /tmp/resolv.conf which points to local dnsmasq service which delivers from its cache or via DNS servers pointed to by proxies resolv.conf.auto (DHCP client updated)
* See also [https://openwrt.org/docs/guide-user/base-system/dns_configuration here]


==== Physical Volumes ====
=== Wifi commands ===


To create a PV out of two partions:
iw phy0 info
  pvcreate /dev/sdc1 /dev/sdd1
iw reg get
  iw reg set GB


To show current PVs:
See other [http://wireless.kernel.org/en/users/Documentation/iw#Scanning iw] commands and [http://git.kernel.org/cgit/linux/kernel/git/linville/wireless-regdb.git/tree/db.txt?id=HEAD Reg Database].
pvscan


==== Volume Groups ====
=== USB and File sharing ===


To create a VG:
Add packages:
  vgcreate vg00 /dev/sd[cd]
  opkg install kmod-usb-core kmod-usb-storage usbutils block-mount luci-app-minidlna


To show all current VGs:
Show device:
  vgscan
  ls /dev/sd*
lsusb -t


To show details of a VG (including free PEs):
Driver USB 1, 2, 3: uhci/ohci, ehci, xhci
vgdisplay vg00


To extend a volume group by adding a new PV:
Show device:
  vgextend vg00 /dev/sde
  # block info /dev/sda1
/dev/sda1: UUID="9814-E49A" LABEL="2" VERSION="FAT16" TYPE="vfat"


To make a volume group available:
Mount FAT32 USB stick:
  vgchange -ay vg00
  /sbin/block mount
cd /mnt/sda1


==== Logical Volumes ====
See also [https://openwrt.org/docs/guide-user/storage/usb-drives here]


To create a new LV:
=== LEDs ===
lvcreate --size 100M vg00 -n lv00
or change --size option to --extents 500 or --extents 60%VG or -l 100%FREE 


eg to create a RAID5 array out of 3 disks (2 data):
* Panel LEDS: [https://openwrt.org/start?id=docs/guide-user/base-system/led_configuration LED Config]
lvcreate -n lv00 --type raid5 -i 2 --extents 100%FREE vg00
* [https://openwrt.org/docs/techref/hardware/port.gpio GPIO]


Show status of LVM RAID:
=== Buttons ===
lvs -a vg00


To rename a LV in VG vg01:
* Panel buttons: [https://openwrt.org/docs/guide-user/hardware/hardware.button Button Config].
lvrename vg00 lvold lvnew


To remove a LV:
procd interface:
lvremove vg00/lv01


To show current LVs:
root@hootoo:/etc/rc.button# ls
  lvscan
  BTN_0    failsafe  power    reset    rfkill
root@hootoo:/etc/rc.button#


== Filesystems ==
scripts need to be named according to the button name, like "BTN_0" or "wps" (see [https://openwrt.org/docs/guide-user/hardware/hardware.button here]). They receive values:
* $BUTTON: Name of button
* $ACTION: "pressed", "timeout" or "released". For released, script returns timeout seconds (for hold down).
* $SEEN: number of seconds


To format with 1% minfree, large file support (see types in /etc/mke2fs.conf), journalling and a label:
root@wifi-ht:/etc/rc.button# cat BTN_0
  mkfs.ext4 -m 1 -T largefile4 -j -L /home /dev/mapper/vg00-lv00
#!/bin/sh
logger "Button $BUTTON: $ACTION (Seen $SEEN)"
return 0
  root@wifi-ht:/etc/rc.button#


To alter the label:
==== C2600 ====
e2label /dev/sda newlabel


To mount at boot time, enter in
Has an additional "lights_toggle":
* /etc/fstab


Or to use XFS on a LV:
[ "${ACTION}" = "released" ] || exit 0
  mkfs.xfs -L /home /dev/mapper/vg0-lv0
led="c2600:white:general"
  device="wifinet3"
logger "Button $ACTION, will toggle Guest Wifi"
echo 1 > /sys/class/leds/$led/brightness
case $(uci get wireless.$device.disabled) in
    0)
        uci set wireless.$device.disabled=1
        logger "Wifi disabled"
    ;;
    1)
        uci set wireless.$device.disabled=0
        logger "Wifi enabled"
    ;;
esac
wifi reload
service network reload
sleep 1
echo 0 > /sys/class/leds/$led/brightness
return 0


== BTRFS ==
=== 6in4 ===


See also [https://btrfs.wiki.kernel.org/index.php/SysadminGuide here]
Requires packages: 6in4 luci-proto-ipv6 and used tunnel from [https://tunnelbroker.net/ Hurricane Electric].
* Restart network
* In LUCI, edit wan6 and change protocol from DHCPv6 to RFC4213
* Set Remote IPv4 address (eg 74.82.46.6)
* Set Local IPv6 address
* Set IPv6 routed prefix (Routed /48)
* Dynamic tunnel
** Tunnel ID
** HE username/password


Create a RAID5 array for data and metadata:
  ping ipv6.google.com
  mkfs.btrfs -L data -d raid5 -m raid5 -f /dev/sdc /dev/sdd /dev/sde


View usage:
Manual Config:
btrfs filesystem usage /data


Look for btrfs filesystems:
  opkg install 6in4
  blkid --match-token TYPE=btrfs


=== Subvolumes ===
uci set network.henet=interface
 
  uci set network.henet.proto=6in4
Create subvolume:
  uci set network.henet.peeraddr=[get IPv4 of HE gateway]
  btrfs subvolume create /data/db
  uci set network.henet.ip6addr='[IPv6 from HE]'
 
  uci set network.henet.tunnelid=[HE tunnel ID]
Info:
  uci set network.henet.username=[HE username]
  btrfs subvolume list .
  uci set network.henet.password='[HE password]'
btrfs subvolume list /data
  uci commit network
btrfs subvolume show /data/db
   
 
  uci set firewall.@zone[1].network='wan henet'
Delete subvolume:
uci commit firewall
  btrfs subvolume delete /data/db
 
  ifup henet
=== Compression ===
  /etc/init.d/firewall restart
 
Mount with compression option in fstab:
  compress=zstd:1
where the algorirm could also be lzo or zlib. Compression level can be increased to 2 or 3
 
Per-file/directory/subvolume compression is also available:
btrfs property get /somefile compression
  btrfs property set /etc compression zlib
 
Degragment:
  btrfs filesystem defragment -r /
 
== Loopback Filesystem ==
 
  dd if=/dev/zero of=loopback.img bs=1024M count=5
  losetup -fP loopback.img
 
To show loopback device(s):
  losetup -a
  losetup -l
 
To delete loopback device:
  losetup -d /dev/loop0
 
Then, create filesystem, eg:
  mkfs.xfs -L backups loopback.img
 
And mount /dev/loop0 (-o loop) as a traditional device. Note: the losetup configuration is lost at restart so can't be added to /etc/fstab for at-boot mounting.
 
== Smarttools ==
 
/etc/smartmontools/smartd.conf
 
Default to scan ATA/SCSI devices and report problems to root:
  DEVICESCAN -H -m root -M exec /usr/libexec/smartmontools/smartdnotify -n standby,10,q
 
Or a specific device, and email an external user:
  /dev/sda -a -o on -S on -s (S/../.././02|L/../../6/03) -m user@domain.com
 
Scan for devices:
smartctl --scan
 
Show detailed information about a device:
smartctl --all /dev/sda

Revision as of 14:30, 9 January 2023

Regulatory Domains

iw reg set GB
iw reg get

Regulatory domains defined in:

/lib/firmware/regulatory.db

See here for explanation of format.

To build:

  • Install: python-m2crypro
  • Edit db.txt as required
  • python db2bin.py regulatory.db db.txt

Channels

Taken from output of:

iw list

2.4 GHz

CA

  • 2412 MHz [1] (30.0 dBm)
  • 2417 MHz [2] (30.0 dBm)
  • 2422 MHz [3] (30.0 dBm)
  • 2427 MHz [4] (30.0 dBm)
  • 2432 MHz [5] (30.0 dBm)
  • 2437 MHz [6] (30.0 dBm)
  • 2442 MHz [7] (30.0 dBm)
  • 2447 MHz [8] (30.0 dBm)
  • 2452 MHz [9] (30.0 dBm)
  • 2457 MHz [10] (30.0 dBm)
  • 2462 MHz [11] (30.0 dBm)
  • 2467 MHz [12] (disabled)
  • 2472 MHz [13] (disabled)
  • 2484 MHz [14] (disabled)

IN, SA

  • 2412 MHz [1] (20.0 dBm)
  • 2417 MHz [2] (20.0 dBm)
  • 2422 MHz [3] (20.0 dBm)
  • 2427 MHz [4] (20.0 dBm)
  • 2432 MHz [5] (20.0 dBm)
  • 2437 MHz [6] (20.0 dBm)
  • 2442 MHz [7] (20.0 dBm)
  • 2447 MHz [8] (20.0 dBm)
  • 2452 MHz [9] (20.0 dBm)
  • 2457 MHz [10] (20.0 dBm)
  • 2462 MHz [11] (20.0 dBm)
  • 2467 MHz [12] (20.0 dBm)
  • 2472 MHz [13] (20.0 dBm)
  • 2484 MHz [14] (disabled)

TW

  • 2412 MHz [1] (24.0 dBm)
  • 2417 MHz [2] (24.0 dBm)
  • 2422 MHz [3] (24.0 dBm)
  • 2427 MHz [4] (24.0 dBm)
  • 2432 MHz [5] (24.0 dBm)
  • 2437 MHz [6] (24.0 dBm)
  • 2442 MHz [7] (24.0 dBm)
  • 2447 MHz [8] (24.0 dBm)
  • 2452 MHz [9] (24.0 dBm)
  • 2457 MHz [10] (24.0 dBm)
  • 2462 MHz [11] (24.0 dBm)
  • 2467 MHz [12] (disabled)
  • 2472 MHz [13] (disabled)
  • 2484 MHz [14] (disabled)

UK

  • 2412 MHz [1] (20.0 dBm)
  • 2417 MHz [2] (20.0 dBm)
  • 2422 MHz [3] (20.0 dBm)
  • 2427 MHz [4] (20.0 dBm)
  • 2432 MHz [5] (20.0 dBm)
  • 2437 MHz [6] (20.0 dBm)
  • 2442 MHz [7] (20.0 dBm)
  • 2447 MHz [8] (20.0 dBm)
  • 2452 MHz [9] (20.0 dBm)
  • 2457 MHz [10] (20.0 dBm)
  • 2462 MHz [11] (20.0 dBm)
  • 2467 MHz [12] (20.0 dBm)
  • 2472 MHz [13] (20.0 dBm)
  • 2484 MHz [14] (disabled)

5 GHz

CA

  • 5180 MHz [36] (23.0 dBm)
  • 5200 MHz [40] (23.0 dBm)
  • 5220 MHz [44] (23.0 dBm)
  • 5240 MHz [48] (23.0 dBm)
  • 5260 MHz [52] (24.0 dBm) (radar detection)
  • 5280 MHz [56] (24.0 dBm) (radar detection)
  • 5300 MHz [60] (24.0 dBm) (radar detection)
  • 5320 MHz [64] (24.0 dBm) (radar detection)
  • 5500 MHz [100] (24.0 dBm) (radar detection)
  • 5520 MHz [104] (24.0 dBm) (radar detection)
  • 5540 MHz [108] (24.0 dBm) (radar detection)
  • 5560 MHz [112] (24.0 dBm) (radar detection)
  • 5580 MHz [116] (24.0 dBm) (radar detection)
  • 5600 MHz [120] (disabled)
  • 5620 MHz [124] (disabled)
  • 5640 MHz [128] (disabled)
  • 5660 MHz [132] (24.0 dBm) (radar detection)
  • 5680 MHz [136] (24.0 dBm) (radar detection)
  • 5700 MHz [140] (24.0 dBm) (radar detection)
  • 5720 MHz [144] (24.0 dBm) (radar detection)
  • 5745 MHz [149] (30.0 dBm)
  • 5765 MHz [153] (30.0 dBm)
  • 5785 MHz [157] (30.0 dBm)
  • 5805 MHz [161] (30.0 dBm)
  • 5825 MHz [165] (30.0 dBm)
  • 5845 MHz [169] (disabled)
  • 5865 MHz [173] (disabled)

IN

  • 5180 MHz [36] (30.0 dBm)
  • 5200 MHz [40] (30.0 dBm)
  • 5220 MHz [44] (30.0 dBm)
  • 5240 MHz [48] (30.0 dBm)
  • 5260 MHz [52] (24.0 dBm)
  • 5280 MHz [56] (24.0 dBm)
  • 5300 MHz [60] (24.0 dBm)
  • 5320 MHz [64] (24.0 dBm)
  • 5500 MHz [100] (24.0 dBm)
  • 5520 MHz [104] (24.0 dBm)
  • 5540 MHz [108] (24.0 dBm)
  • 5560 MHz [112] (24.0 dBm)
  • 5580 MHz [116] (24.0 dBm)
  • 5600 MHz [120] (24.0 dBm)
  • 5620 MHz [124] (24.0 dBm)
  • 5640 MHz [128] (24.0 dBm)
  • 5660 MHz [132] (24.0 dBm)
  • 5680 MHz [136] (24.0 dBm)
  • 5700 MHz [140] (24.0 dBm)
  • 5720 MHz [144] (24.0 dBm)
  • 5745 MHz [149] (30.0 dBm)
  • 5765 MHz [153] (30.0 dBm)
  • 5785 MHz [157] (30.0 dBm)
  • 5805 MHz [161] (30.0 dBm)
  • 5825 MHz [165] (30.0 dBm)
  • 5845 MHz [169] (30.0 dBm)
  • 5865 MHz [173] (30.0 dBm)

SA

  • 5180 MHz [36] (20.0 dBm)
  • 5200 MHz [40] (20.0 dBm)
  • 5220 MHz [44] (20.0 dBm)
  • 5240 MHz [48] (20.0 dBm)
  • 5260 MHz [52] (20.0 dBm) (radar detection)
  • 5280 MHz [56] (20.0 dBm) (radar detection)
  • 5300 MHz [60] (20.0 dBm) (radar detection)
  • 5320 MHz [64] (20.0 dBm) (radar detection)
  • 5500 MHz [100] (27.0 dBm) (radar detection)
  • 5520 MHz [104] (27.0 dBm) (radar detection)
  • 5540 MHz [108] (27.0 dBm) (radar detection)
  • 5560 MHz [112] (27.0 dBm) (radar detection)
  • 5580 MHz [116] (27.0 dBm) (radar detection)
  • 5600 MHz [120] (27.0 dBm) (radar detection)
  • 5620 MHz [124] (27.0 dBm) (radar detection)
  • 5640 MHz [128] (27.0 dBm) (radar detection)
  • 5660 MHz [132] (27.0 dBm) (radar detection)
  • 5680 MHz [136] (27.0 dBm) (radar detection)
  • 5700 MHz [140] (27.0 dBm) (radar detection)
  • 5720 MHz [144] (disabled)
  • 5745 MHz [149] (disabled)
  • 5765 MHz [153] (disabled)
  • 5785 MHz [157] (disabled)
  • 5805 MHz [161] (disabled)
  • 5825 MHz [165] (disabled)
  • 5845 MHz [169] (disabled)
  • 5865 MHz [173] (disabled)

TW

  • 5180 MHz [36] (23.0 dBm)
  • 5200 MHz [40] (23.0 dBm)
  • 5220 MHz [44] (23.0 dBm)
  • 5240 MHz [48] (23.0 dBm)
  • 5260 MHz [52] (23.0 dBm) (radar detection)
  • 5280 MHz [56] (23.0 dBm) (radar detection)
  • 5300 MHz [60] (23.0 dBm) (radar detection)
  • 5320 MHz [64] (23.0 dBm) (radar detection)
  • 5500 MHz [100] (23.0 dBm) (radar detection)
  • 5520 MHz [104] (23.0 dBm) (radar detection)
  • 5540 MHz [108] (23.0 dBm) (radar detection)
  • 5560 MHz [112] (23.0 dBm) (radar detection)
  • 5580 MHz [116] (23.0 dBm) (radar detection)
  • 5600 MHz [120] (23.0 dBm) (radar detection)
  • 5620 MHz [124] (23.0 dBm) (radar detection)
  • 5640 MHz [128] (23.0 dBm) (radar detection)
  • 5660 MHz [132] (23.0 dBm) (radar detection)
  • 5680 MHz [136] (23.0 dBm) (radar detection)
  • 5700 MHz [140] (23.0 dBm) (radar detection)
  • 5720 MHz [144] (23.0 dBm) (radar detection)
  • 5745 MHz [149] (30.0 dBm)
  • 5765 MHz [153] (30.0 dBm)
  • 5785 MHz [157] (30.0 dBm)
  • 5805 MHz [161] (30.0 dBm)
  • 5825 MHz [165] (30.0 dBm)
  • 5845 MHz [169] (disabled)
  • 5865 MHz [173] (disabled)

UK

  • 5180 MHz [36] (23.0 dBm)
  • 5200 MHz [40] (23.0 dBm)
  • 5220 MHz [44] (23.0 dBm)
  • 5240 MHz [48] (23.0 dBm)
  • 5260 MHz [52] (20.0 dBm) (radar detection)
  • 5280 MHz [56] (20.0 dBm) (radar detection)
  • 5300 MHz [60] (20.0 dBm) (radar detection)
  • 5320 MHz [64] (20.0 dBm) (radar detection)
  • 5500 MHz [100] (26.0 dBm) (radar detection)
  • 5520 MHz [104] (26.0 dBm) (radar detection)
  • 5540 MHz [108] (26.0 dBm) (radar detection)
  • 5560 MHz [112] (26.0 dBm) (radar detection)
  • 5580 MHz [116] (26.0 dBm) (radar detection)
  • 5600 MHz [120] (26.0 dBm) (radar detection)
  • 5620 MHz [124] (26.0 dBm) (radar detection)
  • 5640 MHz [128] (26.0 dBm) (radar detection)
  • 5660 MHz [132] (26.0 dBm) (radar detection)
  • 5680 MHz [136] (26.0 dBm) (radar detection)
  • 5700 MHz [140] (26.0 dBm) (radar detection)
  • 5720 MHz [144] (26.0 dBm) (radar detection)
  • 5745 MHz [149] (20.0 dBm) (radar detection)
  • 5765 MHz [153] (20.0 dBm) (radar detection)
  • 5785 MHz [157] (20.0 dBm) (radar detection)
  • 5805 MHz [161] (20.0 dBm) (radar detection)
  • 5825 MHz [165] (20.0 dBm) (radar detection)
  • 5845 MHz [169] (20.0 dBm) (radar detection)
  • 5865 MHz [173] (20.0 dBm) (radar detection)

ZA

  • 5180 MHz [36] (20.0 dBm)
  • 5200 MHz [40] (20.0 dBm)
  • 5220 MHz [44] (20.0 dBm)
  • 5240 MHz [48] (20.0 dBm)
  • 5260 MHz [52] (20.0 dBm) (radar detection)
  • 5280 MHz [56] (20.0 dBm) (radar detection)
  • 5300 MHz [60] (20.0 dBm) (radar detection)
  • 5320 MHz [64] (20.0 dBm) (radar detection)
  • 5500 MHz [100] (30.0 dBm)
  • 5520 MHz [104] (30.0 dBm)
  • 5540 MHz [108] (30.0 dBm)
  • 5560 MHz [112] (30.0 dBm)
  • 5580 MHz [116] (30.0 dBm)
  • 5600 MHz [120] (30.0 dBm)
  • 5620 MHz [124] (30.0 dBm)
  • 5640 MHz [128] (30.0 dBm)
  • 5660 MHz [132] (30.0 dBm)
  • 5680 MHz [136] (30.0 dBm)
  • 5700 MHz [140] (30.0 dBm)
  • 5720 MHz [144] (disabled)
  • 5745 MHz [149] (disabled)
  • 5765 MHz [153] (disabled)
  • 5785 MHz [157] (disabled)
  • 5805 MHz [161] (disabled)
  • 5825 MHz [165] (disabled)
  • 5845 MHz [169] (disabled)
  • 5865 MHz [173] (disabled)

Devices

TP-Link Archer C2600

  • Device page
  • 1.4 GHz CPU, 32 MiB flash, 512 MiB RAM
  • Currently Installed: 22.03.3

TP-Link Archer C7 v4

  • Device page
  • 775 MHz CPU, 16 MiB flash, 128 MiB RAM
  • Currently Installed: 22.03.3

HooToo TripMate Nano (HT-TM02)

  • Device page
  • 360 MHz CPU, 8 MiB flash, 32 MiB RAM
  • Currently Installed: 19.07.10
  • Initial installation here
  • Can remove kernel PPP packages

Mode on Startup

Read status of buttons:

root@wifi-ht:~# cat /sys/kernel/debug/gpio
 gpiochip0: GPIOs 0-21, parent: platform/10000600.gpio, 10000600.gpio:
 gpio-7   (                    |ht-tm02:blue:wlan   ) out lo    
 gpio-10  (                    |reset               ) in  hi    
 gpio-12  (                    |ht-tm02:green:lan   ) out lo    
 gpio-14  (                    |modeswitch          ) in  lo    
root@wifi-ht:~#

For modeswitch, "lo" is Wired, "hi" is WiFi position.

Could also use slide-switch package. Biggest advantage of this is that it triggers at boot time, not just a switch change.

opkg install slide-switch

On startup On mode (button) change, copy files from /etc/config/config-wired or config-wireless to /etc/config with:

  • etc/rc.d/S15config-mode -> /etc/config/config-mode
#!/bin/sh
#
# Set mode according to slide switch
#

CONFIG=/etc/config

state=$(grep modeswitch /sys/kernel/debug/gpio | sed 's/.*\(lo\|hi\).*/\1/')
case "$state" in
        lo)
                mode="wired"
                ;;
        hi)
                mode="wireless"
                ;;
        *)
                echo "unknown"
                return 1
                ;;
esac

message="Using config mode: $mode"
echo $message
logger $message

config="$CONFIG/config-$mode"
for file in $(ls $config)
do
        echo $file
        cp "$config/$file" $CONFIG
done

Package Management

opkg update
opkg list
opkg list-installed
opkg install blah
opkg remove blah

Reset

  • Controlled by /etc/rc.button/reset
  • Quick press of reset button reboots
  • Failsafe (long press) forces network to:
    • 192.168.1.1 / 255.255.255.0
    • SSH open with root / no password
    • "firstboot" command to revert to factory defaults
    • Hard factory reset (to 192.168.1.1.): umount /overlay && jffs2reset && reboot now
    • "mount_root" to mount root partition

Configuration and Commands

Misc

In /etc/config:

  • wireless
  • dhcp
  • system
  • network
  • firewall

Custom startup scripts:

  • /etc/rc.local

In /etc:

  • sysupgrade.conf

DHCP

Custom options may be given per network, eg: for NTP:

  • 42, 192.168.1.1

DNS

  • resolv.conf symlinked to /tmp/resolv.conf which points to local dnsmasq service which delivers from its cache or via DNS servers pointed to by proxies resolv.conf.auto (DHCP client updated)
  • See also here

Wifi commands

iw phy0 info
iw reg get
iw reg set GB

See other iw commands and Reg Database.

USB and File sharing

Add packages:

opkg install kmod-usb-core kmod-usb-storage usbutils block-mount luci-app-minidlna

Show device:

ls /dev/sd*
lsusb -t

Driver USB 1, 2, 3: uhci/ohci, ehci, xhci

Show device:

# block info /dev/sda1
/dev/sda1: UUID="9814-E49A" LABEL="2" VERSION="FAT16" TYPE="vfat"

Mount FAT32 USB stick:

/sbin/block mount
cd /mnt/sda1

See also here

LEDs

Buttons

procd interface:

root@hootoo:/etc/rc.button# ls
BTN_0     failsafe  power     reset     rfkill
root@hootoo:/etc/rc.button#

scripts need to be named according to the button name, like "BTN_0" or "wps" (see here). They receive values:

  • $BUTTON: Name of button
  • $ACTION: "pressed", "timeout" or "released". For released, script returns timeout seconds (for hold down).
  • $SEEN: number of seconds
root@wifi-ht:/etc/rc.button# cat BTN_0 
#!/bin/sh

logger "Button $BUTTON: $ACTION (Seen $SEEN)"

return 0
root@wifi-ht:/etc/rc.button#

C2600

Has an additional "lights_toggle":

[ "${ACTION}" = "released" ] || exit 0

led="c2600:white:general"
device="wifinet3"

logger "Button $ACTION, will toggle Guest Wifi"
echo 1 > /sys/class/leds/$led/brightness
case $(uci get wireless.$device.disabled) in
    0)
        uci set wireless.$device.disabled=1
        logger "Wifi disabled"
    ;;
    1)
        uci set wireless.$device.disabled=0
        logger "Wifi enabled"
    ;;
esac

wifi reload
service network reload
sleep 1
echo 0 > /sys/class/leds/$led/brightness

return 0

6in4

Requires packages: 6in4 luci-proto-ipv6 and used tunnel from Hurricane Electric.

  • Restart network
  • In LUCI, edit wan6 and change protocol from DHCPv6 to RFC4213
  • Set Remote IPv4 address (eg 74.82.46.6)
  • Set Local IPv6 address
  • Set IPv6 routed prefix (Routed /48)
  • Dynamic tunnel
    • Tunnel ID
    • HE username/password
ping ipv6.google.com

Manual Config:

opkg install 6in4
uci set network.henet=interface
uci set network.henet.proto=6in4
uci set network.henet.peeraddr=[get IPv4 of HE gateway] 
uci set network.henet.ip6addr='[IPv6 from HE]'
uci set network.henet.tunnelid=[HE tunnel ID]
uci set network.henet.username=[HE username]
uci set network.henet.password='[HE password]'
uci commit network

uci set firewall.@zone[1].network='wan henet'
uci commit firewall

ifup henet
/etc/init.d/firewall restart