Linux Tutorial – Puntata 18
di jolek78
Care/i fruitrici e fruitori del blog, in questi post – ogni domenica mattina – si parlerà del sistema operativo GNU/Linux e degli strumenti per utilizzarlo al massimo delle potenzialità. Cercheremo di spiegare come funziona, cosa è il kernel, come costruirsi una vpn, come settare un firewall e giocare col terminale, usare adb e altro. Se il capitalismo della sorveglianza ci vuole passivi consumatori-consumatrici di servizi noi si risponde con un po’ di “cultura informatica” e un MARAMEO (quasi affettuoso). Buona lettura!
Dunque, siamo arrivati alla seconda (e ultima) puntata del sysfs presente dentro la directory /sys. Questa domenica proveremo a esplorare sommariamente le ultime subdirectory non trattate in precedenza, per poi riservarci le ultime puntate del FHS parlando di /usr e /var. Finita infatti questa sezione del tutorial, andremo a trattare i programmi più noti e più utili per maneggiare il nostro sistema operativo, la memoria, controllare il suo stato e verificare i suoi errori. Tutto viene di conseguenza. Prima val la pena conoscere le fondamenta, e poi (magari) si può mettere la carta da parati. Pertanto, preparate la vostra tazza di the, fate partire la macchina virtuale e ricominciamo.
/SYS (2/2)
bottega@bottegadelbarbieri /sys ll total 0 drwxr-xr-x 2 root root 0 Jul 3 08:23 block/ drwxr-xr-x 44 root root 0 Jul 3 08:23 bus/ drwxr-xr-x 71 root root 0 Jul 3 08:23 class/ drwxr-xr-x 4 root root 0 Jul 3 08:23 dev/ drwxr-xr-x 16 root root 0 Jul 3 08:23 devices/ drwxr-xr-x 5 root root 0 Jul 3 08:23 firmware/ drwxr-xr-x 10 root root 0 Jul 3 08:23 fs/ drwxr-xr-x 2 root root 0 Jul 3 09:02 hypervisor/ drwxr-xr-x 14 root root 0 Jul 3 08:23 kernel/ drwxr-xr-x 174 root root 0 Jul 3 08:23 module/ drwxr-xr-x 3 root root 0 Jul 3 08:24 power/
Andiamo quindi per prima cosa ad analizzare la directory firmware
– /sys/firmware
bottega@bottegadelbarbieri /sys ls -lha firmware/ total 0 drwxr-xr-x 5 root root 0 Jul 3 08:23 . dr-xr-xr-x 13 root root 0 Jul 3 08:23 .. drwxr-xr-x 5 root root 0 Jul 3 08:24 acpi drwxr-xr-x 3 root root 0 Jul 3 08:24 dmi drwxr-xr-x 10 root root 0 Jul 3 10:26 memmap
Un po’ di definizioni:
acpi > Advanced Configuration and Power Interface
È in sostanza uno standard per la gestione energetica dell’hardware che gira sulla macchina. In questa directory dunque troviamo la modalità con cui il sistema gestisce le periferiche e, in generale, tutta la parte fisica.
bottega@bottegadelbarbieri /sys/firmware tree acpi/ acpi/ ├── hotplug │ ├── force_remove │ ├── memory │ │ └── enabled │ ├── pci_root │ │ └── enabled │ └── processor │ └── enabled ├── interrupts │ ├── error │ ├── ff_gbl_lock │ ├── ff_pmtimer │ ├── ff_pwr_btn │ ├── ff_rt_clk │ ├── ff_slp_btn │ ├── gpe00 │ ├── gpe01 │ ├── gpe02 │ ├── gpe03 │ ├── gpe04 │ ├── gpe05 │ ├── gpe06 │ ├── gpe07 │ ├── gpe_all │ ├── sci │ └── sci_not ├── pm_profile └── tables ├── APIC ├── data ├── DSDT ├── dynamic ├── FACP ├── FACS └── SSDT 8 directories, 27 files
Per esempio, andando a guardare due file dentro la directory hotplug:
bottega@bottegadelbarbieri /sys/firmware cat /sys/firmware/acpi/hotplug/force_remove 0 bottega@bottegadelbarbieri /sys/firmware cat /sys/firmware/acpi/hotplug/processor/enabled 1
0 significherà “non abilitato” mentre 1 significherà “abilitato”
dmi > Desktop Management Interface
E’ una astrazione con cui il software (il kernel) gestisce la parte hardware del sistema. Non è un caso quindi trovarci proprio un file chiamato smbios, cioè la modalità con cui il sistema reperisce informazioni prodotte dal bios (abbiamo esplorato la fase di boot nella 7)
bottega@bottegadelbarbieri /sys/firmware tree dmi/ dmi/ └── tables ├── DMI └── smbios_entry_point 1 directory, 2 files
Nota a margine: per avere alcune info sul bios:
bottega@bottegadelbarbieri /sys/firmware sudo dmidecode -t bios # dmidecode 3.2 Getting SMBIOS data from sysfs. SMBIOS 2.5 present. Handle 0x0000, DMI type 0, 20 bytes BIOS Information Vendor: innotek GmbH Version: VirtualBox Release Date: 12/01/2006 Address: 0xE0000 Runtime Size: 128 kB ROM Size: 128 kB Characteristics: ISA is supported PCI is supported Boot from CD is supported Selectable boot is supported 8042 keyboard services are supported (int 9h) CGA/mono video services are supported (int 10h) ACPI is supported
memmap > Memory Map
Qui invece troveremo i file che descrivono la mappatura della memoria.
bottega@bottegadelbarbieri .../firmware/memmap cat 0/* 0x9fbff 0x0 System RAM bottega@bottegadelbarbieri .../firmware/memmap cat 1/* 0x9ffff 0x9fc00 Reserved [...]
– /sys/fs
Nessuna sorpresa: sono contenuti i file corrispondenti alle informazioni che provengono dal filesystem. Se listiamo, potremo vedere esattamente i nomi dei fs noti che abbiamo già nominato in precedenza:
bottega@bottegadelbarbieri /sys ls -lha fs/ total 0 drwxr-xr-x 10 root root 0 Jul 3 08:23 . dr-xr-xr-x 13 root root 0 Jul 3 08:23 .. drwx-----T 2 root root 0 Jul 3 08:24 bpf drwxr-xr-x 3 root root 0 Jul 3 17:04 btrfs drwxr-xr-x 15 root root 380 Jul 3 08:24 cgroup drwxr-xr-x 2 root root 0 Jul 3 17:04 ecryptfs drwxr-xr-x 5 root root 0 Jul 3 17:04 ext4 drwxr-xr-x 3 root root 0 Jul 3 08:24 fuse drwxr-x--- 2 root root 0 Jul 3 08:24 pstore drwxr-xr-x 3 root root 0 Jul 3 17:04 xfs
Poiche’ il nostro disco sda5 è in ext4
bottega@bottegadelbarbieri /sys lsblk -f NAME FSTYPE LABEL UUID FSAVAIL FSUSE% MOUNTPOINT sda ├─sda1 vfat 880E-018C 511M 0% /boot/efi ├─sda2 ├─sda5 ext4 efc51c8f-4202-458a-9210-239d075aee17 440.4M 30% /boot <<<< └─sda6 crypto_LUKS 6c45a3ec-325e-41cc-98fb-8ac9b5299a5a └─sda6_crypt LVM2_member monDww-pMsR-jn3G-troM-QWzo-PAQL-u68n0k ├─vgxubuntu-root ext4 52895bce-6681-4ab1-85f4-8c1883aff472 4.2G 62% / └─vgxubuntu-swap_1 swap 0ceb88d0-19b4-4888-8eab-c173a9e1a335 [SWAP] sr0 iso9660 VBox_GAs_6.1.16 2020-10-15-14-48-48-14
proviamo a vedere cosa contiene la dir ext4
bottega@bottegadelbarbieri /sys ls -lha fs/ext4/sda5/ total 0 drwxr-xr-x 2 root root 0 Jul 3 17:04 . drwxr-xr-x 5 root root 0 Jul 3 17:04 .. -r--r--r-- 1 root root 4.0K Jul 3 17:04 delayed_allocation_blocks -r--r--r-- 1 root root 4.0K Jul 3 17:04 errors_count -rw-r--r-- 1 root root 4.0K Jul 3 17:04 err_ratelimit_burst -rw-r--r-- 1 root root 4.0K Jul 3 17:04 err_ratelimit_interval_ms -rw-r--r-- 1 root root 4.0K Jul 3 17:04 extent_max_zeroout_kb -r--r--r-- 1 root root 4.0K Jul 3 17:04 first_error_block -r--r--r-- 1 root root 4.0K Jul 3 17:04 first_error_errcode -r--r--r-- 1 root root 4.0K Jul 3 17:04 first_error_func -r--r--r-- 1 root root 4.0K Jul 3 17:04 first_error_ino -r--r--r-- 1 root root 4.0K Jul 3 17:04 first_error_line -r--r--r-- 1 root root 4.0K Jul 3 17:04 first_error_time -rw-r--r-- 1 root root 4.0K Jul 3 17:04 inode_goal -rw-r--r-- 1 root root 4.0K Jul 3 17:04 inode_readahead_blks -r--r--r-- 1 root root 4.0K Jul 3 17:04 journal_task -r--r--r-- 1 root root 4.0K Jul 3 17:04 last_error_block -r--r--r-- 1 root root 4.0K Jul 3 17:04 last_error_errcode -r--r--r-- 1 root root 4.0K Jul 3 17:04 last_error_func -r--r--r-- 1 root root 4.0K Jul 3 17:04 last_error_ino -r--r--r-- 1 root root 4.0K Jul 3 17:04 last_error_line -r--r--r-- 1 root root 4.0K Jul 3 17:04 last_error_time -r--r--r-- 1 root root 4.0K Jul 3 17:04 lifetime_write_kbytes -r--r--r-- 1 root root 4.0K Jul 3 17:04 max_writeback_mb_bump -rw-r--r-- 1 root root 4.0K Jul 3 17:04 mb_group_prealloc -rw-r--r-- 1 root root 4.0K Jul 3 17:04 mb_max_inode_prealloc -rw-r--r-- 1 root root 4.0K Jul 3 17:04 mb_max_to_scan -rw-r--r-- 1 root root 4.0K Jul 3 17:04 mb_min_to_scan -rw-r--r-- 1 root root 4.0K Jul 3 17:04 mb_order2_req -rw-r--r-- 1 root root 4.0K Jul 3 17:04 mb_stats -rw-r--r-- 1 root root 4.0K Jul 3 17:04 mb_stream_req -rw-r--r-- 1 root root 4.0K Jul 3 17:04 msg_ratelimit_burst -rw-r--r-- 1 root root 4.0K Jul 3 17:04 msg_ratelimit_interval_ms -rw-r--r-- 1 root root 4.0K Jul 3 17:04 reserved_clusters -r--r--r-- 1 root root 4.0K Jul 3 17:04 session_write_kbytes -r--r--r-- 1 root root 4.0K Jul 3 17:04 sra_exceeded_retry_limit --w------- 1 root root 4.0K Jul 3 17:04 trigger_fs_error -rw-r--r-- 1 root root 4.0K Jul 3 17:04 warning_ratelimit_burst -rw-r--r-- 1 root root 4.0K Jul 3 17:04 warning_ratelimit_interval_ms
– /sys/kernel
Qui dentro invece, croce e delizia, troviamo le info sul kernel:
bottega@bottegadelbarbieri /sys/kernel ls -lha total 0 drwxr-xr-x 14 root root 0 Jul 3 08:23 . dr-xr-xr-x 13 root root 0 Jul 3 08:23 .. drwxr-xr-x 2 root root 0 Jul 3 17:15 boot_params drwxr-xr-x 2 root root 0 Jul 3 17:15 cgroup drwxr-xr-x 3 root root 0 Jul 3 08:24 config drwx------ 40 root root 0 Jul 3 08:24 debug -r--r--r-- 1 root root 4.0K Jul 3 17:15 fscaps drwxr-xr-x 2 root root 0 Jul 3 17:15 iommu_groups drwxr-xr-x 23 root root 0 Jul 3 17:15 irq -r--r--r-- 1 root root 4.0K Jul 3 17:15 kexec_crash_loaded -rw-r--r-- 1 root root 4.0K Jul 3 17:15 kexec_crash_size -r--r--r-- 1 root root 4.0K Jul 3 17:15 kexec_loaded drwxr-xr-x 2 root root 0 Jul 3 17:15 livepatch drwxr-xr-x 7 root root 0 Jul 3 08:24 mm -r--r--r-- 1 root root 492 Jul 3 17:15 notes -rw-r--r-- 1 root root 4.0K Jul 3 17:15 profiling -rw-r--r-- 1 root root 4.0K Jul 3 17:15 rcu_expedited -rw-r--r-- 1 root root 4.0K Jul 3 17:15 rcu_normal drwxr-xr-x 4 root root 0 Jul 3 08:24 security drwxr-xr-x 172 root root 0 Jul 3 08:24 slab drwxr-xr-x 2 root root 0 Jul 3 17:15 software_nodes drwx------ 8 root root 0 Jul 3 08:24 tracing -rw-r--r-- 1 root root 4.0K Jul 3 08:23 uevent_helper -r--r--r-- 1 root root 4.0K Jul 3 17:15 uevent_seqnum -r--r--r-- 1 root root 4.0K Jul 3 17:15 vmcoreinfo
Davvero, qui ci potremmo perdere più di 10 puntate, ma ci son metodi più smart per andare a leggere le info del kernel e del sistema che ci servono davvero. Una sola piccola aggiunta sulla subdirectory config. Essa appartiene a un altro filesystem, il configfs che in qualche modo è speculare al sysfs. Mentre il sysfs ritiene in memoria tutte le informazioni e gli oggetti del kernel, il configfs esiste con l’unico scopo di modificare, aggiungere o rimuovere dati all’interno del kernel.
/sys/module
Ed ecco i moduli, quei famosi pezzi che aggiungiamo al kernel per fargli fare determinate operazioni. All’interno della nostra macchina virtuale le directory sono 176.
bottega@bottegadelbarbieri /sys/module ls -lha |wc -l 176 bottega@bottegadelbarbieri /sys/module ls -lha |more total 0 drwxr-xr-x 175 root root 0 Jul 3 08:23 . dr-xr-xr-x 13 root root 0 Jul 3 08:23 .. drwxr-xr-x 3 root root 0 Jul 3 08:23 8250 drwxr-xr-x 5 root root 0 Jul 3 08:24 ac97_bus drwxr-xr-x 3 root root 0 Jul 3 08:23 acpi drwxr-xr-x 3 root root 0 Jul 3 08:23 acpi_cpufreq drwxr-xr-x 3 root root 0 Jul 3 08:23 acpiphp drwxr-xr-x 5 root root 0 Jul 3 08:23 aesni_intel drwxr-xr-x 7 root root 0 Jul 3 08:23 ahci drwxr-xr-x 3 root root 0 Jul 3 08:23 apparmor drwxr-xr-x 3 root root 0 Jul 3 08:23 ata_generic drwxr-xr-x 3 root root 0 Jul 3 08:23 ata_piix drwxr-xr-x 5 root root 0 Jul 3 08:24 autofs4 drwxr-xr-x 3 root root 0 Jul 3 08:23 battery drwxr-xr-x 5 root root 0 Jul 3 17:38 binfmt_misc drwxr-xr-x 5 root root 0 Jul 3 08:45 blake2b_generic drwxr-xr-x 3 root root 0 Jul 3 08:23 blk_cgroup drwxr-xr-x 3 root root 0 Jul 3 08:23 blk_crypto drwxr-xr-x 3 root root 0 Jul 3 08:23 block drwxr-xr-x 5 root root 0 Jul 3 08:45 btrfs drwxr-xr-x 3 root root 0 Jul 3 08:23 button drwxr-xr-x 6 root root 0 Jul 3 08:23 cec drwxr-xr-x 2 root root 0 Jul 3 08:23 configfs drwxr-xr-x 3 root root 0 Jul 3 08:23 cpufreq drwxr-xr-x 3 root root 0 Jul 3 08:23 cpuidle drwxr-xr-x 5 root root 0 Jul 3 08:23 crc32_pclmul drwxr-xr-x 3 root root 0 Jul 3 08:23 crc_t10dif drwxr-xr-x 5 root root 0 Jul 3 08:23 crct10dif_pclmul drwxr-xr-x 5 root root 0 Jul 3 08:23 cryptd drwxr-xr-x 3 root root 0 Jul 3 08:23 cryptomgr drwxr-xr-x 5 root root 0 Jul 3 08:23 crypto_simd drwxr-xr-x 3 root root 0 Jul 3 08:23 debug_core
Per esempio dentro configfs:
bottega@bottegadelbarbieri /sys/module cd configfs/ /sys/module/configfs bottega@bottegadelbarbieri .../module/configfs ll total 0 --w------- 1 root root 4.0K Jul 3 08:23 uevent -r--r--r-- 1 root root 4.0K Jul 3 17:48 version
Ci sara’ una puntata in cui parleremo del kernel, e in particolar modo di sysctl. Abbiate pazienza, tratteremo tutto. O quasi.
– /sys/power
Immagino abbiate gia’ capito l’antifona. In questa directory son conservate le informazioni per gestire il sistema di accensione/spegnimento, gestione e alimentazione del sistema.
bottega@bottegadelbarbieri /sys/power ls -lha total 0 drwxr-xr-x 3 root root 0 Jul 3 08:24 . dr-xr-xr-x 13 root root 0 Jul 3 08:23 .. -rw-r--r-- 1 root root 4.0K Jul 3 17:51 disk -rw-r--r-- 1 root root 4.0K Jul 3 17:51 image_size -rw-r--r-- 1 root root 4.0K Jul 3 17:51 mem_sleep -rw-r--r-- 1 root root 4.0K Jul 3 17:51 pm_async -rw-r--r-- 1 root root 4.0K Jul 3 17:51 pm_debug_messages -rw-r--r-- 1 root root 4.0K Jul 3 17:51 pm_freeze_timeout -rw-r--r-- 1 root root 4.0K Jul 3 17:51 pm_print_times -rw-r--r-- 1 root root 4.0K Jul 3 17:51 pm_test -rw-r--r-- 1 root root 4.0K Jul 3 17:51 pm_trace -r--r--r-- 1 root root 4.0K Jul 3 17:51 pm_trace_dev_match -r--r--r-- 1 root root 4.0K Jul 3 17:51 pm_wakeup_irq -rw-r--r-- 1 root root 4.0K Jul 3 17:51 reserved_size -rw-r--r-- 1 root root 4.0K Jul 3 08:24 resume -rw-r--r-- 1 root root 4.0K Jul 3 17:51 resume_offset -rw-r--r-- 1 root root 4.0K Jul 3 17:51 state drwxr-xr-x 2 root root 0 Jul 3 17:51 suspend_stats -rw-r--r-- 1 root root 4.0K Jul 3 17:51 sync_on_suspend -rw-r--r-- 1 root root 4.0K Jul 3 17:51 wake_lock -rw-r--r-- 1 root root 4.0K Jul 3 17:51 wake_unlock -rw-r--r-- 1 root root 4.0K Jul 3 17:51 wakeup_count
disk per esempio ci dice gli stati che puo’ assumere il disco
bottega@bottegadelbarbieri /sys/power cat disk [shutdown] reboot suspend test_resume
imagesize ci dice quanto e’ grande l’immagine in bit
bottega@bottegadelbarbieri /sys/power cat image_size 794071040
state gli stati che puo’ assumere il sistema
bottega@bottegadelbarbieri /sys/power cat state freeze mem disk
e via discorrendo.
Cosi’ per informazione: quante tazze di the avete bevuto? Ne e’ bastata una?
Alla prossima settimana!
jolek78
>> | Indice | << |
Puntata 17 | < > | Puntata 19 |
Il logo “Tux Linux” e’ stato realizzato e distribuito dall’artista deiby-ybied su Deviantart in licenza Creative Commons BY-NC-SA 3.0