Linux Tutorial – Puntata 15
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!
Bentornati a tutti. Questo Linux tutorial sta diventando ormai un appuntamento costante. Più si esplora, più mi diverto. E pensare che l’avevo cominciato cosi’ per gioco, senza nessuna pretesa. Molte cose sono in ballo, alcune veramente cool. Una è già attiva: da poco meno di una settimana il tutorial linux e’ su mastodon con un profilo dove posteremo settimanalmente le puntate. Se non sapete cosa sia mastodon e cosa sia sociale.network, male, molto male. Correte prima a leggere l’intervista fatta dal blog al suo fondatore Carlo Gubitosa e poi tornate qui: ne varrà la pena. Ah, per questa settimana preparate due tazze di the. Questa puntata sarà lunga. Molto lunga…
/PROC (1/2)
Se ricordate quando abbiamo parlato dei processi del sistema, abbiamo accennato al fatto che essi sono identificati da un numero chiamato PID – process id – e che conservano le informazioni all’interno di una particolare directory. Bene, oggi parleremo esattamente di quella dir che accennavamo allora: /proc
bottega@bottegadelbarbieri / ls -lh total 80K lrwxrwxrwx 1 root root 7 Feb 27 08:53 bin -> usr/bin drwxr-xr-x 5 root root 4.0K Jun 9 09:09 boot drwxrwxr-x 2 root root 4.0K Feb 27 08:56 cdrom drwxr-xr-x 20 root root 4.2K Jun 9 16:58 dev -rw-r--r-- 1 root root 0 Apr 25 07:26 dmraid-map drwxr-xr-x 143 root root 12K Jun 9 09:11 etc drwxr-xr-x 4 root root 4.0K Apr 29 17:29 home lrwxrwxrwx 1 root root 7 Feb 27 08:53 lib -> usr/lib lrwxrwxrwx 1 root root 9 Feb 27 08:53 lib32 -> usr/lib32 lrwxrwxrwx 1 root root 9 Feb 27 08:53 lib64 -> usr/lib64 lrwxrwxrwx 1 root root 10 Feb 27 08:53 libx32 -> usr/libx32 drwx------ 2 root root 16K Feb 27 08:53 lost+found drwxr-xr-x 3 root root 4.0K May 5 20:31 media drwxr-xr-x 2 root root 0 Jun 9 16:58 mnt -rw-r--r-- 1 root root 63 Apr 25 07:26 mounted-map drwxr-xr-x 2 root root 4.0K Feb 9 18:48 opt dr-xr-xr-x 196 root root 0 Jun 9 16:58 proc <<<<<<<<<<<<< -rw-r--r-- 1 root root 0 Apr 25 07:26 raided-map drwx------ 3 root root 4.0K Apr 25 07:00 root drwxr-xr-x 34 root root 1.1K Jun 9 18:11 run lrwxrwxrwx 1 root root 8 Feb 27 08:53 sbin -> usr/sbin drwxr-xr-x 2 root root 4.0K Feb 27 09:10 snap drwxr-xr-x 2 root root 4.0K Feb 9 18:48 srv -rw-r--r-- 1 root root 15 Apr 25 07:26 swaps-map dr-xr-xr-x 13 root root 0 Jun 9 16:58 sys drwxrwxrwt 13 root root 4.0K Jun 9 16:58 tmp drwxr-xr-x 14 root root 4.0K Feb 9 18:52 usr drwxr-xr-x 14 root root 4.0K Feb 9 19:08 var
Vediamo prima di tutto di listarne il contenuto:
bottega@bottegadelbarbieri /proc ls 1 117 16 17 2083 22 241 26 3 37 544 580 615 675 769 84 887 902 939 acpi consoles dynamic_debug ioports kpagecgroup misc pressure stat tty 10 12 1616 18 2084 23 242 2695 30 373 569 588 619 684 79 85 89 907 94 asound cpuinfo execdomains irq kpagecount modules sched_debug swaps uptime 101 122 163 188 2089 234 243 27 31 4 570 595 624 706 80 855 893 909 95 bootconfig crypto fb kallsyms kpageflags mounts schedstat sys version 103 13 164 2 21 236 247 28 32 521 574 6 661 708 81 86 894 91 96 buddyinfo devices filesystems kcore loadavg mtrr scsi sysrq-trigger version_signature 11 14 167 20 2125 2362 25 29 345 522 576 600 662 760 819 87 896 915 97 bus diskstats fs keys locks net self sysvipc vmallocinfo 113 15 168 2078 2182 2376 251 292 364 541 577 604 666 761 82 881 899 92 98 cgroups dma interrupts key-users mdstat pagetypeinfo slabinfo thread-self vmstat 116 1594 169 2081 2183 24 2567 293 366 542 579 613 669 766 83 882 9 936 99 cmdline driver iomem kmsg meminfo partitions softirqs timer_list zoneinfo
La dir come si può vedere è decisamente molto ricca di contenuto. Saliamo di root, e vediamo di dettagliare la prima parte del listato:
bottega@bottegadelbarbieri / sudo su -
root@bottegadelbarbieri:/# cd proc/
root@bottegadelbarbieri:/proc/1# ls -l /proc | grep '^d' |head -n 20 dr-xr-xr-x 9 root root 0 Jun 11 08:26 1 dr-xr-xr-x 9 root root 0 Jun 11 08:26 10 dr-xr-xr-x 9 root root 0 Jun 11 08:26 101 dr-xr-xr-x 9 root root 0 Jun 11 08:26 103 dr-xr-xr-x 9 bottega bottega 0 Jun 11 08:52 1040 dr-xr-xr-x 9 bottega bottega 0 Jun 11 08:26 1041 dr-xr-xr-x 9 root root 0 Jun 11 08:26 11 dr-xr-xr-x 9 root root 0 Jun 11 08:26 112 dr-xr-xr-x 9 root root 0 Jun 11 08:26 115 dr-xr-xr-x 9 root root 0 Jun 11 08:26 116 dr-xr-xr-x 9 root root 0 Jun 11 08:26 12 dr-xr-xr-x 9 root root 0 Jun 11 08:26 121 dr-xr-xr-x 9 root root 0 Jun 11 08:52 1230 dr-xr-xr-x 9 root root 0 Jun 11 08:52 1246 dr-xr-xr-x 9 root root 0 Jun 11 08:52 1249 dr-xr-xr-x 9 root root 0 Jun 11 08:48 1259 dr-xr-xr-x 9 root root 0 Jun 11 08:52 1260 dr-xr-xr-x 9 root root 0 Jun 11 08:48 1261 dr-xr-xr-x 9 root root 0 Jun 11 08:52 1262 dr-xr-xr-x 9 root root 0 Jun 11 08:26 13
Se guardate l’ultima colonna a destra, noterete come le subdirectory siano nominate con dei numeri. Quei numeri sono appunto i PID dei processi che lavorano sul sistema. Per vederli all’opera, e per verificare che quei numeri/processi ci siano per davvero, utilizziamo il comando ps:
root@bottegadelbarbieri:/proc/1# ps -ef |head -n 20 UID PID PPID C STIME TTY TIME CMD root 1 0 0 08:26 ? 00:00:01 /sbin/init splash root 2 0 0 08:26 ? 00:00:00 [kthreadd] root 3 2 0 08:26 ? 00:00:00 [rcu_gp] root 4 2 0 08:26 ? 00:00:00 [rcu_par_gp] root 6 2 0 08:26 ? 00:00:00 [kworker/0:0H-kblockd] root 9 2 0 08:26 ? 00:00:00 [mm_percpu_wq] root 10 2 0 08:26 ? 00:00:00 [ksoftirqd/0] root 11 2 0 08:26 ? 00:00:00 [rcu_sched] root 12 2 0 08:26 ? 00:00:00 [migration/0] root 13 2 0 08:26 ? 00:00:00 [idle_inject/0] root 14 2 0 08:26 ? 00:00:00 [cpuhp/0] root 15 2 0 08:26 ? 00:00:00 [cpuhp/1] root 16 2 0 08:26 ? 00:00:00 [idle_inject/1] root 17 2 0 08:26 ? 00:00:00 [migration/1] root 18 2 0 08:26 ? 00:00:00 [ksoftirqd/1] root 20 2 0 08:26 ? 00:00:00 [kworker/1:0H-kblockd] root 21 2 0 08:26 ? 00:00:00 [kdevtmpfs] root 22 2 0 08:26 ? 00:00:00 [netns] root 23 2 0 08:26 ? 00:00:00 [rcu_tasks_kthre]
Sempre nella 7a puntata ci eravamo detti che il primo processo a partire era init e che il suo PID era appunto 1. Entriamo dunque dentro la dir 1 e verifichiamo il contenuto:
root@bottegadelbarbieri:/proc# cd 1 root@bottegadelbarbieri:/proc/1# ls -lha total 0 dr-xr-xr-x 9 root root 0 Jun 9 19:49 . dr-xr-xr-x 201 root root 0 Jun 9 19:49 .. -r--r--r-- 1 root root 0 Jun 9 19:56 arch_status dr-xr-xr-x 2 root root 0 Jun 9 19:49 attr -rw-r--r-- 1 root root 0 Jun 9 19:56 autogroup -r-------- 1 root root 0 Jun 9 19:56 auxv -r--r--r-- 1 root root 0 Jun 9 19:49 cgroup --w------- 1 root root 0 Jun 9 19:56 clear_refs -r--r--r-- 1 root root 0 Jun 9 19:49 cmdline -rw-r--r-- 1 root root 0 Jun 9 19:49 comm -rw-r--r-- 1 root root 0 Jun 9 19:56 coredump_filter -r--r--r-- 1 root root 0 Jun 9 19:56 cpu_resctrl_groups -r--r--r-- 1 root root 0 Jun 9 19:56 cpuset lrwxrwxrwx 1 root root 0 Jun 9 19:56 cwd -> / -r-------- 1 root root 0 Jun 9 19:49 environ lrwxrwxrwx 1 root root 0 Jun 9 19:49 exe -> /usr/lib/systemd/systemd dr-x------ 2 root root 0 Jun 9 19:49 fd dr-x------ 2 root root 0 Jun 9 19:49 fdinfo -rw-r--r-- 1 root root 0 Jun 9 19:49 gid_map -r-------- 1 root root 0 Jun 9 19:56 io -r--r--r-- 1 root root 0 Jun 9 19:49 limits -rw-r--r-- 1 root root 0 Jun 9 19:49 loginuid dr-x------ 2 root root 0 Jun 9 19:56 map_files -r--r--r-- 1 root root 0 Jun 9 19:49 maps -rw------- 1 root root 0 Jun 9 19:56 mem -r--r--r-- 1 root root 0 Jun 9 19:49 mountinfo -r--r--r-- 1 root root 0 Jun 9 19:56 mounts -r-------- 1 root root 0 Jun 9 19:56 mountstats dr-xr-xr-x 55 root root 0 Jun 9 19:49 net dr-x--x--x 2 root root 0 Jun 9 19:56 ns -r--r--r-- 1 root root 0 Jun 9 19:56 numa_maps -rw-r--r-- 1 root root 0 Jun 9 19:56 oom_adj -r--r--r-- 1 root root 0 Jun 9 19:56 oom_score -rw-r--r-- 1 root root 0 Jun 9 19:49 oom_score_adj -r-------- 1 root root 0 Jun 9 19:56 pagemap -r-------- 1 root root 0 Jun 9 19:56 patch_state -r-------- 1 root root 0 Jun 9 19:56 personality -rw-r--r-- 1 root root 0 Jun 9 19:56 projid_map lrwxrwxrwx 1 root root 0 Jun 9 19:49 root -> / -rw-r--r-- 1 root root 0 Jun 9 19:49 sched -r--r--r-- 1 root root 0 Jun 9 19:56 schedstat -r--r--r-- 1 root root 0 Jun 9 19:49 sessionid -rw-r--r-- 1 root root 0 Jun 9 19:49 setgroups -r--r--r-- 1 root root 0 Jun 9 19:56 smaps -r--r--r-- 1 root root 0 Jun 9 19:56 smaps_rollup -r-------- 1 root root 0 Jun 9 19:56 stack -r--r--r-- 1 root root 0 Jun 9 19:55 stat -r--r--r-- 1 root root 0 Jun 9 19:55 statm -r--r--r-- 1 root root 0 Jun 9 19:49 status -r-------- 1 root root 0 Jun 9 19:56 syscall dr-xr-xr-x 3 root root 0 Jun 9 19:49 task -rw-r--r-- 1 root root 0 Jun 9 19:56 timens_offsets -r--r--r-- 1 root root 0 Jun 9 19:56 timers -rw-rw-rw- 1 root root 0 Jun 9 19:56 timerslack_ns -rw-r--r-- 1 root root 0 Jun 9 19:49 uid_map -r--r--r-- 1 root root 0 Jun 9 19:56 wchan
Di informazioni da esplorare, come potete vedere., ce ne sarebbero tante, ma ora proviamo a visualizzare almeno le più importanti:
– /proc/1/cmdline
ci dice come è stato lanciato init – qual’e’ il path – dalla linea di comando
root@bottegadelbarbieri:/proc/1# more cmdline /sbin/init
– /proc/1/environ
nella fattispecie ci dice quale sia la variabile utilizzata dal comando
root@bottegadelbarbieri:/proc/1# more environ HOME=/
– /proc/1/exe
e’ esattamente quello che sembra, ovvero un link simbolico al file eseguibile
root@bottegadelbarbieri:/proc/1# objdump -T exe | head -n 15 exe: file format elf64-x86-64 DYNAMIC SYMBOL TABLE: 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.3.4 __printf_chk 0000000000000000 DF *UND* 0000000000000000 getfilecon_raw 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 sched_getscheduler 0000000000000000 DF *UND* 0000000000000000 SD_SHARED receive_one_fd 0000000000000000 DF *UND* 0000000000000000 SD_SHARED sd_bus_track_unref 0000000000000000 DF *UND* 0000000000000000 SD_SHARED internal_hashmap_reserve 0000000000000000 DF *UND* 0000000000000000 SD_SHARED mac_apparmor_use 0000000000000000 DF *UND* 0000000000000000 SD_SHARED seccomp_parse_syscall_filter 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 __errno_location 0000000000000000 DF *UND* 0000000000000000 SD_SHARED rlimit_nofile_safe 0000000000000000 DF *UND* 0000000000000000 SD_SHARED free_and_strdup
– /proc/1/maps
rappresenta la mappatura dei blocchi e dei file utilizzati dal programma
root@bbottegadelbarbieri:/proc/1# cat maps |head -n 15 560bd806f000-560bd80a1000 r--p 00000000 fd:01 270380 /usr/lib/systemd/systemd 560bd80a1000-560bd815f000 r-xp 00032000 fd:01 270380 /usr/lib/systemd/systemd 560bd815f000-560bd81b5000 r--p 000f0000 fd:01 270380 /usr/lib/systemd/systemd 560bd81b5000-560bd81fb000 r--p 00145000 fd:01 270380 /usr/lib/systemd/systemd 560bd81fb000-560bd81fc000 rw-p 0018b000 fd:01 270380 /usr/lib/systemd/systemd 560bd897c000-560bd8bdd000 rw-p 00000000 00:00 0 [heap] 7faa78000000-7faa78021000 rw-p 00000000 00:00 0 7faa78021000-7faa7c000000 ---p 00000000 00:00 0 7faa7d504000-7faa7d505000 ---p 00000000 00:00 0 7faa7d505000-7faa7dd05000 rw-p 00000000 00:00 0 7faa7dd05000-7faa7dd06000 ---p 00000000 00:00 0 7faa7dd06000-7faa7e50d000 rw-p 00000000 00:00 0 7faa7e50d000-7faa7e51c000 r--p 00000000 fd:01 272074 /usr/lib/x86_64-linux-gnu/libm-2.31.so 7faa7e51c000-7faa7e5c3000 r-xp 0000f000 fd:01 272074 /usr/lib/x86_64-linux-gnu/libm-2.31.so 7faa7e5c3000-7faa7e65a000 r--p 000b6000 fd:01 272074 /usr/lib/x86_64-linux-gnu/libm-2.31.so
– /proc/1/status
di immediata comprensione, e’ lo stato attuale in cui si trova il programma
root@bottegadelbarbieri:/proc/1# head -n 20 status Name: systemd Umask: 0000 State: S (sleeping) Tgid: 1 Ngid: 0 Pid: 1 PPid: 0 TracerPid: 0 Uid: 0 0 0 0 Gid: 0 0 0 0 FDSize: 128 Groups: NStgid: 1 NSpid: 1 NSpgid: 1 NSsid: 1 VmPeak: 167324 kB VmSize: 102124 kB VmLck: 0 kB VmPin: 0 kB
– proc/1/cwd
e’ un link simbolico alla dir nella quale lavora il comando (la dir per init e’ /)
root@bottegadelbarbieri:/proc/1# ls -ltr |grep cwd lrwxrwxrwx 1 root root 0 Jun 11 08:48 cwd -> / root@bottegadelbarbieri:/proc/1# ls -ltr cwd/ total 80 drwxr-xr-x 2 root root 4096 Feb 9 18:48 srv drwxr-xr-x 2 root root 4096 Feb 9 18:48 opt drwxr-xr-x 14 root root 4096 Feb 9 18:52 usr drwxr-xr-x 14 root root 4096 Feb 9 19:08 var drwx------ 2 root root 16384 Feb 27 08:53 lost+found lrwxrwxrwx 1 root root 7 Feb 27 08:53 bin -> usr/bin lrwxrwxrwx 1 root root 8 Feb 27 08:53 sbin -> usr/sbin lrwxrwxrwx 1 root root 10 Feb 27 08:53 libx32 -> usr/libx32 lrwxrwxrwx 1 root root 9 Feb 27 08:53 lib64 -> usr/lib64 lrwxrwxrwx 1 root root 9 Feb 27 08:53 lib32 -> usr/lib32 lrwxrwxrwx 1 root root 7 Feb 27 08:53 lib -> usr/lib drwxrwxr-x 2 root root 4096 Feb 27 08:56 cdrom drwxr-xr-x 2 root root 4096 Feb 27 09:10 snap -rw-r--r-- 1 root root 0 Apr 25 07:26 dmraid-map -rw-r--r-- 1 root root 15 Apr 25 07:26 swaps-map -rw-r--r-- 1 root root 0 Apr 25 07:26 raided-map -rw-r--r-- 1 root root 63 Apr 25 07:26 mounted-map drwxr-xr-x 4 root root 4096 Apr 29 17:29 home drwxr-xr-x 3 root root 4096 May 5 20:31 media drwx------ 4 root root 4096 Jun 9 19:55 root drwxr-xr-x 5 root root 4096 Jun 10 19:42 boot drwxr-xr-x 143 root root 12288 Jun 10 19:43 etc dr-xr-xr-x 13 root root 0 Jun 11 08:26 sys dr-xr-xr-x 204 root root 0 Jun 11 08:26 proc drwxr-xr-x 20 root root 4220 Jun 11 08:26 dev drwxr-xr-x 2 root root 0 Jun 11 08:26 mnt drwxrwxrwt 13 root root 4096 Jun 11 10:50 tmp drwxr-xr-x 33 root root 1100 Jun 11 10:50 run
– /proc/1/tasks
e’ una interessante directory che contiene tutti i processi generati da esso
root@bottegadelbarbieri:/proc/1# ls -ltr |grep task dr-xr-xr-x 3 root root 0 Jun 11 08:26 task root@bottegadelbarbieri:/proc/1# ls -ltr task/1/ |head -n 20 total 0 dr-xr-xr-x 2 root root 0 Jun 11 08:26 attr -r--r--r-- 1 root root 0 Jun 11 11:14 wchan -rw-r--r-- 1 root root 0 Jun 11 11:14 uid_map -r-------- 1 root root 0 Jun 11 11:14 syscall -r--r--r-- 1 root root 0 Jun 11 11:14 status -r--r--r-- 1 root root 0 Jun 11 11:14 statm -r--r--r-- 1 root root 0 Jun 11 11:14 stat -r-------- 1 root root 0 Jun 11 11:14 stack -r--r--r-- 1 root root 0 Jun 11 11:14 smaps_rollup -r--r--r-- 1 root root 0 Jun 11 11:14 smaps -rw-r--r-- 1 root root 0 Jun 11 11:14 setgroups -r--r--r-- 1 root root 0 Jun 11 11:14 sessionid -r--r--r-- 1 root root 0 Jun 11 11:14 schedstat -rw-r--r-- 1 root root 0 Jun 11 11:14 sched lrwxrwxrwx 1 root root 0 Jun 11 11:14 root -> / -rw-r--r-- 1 root root 0 Jun 11 11:14 projid_map -r-------- 1 root root 0 Jun 11 11:14 personality -r-------- 1 root root 0 Jun 11 11:14 patch_state -r-------- 1 root root 0 Jun 11 11:14 pagemap
Analizziamo per esempio il processo syscall:
root@bottegadelbarbieri:/proc/1# ps -ef |grep syscall root 2147 1262 0 11:18 pts/0 00:00:00 grep --color=auto syscall root@bottegadelbarbieri:/proc/1# pstree -s 2147 systemd─┬─ModemManager───2*[{ModemManager}] ├─NetworkManager───2*[{NetworkManager}] ├─accounts-daemon───2*[{accounts-daemon}] ├─acpid ├─agetty ├─automount───3*[{automount}] ├─avahi-daemon───avahi-daemon ├─colord───2*[{colord}] ├─cron ├─cups-browsed───2*[{cups-browsed}] ├─cupsd───4*[dbus] ├─dbus-daemon ├─irqbalance───{irqbalance} ├─2*[kerneloops] ├─lightdm─┬─Xorg───{Xorg} │ ├─lightdm─┬─lightdm-greeter───lightdm-gtk-gre───2*[{lightdm-gtk-gre}] │ │ └─2*[{lightdm}] │ ├─lightdm │ └─2*[{lightdm}] ├─networkd-dispat ├─polkitd───2*[{polkitd}] ├─rpcbind ├─rsyslogd───3*[{rsyslogd}] ├─rtkit-daemon───2*[{rtkit-daemon}] ├─sshd───sshd───sshd───bash───sudo───su───bash───pstree ├─systemd─┬─(sd-pam) │ ├─at-spi-bus-laun─┬─dbus-daemon │ │ └─3*[{at-spi-bus-laun}] │ ├─at-spi2-registr───2*[{at-spi2-registr}] │ ├─dbus-daemon │ ├─gvfsd───2*[{gvfsd}] │ ├─gvfsd-fuse───5*[{gvfsd-fuse}] │ └─pulseaudio───3*[{pulseaudio}] ├─systemd─┬─(sd-pam) │ ├─dbus-daemon │ └─pulseaudio───2*[{pulseaudio}] ├─systemd-journal ├─systemd-logind ├─systemd-resolve ├─systemd-timesyn───{systemd-timesyn} ├─systemd-udevd ├─udisksd───4*[{udisksd}] ├─unattended-upgr───{unattended-upgr} ├─whoopsie───2*[{whoopsie}] └─wpa_supplicant
Ci sarebbe davvero ancora tanto da dire ma, davvero, per oggi concludiamo qui. Nella prossima puntata continueremo ad esplorare il /proc filesystem centrando la nostra attenzione sui processi direttamente controllati dal kernel. Tanta tanta roba…
Alla prossima settimana!
jolek78
>> | Indice | << |
Puntata 14 | < > | Puntata 16 |
Il logo “Tux Linux” e’ stato realizzato e distribuito dall’artista deiby-ybied su Deviantart in licenza Creative Commons BY-NC-SA 3.0