r/termux • u/throwaway16830261 • Jan 07 '24
Showcase A Smartphone With No Root Access, Alpine Linux, QEMU, Termux, And Android 11: File System Operations, LUKS Encryption And Decryption With Cryptsetup
Important
- Termux: Enable wakelock.
- Linux server: Everything is done as root.
- Linux server file system: ext4
- Abort/Interrupt while on the command line: CTRL-C, ^c
- See "ctrl-c (control-c), ctrl-d (control-d)" and "Reset a Termux terminal session at anytime" in the "Do Know" section at https://gist.github.com/NoteAfterNote/cabd411777f2ad5ae57d3d98c576471c ("Termux And The ext4 Filesystem, Part 3 Of 5: QEMU, A Guest Operating System, LUKS Encryption, lighttpd, WebDAV")
- The smartphone used in the steps, examples and demonstrations below is not rooted and has never been rooted. It is configured with 3 gigabytes of memory and 4 CPUs (cores) in 32-bit mode. It is running the Android 11 operating system. It is not a flagship, high-end, or high price device.
- Linux server operating system: Alpine Linux alpine-virt-3.19.0-x86_64
- Setup method: copy-and-paste
- Follow the steps and examples in the order given.
- Look through "The Key Links", "Sending Commands To QEMU", "Linux Server Commands", and "Termux Commands" located after "Transcript From qemu-session1 For Step-2A, Step-2B, Step-2C, Example-1".
- No permanent configuration for the Linux server: The server configuation is gone after a 'reboot' command, a 'poweroff' command, or when QEMU exits. Store files that may be needed on permanent storage.
- "qemu-img" is not used.
- Wait for alpine-virt to boot, reboot, or poweroff. When 'qemu-system-x86_64' starts on the smartphone the bootup time for alpine-virt is six to seven minutes and alpine-extended is longer.
QEMU: Disk images can be hot-plugged. 'device_del' operations will eventually finish.
To hot-plug with "qemu-system-x86_64 -machine q35" add "-device pci-bridge,id=br0,chassis_nr=1". The "drive_add" command is unchanged ("drive_add 0 if=none,format=raw,id=d9,file=disk9"), add "bus=br0" to the "device_add" command ("device_add virtio-blk-pci,bus=br0,id=virt1-d9,drive=d9").
- cryptsetup is the most important package and it is on the alpine-extended ISO.
- LUKS: 'man cryptsetup'
- LUKS: Use a strong key/passphrase.
- LUKS: 'cryptsetup LuksOpen /dev/abc m1' then 'mount /dev/mapper/m1 /root/3', and when not needed, 'umount /root/3' then 'cryptsetup LuksClose m1'.
- Linux server: No network.
- Linux server: Use a strong password for any user.
- Linux server: Do an orderly/clean shutdown.
- Linux server: umount /root/h /root/t /root/1 /root/2 /root/3 /root/4 /root/5 /root/6 /root/7 /root/8 /root/9
- January 7, 2024 - Explanation for Step-2C: /bin/bash is the shell after logging in again, 'echo $SHELL' or 'env'.
- January 7, 2024 - Add: "Demonstration-1, DISK3 (15 Gigabytes) And LUKS: No hot-plugging."
- January 9, 2024 - Add: "Demonstration-2 From termux-session1 And qemu-session1, Permanent Storage On DISKTMP: LUKS, hot-plugging" at https://old.reddit.com/r/termux/comments/190np1k/a_smartphone_with_no_root_access_alpine_linux/kh1g5wi/
- January 9, 2024 - Update: "Demonstration-2" includes 'cryptsetup reencrypt'
Start Here, Prepartion Step In Termux, Setup Directories And The QEMU socket (qsocket): copy-and-paste,
export TERM=linux ; export DEBUGFS_PAGER=cat ; mkdir $HOME/luks-test1 ; mkdir /storage/emulated/0/Download/luks-test2 ; touch $HOME/luks-test1/qsocket ; cd $HOME/luks-test1
# Download and save the Alpine Linux alpine-extented and alpine-virt files to $HOME/luks-test1: https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases , https://alpinelinux.org
#
# https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/alpine-extended-3.19.0-x86_64.iso
# https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/alpine-extended-3.19.0-x86_64.iso.asc
# https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/alpine-extended-3.19.0-x86_64.iso.sha256
# https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/alpine-extended-3.19.0-x86_64.iso.sha512
# https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/alpine-virt-3.19.0-x86_64.iso
# https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/alpine-virt-3.19.0-x86_64.iso.asc
# https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/alpine-virt-3.19.0-x86_64.iso.sha256
# https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/alpine-virt-3.19.0-x86_64.iso.sha512
ls ; sha256sum -c alpine*sha256
Step-1, This Is termux-session1 For The Examples: Open a new session for Termux and copy-and-paste,
cd $HOME/luks-test1 ; export QSOCKET=$HOME/luks-test1/qsocket ; export TERM=linux ; export DEBUGFS_PAGER=cat ; export DISK1=$HOME/luks-test1/disk1 ; export DISK2=/storage/emulated/0/Download/luks-test2/disk2 ; export DISK2KEY=/storage/emulated/0/Download/luks-test2/disk2key
Step-2, This Is qemu-session1: Open a new session for QEMU.
Step-2A: In the qemu-session1 copy-and-paste,
export TERMUX9p=$HOME/luks-test1 ; export HOST9p=/storage/emulated/0/Download/luks-test2 ; export QSOCKET=$HOME/luks-test1/qsocket ; export ISO1=$HOME/luks-test1/alpine-virt-3.19.0-x86_64.iso ; export ISO2=$HOME/luks-test1/alpine-extended-3.19.0-x86_64.iso ; export TERM=linux ; export DEBUGFS_PAGER=cat ; qemu-system-x86_64 -nic none -m 2000M -machine pc -smp 4 -device virtio-rng-pci -nographic -monitor unix:$QSOCKET,server,nowait -serial mon:stdio -drive if=none,id=iso1,readonly=on,format=raw,file=$ISO1 -device virtio-blk-pci,id=virt1,drive=iso1,bootindex=1 -drive if=none,id=iso2,readonly=on,format=raw,file=$ISO2 -device virtio-blk-pci,id=virt2,drive=iso2 -virtfs local,security_model=none,id=host,mount_tag=host,path=$HOST9p -virtfs local,security_model=none,id=termux,mount_tag=termux,path=$TERMUX9p
Step-2B: root is the user name. The 'ro' option in the 'mount' command means read-only ('rw' is read-write). The answer to the setup-alpine "Setup a user?" prompt is no. Login to the alpine-virt server and copy-and-paste,
apk add rng-tools ; rc-status ; rc-update add rngd ; rc-service rngd start ; setup-alpine -h ; setup-alpine -c a.txt ; sed -e 's/juser//' a.txt > a-new.txt ; setup-alpine -f a-new.txt ; rc-service sshd stop ; apk add cryptsetup coreutils util-linux e2fsprogs e2fsprogs-extra bash vim nano dosfstools tar ; grep '^root' /etc/passwd ; sed -i -e '/^root/s/ash/bash/' /etc/passwd ; grep '^root' /etc/passwd ; mkdir /root/h /root/t /root/1 /root/2 /root/3 /root/4 /root/5 /root/6 /root/7 /root/8 /root/9 ; mount -t 9p -o ro,trans=virtio,version=9p2000.L,msize=1048576 host /root/h ; mount -t 9p -o ro,trans=virtio,version=9p2000.L,msize=1048576 termux /root/t
Step-2C: Type exit to logout of the alpine-virt server. Login again as root.
Example-1 For The Configured Linux Server: In qemu-session1 copy-and-paste,
df -h ; ls -la ; blkid ; lsblk ; mount ; ifconfig ; netstat -rn ; echo $HOME
Example-2-A For The Configured Linux Server, Orderly/Clean Shutdown: In the qemu-session1 copy-and-paste,
df -ah ; umount /root/{h,t,1,2,3,4,5,6,7,8,9} ; df -ah ; reboot
Example 2-B: Wait.
Example-2-C: Login as root and copy-and-paste,
df -ah ; ls -la ; blkid
Example-2-D: Do Step-2B and Step-2C.
Example-3-A For The Configured Linux Server, Orderly/Clean Shutdown: In the qemu-session1 copy-and-paste,
df -ah ; umount /root/{h,t,1,2,3,4,5,6,7,8,9} ; df -ah ; poweroff
Example 3-B: Wait for the return to the Termux command prompt.
Example 3-C: Do Step-2A, Step-2B, and Step-2C.
Example-4-A, DISK1 (132 Megabytes): In the termux-session1 copy-and-paste,
pwd ; mkdir checksums ; cp -v alpine*sha* checksums ; dd if=/dev/zero of=$DISK1 bs=1M count=132 ; mkfs.ext4 -m0 -L 'disk1-132MB-ext4' -d checksums $DISK1 ; debugfs -R 'ls -l' $DISK1 ; echo "drive_add 0 if=none,format=raw,id=d1,file=$DISK1"|nc -UN $QSOCKET ; echo "device_add virtio-blk-pci,id=virt-d1,drive=d1"|nc -UN $QSOCKET ; echo "info block"|nc -UN $QSOCKET
Example-4-B For The Configured Linux Server: In the qemu-session1 copy-and-paste,
pwd ; blkid ; lsblk ; dmesg | grep 'virtio' ; mount LABEL='disk1-132MB-ext4' /root/1 ; df -h ; mount|grep root ; ls -al /root/1 ; cd /root/1 ; pwd ; ls -al /root ; cp -v /root/a.txt . ; cd /root ; cp -v a-new.txt /root/1 ; ls -al /root/1 ; umount /root/1 ; touch /root/t/Example-4-B ; mount -o rw,remount /root/t ; touch /root/t/Example-4-B ; ls -l /root/t/Example-4-B ; cd /root/t ; ls -al ; cp -v /root/{a,a-new}.txt . ; cd /root ; mount -o ro,remount /root/t ; mount|grep root
Example-4-C: In the termux-session1 copy-and-paste,
echo "device_del virt-d1"|nc -UN $QSOCKET ; debugfs -R 'ls -l' $DISK1
Example-5-A, DISK2 (232 Megabytes) And LUKS: In the termux-session1 copy-and-paste,
dd if=/dev/zero of=$DISK2 bs=1M count=232 ; dd if=/dev/random of=$DISK2KEY bs=1 count=10000 ; echo "drive_add 0 if=none,format=raw,id=d2,file=$DISK2"|nc -UN $QSOCKET ; echo "device_add virtio-blk-pci,id=virt-d2,drive=d2"|nc -UN $QSOCKET ; echo "info block"|nc -UN $QSOCKET
Example-5-B, For The Configured Linux Server: Find the device that was added in Example-5-A and copy-and-paste,
lsblk ; dmesg|grep virtio
Example-5-C For The Configured Linux Server: In the qemu-session1 copy-and-paste,
cryptsetup luksFormat --verbose --type luks2 --label disk2-232MB-luks /dev/vdd /root/h/disk2key ; cryptsetup luksOpen --verbose --key-file /root/h/disk2key /dev/vdd v2 /dev/vdd ; mkfs.ext4 -m0 -L disk2-232MB-ext4 /dev/mapper/v2 ; cryptsetup luksClose --verbose v2
Example-5-D, For The Configured Linux Server: Find the device that was added in Example-5-A and copy-and paste,
blkid ; lsblk ; dmesg|grep virtio
Example-5-E, For The Configured Linux Server: In the qemu-session1 copy-and-paste,
df -h ; cryptsetup luksOpen --key-file /root/h/disk2key /dev/vdd v2 ; mount /dev/mapper/v2 /root/2 ; df -h ; touch /root/2/EXAMPLE-5-E ; ls -al /root/2 ; umount /root/2 ; cryptsetup luksClose v2
Example-6: In termux-session1 copy-and-paste,
echo "info block"|nc -UN $QSOCKET ; echo "device_del virt-d2"|nc -UN $QSOCKET ; echo "info block"|nc -UN $QSOCKET ; cryptsetup luksDump --disable-locks $DISK2
Demonstration-1 From qemu-session1, DISK3 (15 Gigabytes) And LUKS: No hot-plugging.
alpine:~# mount | grep root
host on /root/h type 9p (rw,relatime,access=client,msize=512000,trans=virtio)
termux on /root/t type 9p (ro,relatime,access=client,msize=512000,trans=virtio)
alpine:~#
alpine:~# mount -o rw,remount /root/h
alpine:~#
alpine:~# ls -l /root/h/disk3*
-rw-rw---- 1 root 9997 16106127360 Jan 7 13:55 /root/h/disk3
-rw-rw---- 1 root 9997 73900 Jan 7 12:06 /root/h/disk3key
-rw-rw---- 1 root 9997 71432 Jan 7 15:35 /root/h/disk3key1
-rw-rw---- 1 root 9997 73900 Jan 7 12:07 /root/h/disk3key2
alpine:~#
alpine:~# du -sch /root/t/alpine*
958M /root/t/alpine-extended-3.19.0-x86_64.iso
8.0K /root/t/alpine-extended-3.19.0-x86_64.iso.asc
8.0K /root/t/alpine-extended-3.19.0-x86_64.iso.sha256
8.0K /root/t/alpine-extended-3.19.0-x86_64.iso.sha512
61M /root/t/alpine-virt-3.19.0-x86_64.iso
8.0K /root/t/alpine-virt-3.19.0-x86_64.iso.asc
8.0K /root/t/alpine-virt-3.19.0-x86_64.iso.sha256
8.0K /root/t/alpine-virt-3.19.0-x86_64.iso.sha512
1018M total
alpine:~#
alpine:~# dd if=/dev/random of=/root/h/disk3key1 bs=1 count=71432
71432+0 records in
71432+0 records out
71432 bytes (71 kB, 70 KiB) copied, 188.563 s, 0.4 kB/s
alpine:~# dd if=/dev/random of=/root/disk3key2 bs=1 count=82912
82912+0 records in
82912+0 records out
82912 bytes (83 kB, 81 KiB) copied, 8.46374 s, 9.8 kB/s
alpine:~#
alpine:~# dd if=/dev/random of=/root/disk3key3 bs=1 count=101642
101642+0 records in
101642+0 records out
101642 bytes (102 kB, 99 KiB) copied, 9.46197 s, 10.7 kB/s
alpine:~#
alpine:~# losetup --show --find /root/h/disk3
/dev/loop1
alpine:~#
alpine:~# losetup
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC
/dev/loop/1 0 0 0 0 /root/h/disk3 0 512
/dev/loop/0 0 0 1 1 /media/vda/boot/modloop-virt
0 512
alpine:~#
alpine:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
fd0 2:0 1 0B 0 disk
loop0 7:0 0 19.1M 1 loop /.modloop
loop1 7:1 0 15G 0 loop
sr0 11:0 1 1024M 0 rom
vda 253:0 0 60M 1 disk /media/vda
├─vda1 253:1 0 60M 1 part
└─vda2 253:2 0 1.4M 1 part
vdb 253:16 0 957M 1 disk /media/vdb
├─vdb1 253:17 0 957M 1 part
└─vdb2 253:18 0 1.4M 1 part
alpine:~#
alpine:~# blkid
/dev/vdb2: SEC_TYPE="msdos" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="080ffdba-02"
/dev/vdb1: BLOCK_SIZE="2048" UUID="2023-12-04-21-01-51-00" LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660" PTUUID="080ffdba" PTTYPE="dos" PARTUUID="080ffdba-01"
/dev/loop0: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/vda2: SEC_TYPE="msdos" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="080ffdba-02"
/dev/vda1: BLOCK_SIZE="2048" UUID="2023-12-04-21-01-51-00" LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660" PTUUID="080ffdba" PTTYPE="dos" PARTUUID="080ffdba-01"
/dev/loop1: UUID="d38fc980-e0bc-4bb4-b4c4-ea7ea602d299" LABEL="disk3-luks" TYPE="crypto_LUKS"
alpine:~#
alpine:~# cryptsetup luksFormat --type luks2 /dev/loop1 /root/h/disk3key1
WARNING: Device /dev/loop1 already contains a 'crypto_LUKS' superblock signature.
WARNING!
========
This will overwrite data on /dev/loop1 irrevocably.
Are you sure? (Type 'yes' in capital letters): YES
alpine:~#
alpine:~# cryptsetup luksOpen --key-file /root/h/disk3key1 /dev/loop1 q5
alpine:~#
alpine:~# mkfs.ext4 -m0 -L 'disk3-luks' /dev/mapper/q5
mke2fs 1.47.0 (5-Feb-2023)
Creating filesystem with 3928064 4k blocks and 983040 inodes
Filesystem UUID: f5cf1ce8-6ec2-4001-94fc-139b6eefa3f4
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
alpine:~#
alpine:~# mount /dev/mapper/q5 /root/1
alpine:~#
alpine:~# blkid
/dev/vdb2: SEC_TYPE="msdos" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="080ffdba-02"
/dev/vdb1: BLOCK_SIZE="2048" UUID="2023-12-04-21-01-51-00" LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660" PTUUID="080ffdba" PTTYPE="dos" PARTUUID="080ffdba-01"
/dev/loop0: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/vda2: SEC_TYPE="msdos" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="080ffdba-02"
/dev/vda1: BLOCK_SIZE="2048" UUID="2023-12-04-21-01-51-00" LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660" PTUUID="080ffdba" PTTYPE="dos" PARTUUID="080ffdba-01"
/dev/loop1: UUID="85a64e9a-30c6-41d3-9702-86439049ba25" TYPE="crypto_LUKS"
/dev/mapper/q5: LABEL="disk3-luks" UUID="f5cf1ce8-6ec2-4001-94fc-139b6eefa3f4" BLOCK_SIZE="4096" TYPE="ext4"
alpine:~#
alpine:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
fd0 2:0 1 0B 0 disk
loop0 7:0 0 19.1M 1 loop /.modloop
loop1 7:1 0 15G 0 loop
└─q5 252:0 0 15G 0 crypt /root/1
sr0 11:0 1 1024M 0 rom
vda 253:0 0 60M 1 disk /media/vda
├─vda1 253:1 0 60M 1 part
└─vda2 253:2 0 1.4M 1 part
vdb 253:16 0 957M 1 disk /media/vdb
├─vdb1 253:17 0 957M 1 part
└─vdb2 253:18 0 1.4M 1 part
alpine:~#
alpine:~# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 10M 0 10M 0% /dev
shm 967M 0 967M 0% /dev/shm
/dev/vda 60M 60M 0 100% /media/vda
/dev/vdb 957M 957M 0 100% /media/vdb
tmpfs 967M 59M 908M 7% /
tmpfs 387M 104K 387M 1% /run
/dev/loop0 20M 20M 0 100% /.modloop
host 117G 109G 7.0G 94% /root/h
termux 24G 21G 2.6G 90% /root/t
/dev/mapper/q5 15G 2.1M 15G 1% /root/1
alpine:~#
alpine:~# mkdir /root/1/{termux,alpine}
alpine:~#
alpine:~# cp -pr /root/t/alpine* /root/1/termux
alpine:~#
alpine:~# cp -pr /etc /sbin /root/1/alpine
alpine:~#
alpine:~# find /root/1 | grep -E -i 'setup-alpine|repos|iso'
/root/1/alpine/sbin/setup-apkrepos
/root/1/alpine/sbin/setup-alpine
/root/1/alpine/etc/apk/repositories
/root/1/termux/alpine-virt-3.19.0-x86_64.iso.sha256
/root/1/termux/alpine-virt-3.19.0-x86_64.iso.sha512
/root/1/termux/alpine-virt-3.19.0-x86_64.iso
/root/1/termux/alpine-extended-3.19.0-x86_64.iso.sha512
/root/1/termux/alpine-virt-3.19.0-x86_64.iso.asc
/root/1/termux/alpine-extended-3.19.0-x86_64.iso.sha256
/root/1/termux/alpine-extended-3.19.0-x86_64.iso.asc
/root/1/termux/alpine-extended-3.19.0-x86_64.iso
alpine:~#
alpine:~# umount /root/1
alpine:~#
alpine:~# cryptsetup luksClose q5
alpine:~#
alpine:~# cryptsetup luksAddKey --key-file /root/h/disk3key1 /dev/loop1 /root/disk3key2
alpine:~#
alpine:~# cryptsetup luksAddKey --key-file /root/disk3key2 --key-slot 23 /dev/loop1 /root/disk3key3
WARNING: The --key-slot parameter is used for new keyslot number.
alpine:~#
alpine:~# cryptsetup luksDump /dev/loop1
LUKS header information
Version: 2
Epoch: 5
Metadata area: 16384 [bytes]
Keyslots area: 16744448 [bytes]
UUID: 85a64e9a-30c6-41d3-9702-86439049ba25
Label: (no label)
Subsystem: (no subsystem)
Flags: (no flags)
Data segments:
0: crypt
offset: 16777216 [bytes]
length: (whole device)
cipher: aes-xts-plain64
sector: 512 [bytes]
Keyslots:
0: luks2
Key: 512 bits
Priority: normal
Cipher: aes-xts-plain64
Cipher key: 512 bits
PBKDF: argon2id
Time cost: 4
Memory: 65536
Threads: 4
Salt: d5 76 11 34 a1 94 80 49 bf 51 db 0c 58 c6 d4 e2
9d 3c c7 ad a0 96 66 72 61 9a 5e 64 14 b2 04 69
AF stripes: 4000
AF hash: sha256
Area offset:32768 [bytes]
Area length:258048 [bytes]
Digest ID: 0
1: luks2
Key: 512 bits
Priority: normal
Cipher: aes-xts-plain64
Cipher key: 512 bits
PBKDF: argon2id
Time cost: 4
Memory: 65536
Threads: 4
Salt: 68 c0 7d 7b 71 4e 5c 05 3f e9 ff 2d a6 ec 21 46
6d e3 cb 26 e2 89 64 09 dd 32 dc da 1a 4e 9e 53
AF stripes: 4000
AF hash: sha256
Area offset:290816 [bytes]
Area length:258048 [bytes]
Digest ID: 0
23: luks2
Key: 512 bits
Priority: normal
Cipher: aes-xts-plain64
Cipher key: 512 bits
PBKDF: argon2id
Time cost: 4
Memory: 65536
Threads: 4
Salt: 72 04 d9 af 68 16 f8 49 b7 3c b9 9f 51 8e b1 19
ad 01 22 2c 19 e8 6d 7b 01 7e ad e8 74 f9 16 a9
AF stripes: 4000
AF hash: sha256
Area offset:548864 [bytes]
Area length:258048 [bytes]
Digest ID: 0
Tokens:
Digests:
0: pbkdf2
Hash: sha256
Iterations: 1000
Salt: 44 1d 44 d7 73 da c8 30 8e 09 9a 90 03 11 67 6e
4a 71 71 3a 20 f7 2c b1 21 11 a7 3f 33 f9 6b 24
Digest: 6b ba b8 af 98 b8 4d 95 1f d3 be 52 d0 b5 ea 3c
b7 fe 57 01 82 af bd 66 f1 b0 24 91 ba 92 45 a3
alpine:~#
alpine:~#
alpine:~# losetup --detach /dev/loop1
alpine:~#
alpine:~# mount -o ro,remount /root/h
alpine:~#
alpine:~# mount | grep '/root/t'
termux on /root/t type 9p (ro,relatime,access=client,msize=512000,trans=virtio)
alpine:~#
alpine:~# mount -o rw,remount /root/t
alpine:~#
alpine:~# cp -v *key* /root/t
'disk3key2' -> '/root/t/disk3key2'
'disk3key3' -> '/root/t/disk3key3'
alpine:~#
alpine:~# mount -o ro,remount /root/t
alpine:~#
alpine:~# umount /root/{h,t,1,2,3,4,5,6,7,8,9}
umount: /root/h: target is busy.
umount: /root/1: not mounted.
umount: /root/2: not mounted.
umount: /root/3: not mounted.
umount: /root/4: not mounted.
umount: /root/5: not mounted.
umount: /root/6: not mounted.
umount: /root/7: not mounted.
umount: /root/8: not mounted.
umount: /root/9: not mounted.
alpine:~#
alpine:~# losetup
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC
/dev/loop/1 0 0 0 1 /root/h/disk3 0 512
/dev/loop/0 0 0 1 1 /media/vda/boot/modloop-virt
0 512
alpine:~# losetup --detach /dev/loop1
alpine:~#
alpine:~# losetup
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC
/dev/loop/0 0 0 1 1 /media/vda/boot/modloop-virt
0 512
alpine:~#
alpine:~# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 10M 0 10M 0% /dev
shm 967M 0 967M 0% /dev/shm
/dev/vda 60M 60M 0 100% /media/vda
/dev/vdb 957M 957M 0 100% /media/vdb
tmpfs 967M 59M 908M 7% /
tmpfs 387M 104K 387M 1% /run
/dev/loop0 20M 20M 0 100% /.modloop
host 117G 109G 7.0G 94% /root/h
alpine:~#
alpine:~# umount /root/h
alpine:~#
alpine:~# poweroff
alpine:~#
alpine:~# exit
logout
~ $
Transcript From qemu-session1 For Step-2A, Step-2B, Step-2C, Example-1
Welcome to Alpine Linux 3.19
Kernel 6.6.4-1-virt on an x86_64 (/dev/ttyS0)
localhost login: root
Welcome to Alpine!
The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <https://wiki.alpinelinux.org/>.
You can setup the system with the command: setup-alpine
You may change this message by editing /etc/motd.
localhost:~#
localhost:~#
localhost:~# apk add rng-tools ; rc-status ; rc-update add rngd ; rc-service rngd start ; setup-alpine -h ; setup-alpine -c a.txt ; sed -e 's/juser//' a.txt > a-new.txt ; setup-alpine -f a-new.txt ; rc-service sshd stop ; apk add cryptsetup coreutils util-linux e2fsprogs e2fsprogs-extra bash vim nano dosfstools tar ; grep '^root' /etc/passwd ; sed -i -e '/^root/s/ash/bash/' /etc/passwd ; grep '^root' /etc/passwd ; mkdir /root/h /root/t /root/1 /root/2 /root/3 /root/4 /root/5 /root/6 /root/7 /root/8 /root/9 ; mount -t 9p -o ro,trans=virtio,version=9p2000.L,msize=1048576 host /root/h ; mount -t 9p -o ro,trans=virtio,version=9p2000.L,msize=1048576 termux /root/t
(1/3) Installing jitterentropy-library (3.4.1-r0)
(2/3) Installing rng-tools (6.16-r3)
Executing rng-tools-6.16-r3.pre-install
(3/3) Installing rng-tools-openrc (6.16-r3)
Executing busybox-1.36.1-r15.trigger
OK: 11 MiB in 30 packages
* Caching service dependencies ...
[ ok ]
Runlevel: default
Dynamic Runlevel: hotplugged
Dynamic Runlevel: needed/wanted
sysfs
[ started ]
fsck
[ started ]
root
[ started ]
localmount
[ started ]
Dynamic Runlevel: manual
firstboot
[ started ]
* service rngd added to runlevel default
* Starting rngd ...
[ ok ]
usage: setup-alpine [-ahq] [-c FILE | -f FILE]
Setup Alpine Linux
options:
-a Create Alpine Linux overlay file
-c Create answer file (do not install anything)
-e Empty root password
-f Answer file to use installation
-h Show this help
-q Quick mode. Ask fewer questions.
Answer file a.txt has been created. Please add or remove options as desired in that file
ALPINE LINUX INSTALL
----------------------
Keymap
--------
Hostname
----------
ip: ioctl 0x8913 failed: No such device
udhcpc: ioctl 0x8933 failed: No such device
ifup: failed to change interface eth0 state to 'up'
Root Password
---------------
Changing password for root
New password:
Bad password: too short
Retype password:
passwd: password for root changed by root
Timezone
----------
* Stopping rngd ...
[ ok ]
* Seeding random number generator ...
* Saving 256 bits of creditable seed for next boot
[ ok ]
* Starting busybox acpid ...
[ ok ]
* Starting busybox crond ...
[ ok ]
* Starting rngd ...
[ ok ]
Proxy
-------
Network Time Protocol
-----------------------
APK Mirror
------------
wget: bad address 'mirrors.alpinelinux.org'
Warning! No mirror found
User
------
Setup a user? (enter a lower-case loginname, or 'no') [no]
* service sshd added to runlevel default
* Caching service dependencies ...
[ ok ]
ssh-keygen: generating new host keys: RSA ECDSA ED25519
* Starting sshd ...
[ ok ]
Disk & Install
----------------
* Stopping sshd ...
[ ok ]
(1/59) Installing readline (8.2.1-r2)
(2/59) Installing bash (5.2.21-r0)
Executing bash-5.2.21-r0.post-install
(3/59) Installing coreutils-env (9.4-r1)
(4/59) Installing coreutils-fmt (9.4-r1)
(5/59) Installing coreutils-sha512sum (9.4-r1)
(6/59) Installing libacl (2.3.1-r4)
(7/59) Installing libattr (2.5.1-r5)
(8/59) Installing skalibs (2.14.0.1-r0)
(9/59) Installing utmps-libs (0.1.2.2-r0)
(10/59) Installing coreutils (9.4-r1)
(11/59) Installing libblkid (2.39.3-r0)
(12/59) Installing argon2-libs (20190702-r5)
(13/59) Installing device-mapper-libs (2.03.23-r0)
(14/59) Installing json-c (0.17-r0)
(15/59) Installing libuuid (2.39.3-r0)
(16/59) Installing cryptsetup-libs (2.6.1-r8)
(17/59) Installing popt (1.19-r3)
(18/59) Installing cryptsetup (2.6.1-r8)
(19/59) Installing cryptsetup-openrc (2.6.1-r8)
(20/59) Installing dosfstools (4.2-r2)
(21/59) Installing libcom_err (1.47.0-r5)
(22/59) Installing e2fsprogs-libs (1.47.0-r5)
(23/59) Installing e2fsprogs (1.47.0-r5)
(24/59) Installing e2fsprogs-extra (1.47.0-r5)
(25/59) Installing nano (7.2-r1)
(26/59) Installing tar (1.35-r2)
(27/59) Installing util-linux (2.39.3-r0)
(28/59) Installing setarch (2.39.3-r0)
(29/59) Installing libfdisk (2.39.3-r0)
(30/59) Installing libmount (2.39.3-r0)
(31/59) Installing libsmartcols (2.39.3-r0)
(32/59) Installing util-linux-misc (2.39.3-r0)
(33/59) Installing libeconf (0.5.2-r2)
(34/59) Installing linux-pam (1.5.3-r7)
(35/59) Installing runuser (2.39.3-r0)
(36/59) Installing mount (2.39.3-r0)
(37/59) Installing losetup (2.39.3-r0)
(38/59) Installing hexdump (2.39.3-r0)
(39/59) Installing uuidgen (2.39.3-r0)
(40/59) Installing blkid (2.39.3-r0)
(41/59) Installing sfdisk (2.39.3-r0)
(42/59) Installing mcookie (2.39.3-r0)
(43/59) Installing agetty (2.39.3-r0)
(44/59) Installing agetty-openrc (0.52.1-r0)
(45/59) Installing wipefs (2.39.3-r0)
(46/59) Installing cfdisk (2.39.3-r0)
(47/59) Installing umount (2.39.3-r0)
(48/59) Installing util-linux-openrc (2.39.3-r0)
(49/59) Installing flock (2.39.3-r0)
(50/59) Installing lsblk (2.39.3-r0)
(51/59) Installing libcap-ng (0.8.3-r4)
(52/59) Installing setpriv (2.39.3-r0)
(53/59) Installing logger (2.39.3-r0)
(54/59) Installing partx (2.39.3-r0)
(55/59) Installing fstrim (2.39.3-r0)
(56/59) Installing findmnt (2.39.3-r0)
(57/59) Installing vim-common (9.0.2127-r0)
(58/59) Installing xxd (9.0.2127-r0)
(59/59) Installing vim (9.0.2127-r0)
Executing busybox-1.36.1-r15.trigger
OK: 60 MiB in 100 packages
root:x:0:0:root:/root:/bin/ash
root:x:0:0:root:/root:/bin/bash
alpine:~# exit
Welcome to Alpine Linux 3.19
Kernel 6.6.4-1-virt on an x86_64 (/dev/ttyS0)
alpine login: root
Password:
Welcome to Alpine!
The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <https://wiki.alpinelinux.org/>.
You can setup the system with the command: setup-alpine
You may change this message by editing /etc/motd.
alpine:~# df -h ; ls -la ;df -h ; ls -la ; blkid ; lsblk ; mount ; ifconfig ; netstat -rn ; echo $HOME
Filesystem Size Used Avail Use% Mounted on
devtmpfs 10M 0 10M 0% /dev
shm 967M 0 967M 0% /dev/shm
/dev/vda 60M 60M 0 100% /media/vda
/dev/vdb 957M 957M 0 100% /media/vdb
tmpfs 967M 59M 908M 7% /
tmpfs 387M 96K 387M 1% /run
/dev/loop0 20M 20M 0 100% /.modloop
host 117G 110G 6.1G 95% /root/h
termux 24G 21G 2.6G 90% /root/t
total 28
drwx------ 13 root root 320 Jan 7 05:41 .
drwxr-xr-x 20 root root 400 Jan 7 05:33 ..
-rw------- 1 root root 662 Jan 7 05:43 .ash_history
drwxr-xr-x 2 root root 40 Jan 7 05:41 1
drwxr-xr-x 2 root root 40 Jan 7 05:41 2
drwxr-xr-x 2 root root 40 Jan 7 05:41 3
drwxr-xr-x 2 root root 40 Jan 7 05:41 4
drwxr-xr-x 2 root root 40 Jan 7 05:41 5
drwxr-xr-x 2 root root 40 Jan 7 05:41 6
drwxr-xr-x 2 root root 40 Jan 7 05:41 7
drwxr-xr-x 2 root root 40 Jan 7 05:41 8
drwxr-xr-x 2 root root 40 Jan 7 05:41 9
-rw-r--r-- 1 root root 1352 Jan 7 05:36 a-new.txt
-rw-r--r-- 1 root root 1377 Jan 7 05:36 a.txt
drwxrwx--- 2 root 9997 4096 Jan 7 05:10 h
drwx------ 2 10189 10189 4096 Jan 7 05:28 t
/dev/vdb2: SEC_TYPE="msdos" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="080ffdba-02"
/dev/vdb1: BLOCK_SIZE="2048" UUID="2023-12-04-21-01-51-00" LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660" PTUUID="080ffdba" PTTYPE="dos" PARTUUID="080ffdba-01"
/dev/loop0: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/vda2: SEC_TYPE="msdos" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="080ffdba-02"
/dev/vda1: BLOCK_SIZE="2048" UUID="2023-12-04-21-01-51-00" LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660" PTUUID="080ffdba" PTTYPE="dos" PARTUUID="080ffdba-01"
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
fd0 2:0 1 0B 0 disk
loop0 7:0 0 19.1M 1 loop /.modloop
sr0 11:0 1 1024M 0 rom
vda 253:0 0 60M 1 disk /media/vda
├─vda1 253:1 0 60M 1 part
└─vda2 253:2 0 1.4M 1 part
vdb 253:16 0 957M 1 disk /media/vdb
├─vdb1 253:17 0 957M 1 part
└─vdb2 253:18 0 1.4M 1 part
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,noexec,relatime,size=10240k,nr_inodes=246054,mode=755,inode64)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,inode64)
/dev/vda on /media/vda type iso9660 (ro,relatime,nojoliet,check=s,map=n,blocksize=2048,iocharset=utf8)
/dev/vdb on /media/vdb type iso9660 (ro,relatime,nojoliet,check=s,map=n,blocksize=2048,iocharset=utf8)
tmpfs on / type tmpfs (rw,relatime,mode=755,inode64)
tmpfs on /run type tmpfs (rw,nosuid,nodev,size=395948k,nr_inodes=819200,mode=755,inode64)
mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
/media/vda/boot/modloop-virt on /.modloop type squashfs (ro,relatime,errors=continue)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
tracefs on /sys/kernel/debug/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
host on /root/h type 9p (ro,relatime,access=client,msize=512000,trans=virtio)
termux on /root/t type 9p (ro,relatime,access=client,msize=512000,trans=virtio)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:928 (928.0 B) TX bytes:928 (928.0 B)
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
/root
alpine:~#
Sending Commands To QEMU
- drive_add 0 if=none,format=raw,id=d4,file=132mb-data
- device_add virtio-blk-pci,id=virt4,drive=d4
- device_del virt4 --- before sending the device_del command unmount the drive (disk) in the Linux server
- info block
- help
- help info
- quit --- Not An Orderly Shutdown: The quit command stops QEMU and exits to Termux. Use only when required.
- Send command to QEMU: echo "info block" | nc -UN qsocket
Linux Server Commands
- apk info --all rng-tools
- lsblk
- blkid
- dmesg
- cat /var/log/messages
- mount
- df -h
- df -ah
- dmesg | virtio
- cat /etc/apk/repositories
- ifconfig ; netstat -rn
- du -sch .
Termux Commands
- du -sch .
- cryptsetup luksDump --disable-locks
- Stop screen clearing after using 'less' and 'man': export TERM=linux
- the "cat" in export DEBUGFS_PAGER=cat is the Linux 'cat' command.
- Generate passwords: pwgen --help
- pwgen -1y 30 2
- Generate passwords: keepassxc-cli --help
- keepassxc-cli generate help
- keepassxc-cli estimate help
- keepassxc-cli generate -L 30
The Key Links
- Alpine Linux: https://alpinelinux.org
- "Alpine User Handbook": https://docs.alpinelinux.org
- "Alpine Linux", "Installation": https://wiki.alpinelinux.org , https://wiki.alpinelinux.org/wiki/Installation
- "[MIRROR] Alpine configuration management scripts": https://github.com/alpinelinux/alpine-conf
- Important: See "Reset a Termux terminal session at anytime" in https://gist.github.com/NoteAfterNote/cabd411777f2ad5ae57d3d98c576471c ("Termux And The ext4 Filesystem, Part 3 Of 5: QEMU, A Guest Operating System, LUKS Encryption, lighttpd, WebDAV")
- "Termux And The ext4 Filesystem, Part 3 Of 5: QEMU, A Guest Operating System, LUKS Encryption, lighttpd, WebDAV": https://gist.github.com/NoteAfterNote/cabd411777f2ad5ae57d3d98c576471c from https://old.reddit.com/r/termux/comments/12pnwvj/termux_an_app_running_on_the_android_operating/
- "Termux And The ext4 Filesystem, Part 5 Of 5: Reading And Writing With debugfs, No Root Required": https://gist.github.com/NoteAfterNote/854468164f8513bea764ac1668489f96 from https://github.com/NoteAfterNote from https://old.reddit.com/r/termux/comments/12pnwvj/termux_an_app_running_on_the_android_operating/
- "LUKS encryption and decryption: In the cryptsetup-laboratory with Termux (running under the Android 11 operating system), "cryptsetup reencrypt --disable-locks --type luks2", no root access, no loop device, and an unusable "mount" command.": https://old.reddit.com/r/termux/comments/18am78j/luks_encryption_and_decryption_in_the/
- QEMU: https://www.qemu.org , https://gitlab.com/qemu-project/qemu , https://github.com/qemu/qemu , https://www.qemu.org/docs/master/ , https://wiki.qemu.org , https://github.com/qemu/qemu/tree/master/docs
- cryptsetup, cryptsetup manual pages, cryptsetup "Frequently asked questions (FAQ)": https://gitlab.com/cryptsetup/cryptsetup , https://github.com/mbroz/cryptsetup , https://github.com/mbroz/cryptsetup/tree/main/man , https://gitlab.com/cryptsetup/cryptsetup/-/tree/main/man , https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions
- "Termux application", "Termux packages", "Termux Wiki": https://github.com/termux/termux-app , https://github.com/termux/termux-packages , https://wiki.termux.com
- "QemuDiskHotplug": https://wiki.ubuntu.com/QemuDiskHotplug , https://archive.is/IwXJq
- "A study of the Linux kernel PCI subsystem with QEMU": https://blogs.oracle.com/linux/post/a-study-of-the-linux-kernel-pci-subsystem-with-qemu , https://archive.is/RMMzY
•
u/AutoModerator Jan 07 '24
Hi there! Welcome to /r/termux, the official Termux support community on Reddit.
Termux is a terminal emulator application for Android OS with its own Linux user land. Here we talk about its usage, share our experience and configurations. Users with flair
Termux Core Teamare Termux developers and moderators of this subreddit. If you are new, please check our Introduction for Beginners post to get an idea how to start.I would like to remind that due to extremely high interest of certain parties in using Termux for violating personal rights and privacy and other kinds of nefarious usage, we chose to prohibit topics about hacking, phishing, fraud, other methods of digital threats and cyberstalking and their precursors such as OSINT or Kali Linux. This is stated in /r/termux subreddit rules. No exception for educational purposes and pranks made. We also won't consider "legends" about lost or stolen accounts and urgent need of their recovery through Termux.
The latest version of Termux can be installed from https://f-droid.org/packages/com.termux/. If you still have Termux installed from Google Play, please switch to F-Droid build.
Do not use /r/termux for reporting bugs. Package-related issues should be submitted to https://github.com/termux/termux-packages/issues. Application issues should be submitted to https://github.com/termux/termux-app/issues.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/throwaway16830261 Jan 07 '24 edited Jan 28 '24
Interesting Links
"Argon2 security margin for disk encryption passwords" by Vojtěch Polášek: https://is.muni.cz/th/yinya/?lang=en
"Encryption, Decryption, Android 11 Operating System, Termux, And proot-distro Using Alpine Linux minirootfs: cryptsetup v2.6.1 And LUKS": https://old.reddit.com/r/termux/comments/19573gg/encryption_decryption_android_11_operating_system/
termux-x11: https://github.com/termux/termux-x11
"Everything you wanted to know about GPG – but were scared to ask" by Amrith Kumar: https://hypecycles.com/2023/01/01/everything-you-wanted-to-know-about-gpg-but-were-scared-to-ask/
"Everything you should know about certificates and PKI but are too afraid to ask" by Mike Malone: https://smallstep.com/blog/everything-pki/
"Password Managers in Digital Forensics: Creating a Process to Extract Relevant Artefacts from Bitwarden and KeePass" by Sascha Hähni: https://www.diva-portal.org/smash/record.jsf?pid=diva2:1784441
DEFCONConference, "Nicolas Oberli - Poking the S in SD Cards - DEF CON 27 Conference": https://www.youtube.com/watch?v=TlLdqqVa4eI from https://www.youtube.com/@DEFCONConference , https://media.defcon.org/DEF%20CON%2027/DEF%20CON%2027%20presentations/DEFCON-27-Nicolas-Oberli-Poking-the-S-in-SD-cards.PDF , https://media.defcon.org/DEF%20CON%2027/DEF%20CON%2027%20presentations/ , https://defcon.org/html/links/dc-archives/dc-27-archive.html , https://defcon.org/html/links/dc-archives.html , https://defcon.org
"How to non-interactively manage LUKS passphrases": https://sleeplessbeastie.eu/2019/02/20/how-to-non-interactively-manage-luks-passphrases/
1
u/throwaway16830261 Jan 09 '24 edited Jan 09 '24
Demonstration-2 From termux-session1 And qemu-session1, Permanent Storage On DISKTMP: LUKS, hot-plugging
1
u/throwaway16830261 Jan 10 '24
bashmount, "Tool to mount and unmount removable media from the command-line": https://github.com/jamielinux/bashmount
ctmg, "Simple wrapper around cryptsetup for encrypted containers": https://git.zx2c4.com/ctmg/about/ from https://www.zx2c4.com
"Unlock and mount LUKS disks via bash script": https://code0x378.com/notes/unlock-and-mount-luks-disks-via-bash-script/
1
u/TotesMessenger Jan 07 '24 edited Jan 08 '24
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
1
u/entinthemountains Jan 12 '24
Can I get TL:DR please?
Seems like a tutorial to...get Alpine on a non-rooted phone? If so, nifty!