tips: add debug_hook.md with netcat example

This commit is contained in:
Filippo Gentile 2024-01-15 15:21:17 +01:00
parent c23ab3571f
commit f66b091b54
1 changed files with 80 additions and 0 deletions

80
tips/debug_hook.md Normal file
View File

@ -0,0 +1,80 @@
# Inspecting Initramfs
See [PmOS Wiki](https://wiki.postmarketos.org/wiki/Inspecting_the_initramfs)
## Enable debug hook
```
pmbootstrap initfs hook_add debug-shell
pmbootstrap flasher flash_kernel # or however you flash/boot the kernel
```
## Connect to device using Telnet
Running:
```
telnet 172.16.42.1
```
opens a shell to device initramfs.
## Mount rootfs
Current root filesystem is initramfs loaded in RAM.
To switch to device root filesystem run:
```
source ./init_functions.sh
mount -o rw $(find_root_partition) /sysroot
```
Now you have mounted rootfs inside `/sysroot` directory
**NOTE**: to continue boot you have to undo this operation and let init system mount root partition by itself so run:
```
umount /sysroot
pmos_continue_boot
```
## Chroot into rootfs
Once you have mounted to `/sysroot` you can run programs in it.
First do a chroot:
```
chroot /sysroot
```
Now you can run executable as if you booted.
**NOTE**: services are not running and would not start correctly inside chroot
To undo just run from chroot shell:
```
exit
```
## Copy files folders from device to PC (netcat)
From device go into folder you want to send, then run:
```
tar c . | nc -l -p 10000
```
From PC go to destination folder and run:
```
nc -w 5 172.16.42.1 10000 | tar xf -
```
**NOTE**: `-w 5` otpions is a timeout of 5 seconds needed because sometimes `nc` does keep the connections after all data is sent so it would never quit.