WorkingTipsOnMultiSeatUbuntu180406

前提

基准操作系统为ubuntu-18.04.6-live-server-amd64.iso, 不可以安装为desktop版本的iso。

系统及包更新

确保系统更新到最新:

$ sudo apt-get update -y && sudo apt-get upgrade -y

安装必要的包:

$ sudo apt-get install -y sddm xfce4 unzip autoconf automake libtool pkg-config build-essential x11proto-dev xserver-xorg-dev libxcb-util-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-shm0-dev libxcb-randr0-dev vim cmake cmake-extras extra-cmake-modules libpam-dev libxcb-xkb-dev qt5-default libqt5qml5 qt5-qmltooling-plugins qtdeclarative5-dev qttools5-dev xutils-dev

Multi-seat编译/配置

multi-seat.tar.gz上传到机器上,解压:

$ tar xzvf multi-seat.tar.gz
$ cd multi-seat/
$ ls
sddm-nested-multiseat  xf86-video-nested sddm_config

编译xf86-video-nested包:

$ cd xf86-video-nested
$ ./autogen.sh && ./configure --prefix=/usr && make -j2 && sudo make install

编译sddm-nested-multiseat包, 生成并更新配置文件:

$ cd sddm-nested-multiseat
$ mkdir build &&  cd build
$ cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release  -Wno-dev .. && make -j2 && sudo make install
$ sudo install -v -dm755 -o sddm -g sddm /var/lib/sddm
$ sddm --example-config > sddm.example.conf
$ sudo cp -v  sddm.example.conf /etc/sddm.conf

更新sddm登陆免密配置文件:

$ cd sddm_config
$ sudo cp * /etc/pam.d

配置桌面登陆

更新xorg定义文件:

$ cd xorg_config
$ sudo mkdir -p /etc/X11/xorg.conf.d
$ sudo cp xorg.conf.d/20-intel.conf /etc/X11/xorg.conf.d
$ sudo cp seat* /etc/X11
$ sudo cp /bin/sed /usr/bin/sed

配置USB口与seat的映射关系(从已有的例子进行修改):

$ cd udev_config
$ vim 70-seat.rules
修改完毕后:   
$ sudo cp 70-seat.rules /etc/udev/rules.d/70-seat.rules

开启multi-seat:

$ sudo vim /etc/default/grub
.....
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash startseat=true"
GRUB_CMDLINE_LINUX="startseat=true"
....
$ sudo update-grub2

建立两个用于登陆的用户:

$ sudo useradd -m seat1
$ sudo useradd -m seat2
$ sudo passwd seat1
$ sudo passwd seat2

配置sddm为两个用户的自动登陆([AutoLogin]内只保留如下所示部分):

# cat /etc/sddm.conf | more
[Autologin]
# Whether sddm should automatically log back into sessions when they exit
# Whether sddm should automatically log back into sessions when they exit
Relogin=false,false
SeatName=seat1,seat2
#Session=awesome,awesome
Session=xfce,xfce
User=seat1,seat2
....
此时重启后可以看到,双屏方案在登陆前自动进入到图形界面并已经实现分屏.   

TipsForSeAndroid

基本概念

SEAndroid是在Android系统中基于SELinux推出的强制访问控制模型,来完善自主访问模型中只要取得root权限就可以为所欲为的情况。
SELinux是一种基于域-类型(domain-type)模型的强制访问控制(MAC)安全系统,其原则是任何进程想在SELinux系统中干任何事,都必须先在安全策略的配置文件中赋予权限。凡是没有在安全策略中配置的权限,进程就没有该项操作的权限。在SELinux出现之前,Linux的安全模型是DAC(DiscretionaryAccess Control),译为自主访问控制。其核心思想是进程理论上所拥有的权限与运行它的用户权限相同。比如,以root用户启动shell,那么shell就有root用户的权限,在Linux系统上能干任何事。这种管理显然比较松散。在SELinux中,如果需要访问资源,系统会先进行DAC检查,不通过则访问失败,然后再进行MAC权限检查。

SEAndroid app分类

app分类:

SELinux(或SEAndroid)将app划分为主要三种类型(根据user不同,也有其他的domain类型):

1.untrusted_app  第三方app,没有Android平台签名,没有system权限
2.platform_app    有android平台签名,没有system权限
3.system_app      有android平台签名和system权限
4.untrusted_app_25 第三方app,没有Android平台签名,没有system权限,其定义如下This file defines the rules for untrusted apps running with targetSdkVersion <= 25.

从上面划分,权限等级,理论上:untrusted_app < platform_app < system_app按照这个进行排序

app_neverallows.te

/home/ctctest/AndroidSources/aosp11_r48/system/sepolicy/prebuilts/api/30.0/private

Line 182, 183 Line 198, comment the proc_version

private/domain.te

Changes to /home/ctctest/AndroidSources/aosp11_r48/system/sepolicy/prebuilts/api/30.0/private/coredomain.te Line187, Line 113,

genfs_contexts

The same as in android9.0 Line43

system_server.te

The same as in Pie Line 987

untrusted_app.te

The same as in Pie Appended in last

untrusted_app_25.te

Line 28, line 38

untrusted_app_27.te

Line 28, 45

untrusted_app_all.te

Line 161

webview_zygote.te

Line 66

zygote.te

Line 235

public/app.te

Line 472, Line 438

public/domain.te

Line 468 Line 490 Line 531 Line 970~LIne973, Line 980 Line 1348

public/file.te

Line 150

public/fsck.te

Line 21

public/init.te

Line 175, 181

public/netd.te

Line 55

public/platform_app.te

Append last

public/shell.te

Line 258, 259

public/system_server.te

Append last

public/vendor_init.te

Line 47~50

public/vold.te

Line 22, 23

public/webview_zygote.te

Append last

Make

WorkingTipsOnAVDHoudini

添加lunch属性

添加一个sdk_phone_x86_64-userdebug的属性:

$ vim build/envsetup.sh
....
add_lunch_combo sdk_phone_x86_64-userdebug

之后在lunch的时候就可以选择了。

更改vendor分区尺寸

更改BOARD_VENDORIMAGE_PARTITION_SIZE的大小:

vim build/make/target/board/generic_x86_64/BoardConfig.mk
...
BOARD_VENDORIMAGE_PARTITION_SIZE := 400000000
...

而后重新开始编译即可:

$ make installclean
$ m -j80

从0开始编译的命令:

source build/envsetup
lunch sdk_phone_x86_64-userdebug
m -j80

/images/2021_10_23_11_11_00_391x702.jpg

直接更改镜像

mount到某个挂载目录:

sudo mount -o loop,offset=1048576 system.img /mnt

实验步骤

初始化的r44镜像:

/images/2021_10_23_11_12_25_499x281.jpg

按照houdini的容器方案替代:

换方法

使用另外一种android发行版:

lineage-16.0
lineage-17.1
lineage-18.1

WorkingTipsOnVirtualNetworkCrossGFW

Environment Description

In virt-manager, create a new isolated virtual network via:

/images/2021_10_18_10_39_01_522x540.jpg

Create VM

Get the openwrt x86 images from:

wget https://downloads.openwrt.org/releases/21.02.0-rc4/targets/x86/64/openwrt-21.02.0-rc4-x86-64-generic-ext4-combined.img.gz
gunzip openwrt-21.02.0-rc4-x86-64-generic-ext4-combined.img.gz 
mv /root/openwrt-21.02.0-rc4-x86-64-generic-ext4-combined.img /var/lib/libvirt/images

Create a new virtual machine using this image:

/images/2021_10_18_11_32_10_487x492.jpg

2-Core , 1024 MB:

/images/2021_10_18_11_32_30_291x173.jpg

Named it zzzz_OpenWRT:

./images/2021_10_18_11_32_44_354x265.jpg

Customize the vm, first define an ethernet card which use default network:

/images/2021_10_18_11_33_46_449x255.jpg

Add a second nic which uses isolated network:

/images/2021_10_18_11_34_20_611x214.jpg

Bootup the machine until you see:

/images/2021_10_18_11_35_07_584x285.jpg

You should use passwd for generating a new password for security.

Configure

Swith the eth0/eth1, cause eth0 will be the lan, while eth1 will be the wan.

/images/2021_10_18_11_49_52_617x258.jpg

Manually set the br-lan address via:

# vim /etc/config/network
- option ipaddr '192.168.1.1'
+ option ipaddr '10.17.18.254'

Login luci via:

/images/2021_10_18_11_52_08_714x545.jpg

Install redsocks via:

# opkg update
# opkg install redsocks

Linuxtips13

1. Install Android Studio

Enable 32-bit library and install some 32-bit libs:

dpkg --add-architecture i386
apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i38

Download from offcial website:

https://developer.android.com/studio, then untar it to:

Ignored

2. vendor.img resize

Install qemu tools via:

# apt-get install -y qemu qemu-utils

Resize via:

# qemu-img resize vendor.img +1G
# mount -o loop,offset=1048576 vendor.img /mnt8/
# losetup -l
# resize2fs /dev/loop9
# df -h | grep mnt8
/dev/loop9      1.1G   67M  1.1G   7% /mnt8

3. waydroid

Install via:

# export DISTRO="focal"
# sudo curl https://repo.waydro.id/waydroid.gpg --output /usr/share/keyrings/waydroid.gpg && \ 
# echo "deb [signed-by=/usr/share/keyrings/waydroid.gpg] https://repo.waydro.id/ $DISTRO main" > ~/waydroid.list && sudo mv ~/waydroid.list /etc/apt/sources.list.d/waydroid.list && sudo apt-get update -y
# sudo apt-get install -y waydroid

Initialize via:

root@vp1:~# waydroid init
[08:42:25] Download https://sourceforge.net/projects/waydroid/files/images/system/lineage/waydroid_x86_64/lineage-17.1-20211007-VANILLA-waydroid_x86_64-system.zip/download
[08:43:29] Validating system image
[08:43:31] Extracting to /var/lib/waydroid/images
[08:43:58] Download https://sourceforge.net/projects/waydroid/files/images/vendor/waydroid_x86_64/lineage-17.1-20211007-MAINLINE-waydroid_x86_64-vendor.zip/download
[08:44:10] Validating vendor image
[08:44:10] Extracting to /var/lib/waydroid/images

conflict with redroid, so ignored.

4. Configure monitor in wayland

Via gnome-control-center we could setup the monitor.

https://blog.csdn.net/ALakers/article/details/102705681
https://blog.imlk.top/blog/51/
https://zhiwei.li/blog/%E7%BC%96%E8%AF%91android_emualtor.html
https://zhiwei.li/blog/android%E6%A8%A1%E6%8B%9F%E5%99%A8rom%E7%BC%96%E8%AF%91.html

6. v2ray

via:

sudo docker run -d --restart=always --privileged --network=host --name=v2raya -v /etc/v2raya:/etc/v2raya mzz2017/v2raya

7. repo sync issue

solved via(python2->python3):

curl https://storage.googleapis.com/git-repo-downloads/repo-1 > ~/bin/repo
chmod a+x ~/bin/repo
python3 ~/bin/repo init -u git@....

8. build blissOS

via:

sudo apt-get install git-core gnupg flex bison maven gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386  lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip squashfs-tools python-mako libssl-dev ninja-build lunzip syslinux syslinux-utils gettext genisoimage gettext bc xorriso libncurses5
sudo apt-get install -y openjdk-8-jdk
repo init -u https://github.com/BlissRoms-x86/manifest.git -b p9.0-x86
repo sync -j24 -c --no-tags --no-clone-bundle
Next step is to download the proprietary files from ChromeOS:
mkdir vendor/bliss_priv/proprietary
mkdir vendor/bliss_priv/source
bash build-x86.sh -r android_x86_64-userdebug
After that, you can build your release file:
bash build-x86.sh android_x86_64-userdebug (to build the userdebug version for x86_64 CPUs)

9. Install gcc/g++ 10

via:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt install gcc-10
For g++-10:
   sudo apt install g++-10

10. tips for houdini

refers to:

https://www.reddit.com/r/Androidx86/comments/nf2kx7/aarch64armv8aarm64_support/

11. Disable unattended upgrade svc

via:

systemctl stop unattended-upgrades.service && systemctl disable unattended-upgrades.service

12. repo sync

using ustc:

repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest
## 如果提示无法连接到 gerrit.googlesource.com,可以编辑 ~/bin/repo,把 REPO_URL 一行替换成下面的:
## REPO_URL = 'https://gerrit-googlesource.proxy.ustclug.org/git-repo'

13. repo sync in cn

via:

repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-9.0.0_r61
repo sync -c
# backup
tar cf - houdini_build/ | pigz -9 -p 32 > houdini_build.tar.gz

14. android 11 add new lunch

via:

# vim build/make/target/product/AndroidProducts.mk
.....
COMMON_LUNCH_CHOICES := \
    aosp_arm64-eng \
    aosp_arm-eng \
    aosp_x86_64-eng \
    aosp_x86-eng \
    sdk_phone_x86_64-userdebug \
# lunch sdk_phone_x86_64
# m -j88

15. stop k3s

via:

/usr/local/bin/k3s-killall.sh
/usr/local/bin/uninstall-all.sh

16. headless vnc server

via:

https://kb.brightcomputing.com/knowledge-base/using-nvidia-gpus-in-x-application-on-a-headless-node-via-vnc/ https://joelgriffiths.com/how-to-configure-nvidia-settings-for-linux-crypto-mining-on-headless-ubuntu-system/

17. disable sleep

disable sleep in ubuntu:

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

18. rotate screen

via:

$ xrandr --output HDMI1 --rotate left

19. speed-up grep

via:

LANG=c grep -i xxxx ./ -r

20. diff ignore directory

via:

diff -qr --exclude=ignoreme ...

21. change default boot item

via:

# vim /etc/default/grub
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 4.15.0-162-generic"
# update-grub2

22. list all users

via:

ps -eo user,uid | awk 'NR>1 && $2 >= 1000 && ++seen[$2]==1{print $1}'

23. remove pci devices

via:

$  vim /etc/udev/rules.d/removesomething.rules
ACTION=="add", KERNEL=="0000:00:03.0", SUBSYSTEM=="pci", RUN+="/bin/sh -c 'echo 1 > /sys/bus/pci/devices/0000:00:03.0/remove'"

24. config gcc

via:

sudo update-alternatives --config gcc

25. Install gcc version

Using gcc 9 via:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9

26. build kernel for 20.10

via:

# rm -f vmlinux-gdb.py 
# vim tools/objtool/elf.c
# make deb-pkg -j$(nproc)

27. Disable gdm sleep mode

via:

sudo -u gdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'

28. Use phoronix for tesing gpu

Steps:

$ sudo dpkg install -y phoronix-test-suite_10.6.1_all.deb
$ sudo apt --fix-broken install
$ phoronix-test-suite list-available-tests
$ export DISPLAY=:0.0
$ phoronix-test-suite install pts/unigine-heaven
$ phoronix-test-suite benchmark pts/unigine-heaven

29. Auto-Login in gdm

via:


Had the same issue, I solved it by enabling 'Timed Login' in the /etc/gdm3/custom.conf file. Mine looks like:

# GDM configuration storage
#
# See /usr/share/gdm/gdm.schemas for a list of available options.

[daemon]
AutomaticLoginEnable=true
AutomaticLogin=username

# Uncoment the line below to force the login screen to use Xorg
#WaylandEnable=false

# Enabling automatic login

# Enabling timed login
TimedLoginEnable = true
TimedLogin = username
TimedLoginDelay = 10

30. Disable auto-sleep in gdm

via:

switch to a VT (e.g. Ctrl+Alt+F3), login as root and run:

su - gdm -s /bin/sh
to switch user to gdm.

then run:

export $(dbus-launch)
and set idle delay to 0 (which translates to never):

GSETTINGS_BACKEND=dconf gsettings set org.gnome.desktop.session idle-delay 0
run exit or hit Ctrl+D to return to root account.

reboot your machine or restart the display manager:

systemctl restart gdm

And:

systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

31. update initramfs

In ubuntu 20.04 update initramfs Via:

update-initramfs -u 

32. termux change repo

via:

termux-change-repo

33. Android Phone Image BAckup

via:

$ aft-mtp-mount ~/mnt

34. remount android partition

via:

:/boot # mount -o rw,remount /boot
:/boot # cp Image  Image.origin 

35. android docker tips

Start dockerd via:

# echo "nameserver 223.5.5.5">/etc/resolv.conf
#  dockerd --iptables=false --dns=223.5.5.5

Start docker instance via:

#  docker run --entrypoint "/system/bin/sleep" redroid/redroid:9.0.0-latest -- 3600 

Enter docker instance and execute the init via:

rpi4:/ # docker exec -it 59eccd0c23ea /system/bin/sh
59eccd0c23ea:/ # /init qemu=1 androidboot.hardware=redroid
59eccd0c23ea:/ # ps -ef
UID            PID  PPID C STIME TTY          TIME CMD
root             1     0 0 12:36 ?        00:00:00 sleep -- 3600
root             7     0 0 12:49 pts/0    00:00:00 sh
root            16     1 0 15:44 136:0    00:00:00 [init]
root            17     1 0 15:44 136:0    00:00:00 [init]
root            18     1 0 15:44 136:0    00:00:00 ueventd
root            43     7 2 58:46 pts/0    00:00:00 ps -ef

36. android docker tips(x86)

Start docker instance via:

docker run --privileged  -p 15589:5555 --memory-swappiness=0 --entrypoint "/system/bin/sleep" redroid:9officialhoudini -- 3600

Enter the docker instance and execute:

a2c9bf73d181:/ # ./init qemu=1 androidboot.hardware=redroid                                              
6|a2c9bf73d181:/ # getprop | grep -i boot | grep comple                                                  
[sys.logbootcomplete]: [0]

37. redroid in docker

via:

# docker run --privileged --memory-swappiness=0  -p 15589:5555 --rm  --entrypoint "/init" redroid/redroid:11.0.0-latest qemu=1 androidboot.hardware=redroid
root@ubuntu:/home/ubuntu# docker ps
dCONTAINER ID   IMAGE                           COMMAND                  CREATED         STATUS         PORTS                                         NAMES
8b4ffa8dcb58   redroid/redroid:11.0.0-latest   "/init qemu=1 androi…"   4 minutes ago   Up 4 minutes   0.0.0.0:15589->5555/tcp, :::15589->5555/tcp   adoring_hertz
root@ubuntu:/home/ubuntu# docker exec -it adoring_hertz sh
8b4ffa8dcb58:/ # getprop | grep boot | grep complete                                                                                                                                         
grep: (standard input): Invalid argument
[dev.bootcomplete]: [1]
[sys.boot_completed]: [1]
[sys.bootstat.first_boot_completed]: [1]

images:

redroid/redroid   11.0.0-latest   7fb7c2776f41   12 days ago    1.47GB

38. remount android system

via:

$ su
# mount -o rw,remount -t ext4 /system

39. Disable oh-my-zsh auto update

via:

DISABLE_UPDATE_PROMPT=true

40. Build Android Kernel

Classical method:

/media/nvme/security/prebuilts/qemu-kernel/build-kernel.sh --arch=x86_64 --config=x86_64_ranchu --out=/root/Code/commonout

41. tim in archlinux

Install via:

$ yay com.qq.tim.spark
$ sudo vim /opt/apps/com.qq.tim.spark/files/run.sh
#......
#Add: 
export XMODIFIERS="@im=fcitx"
export GTK_IM_MODULE="fcitx"
export QT_IM_MODULE="fcitx"
#.....

42. awesome dialog position

Edit the rc.lua via:

 {
      rule = { class = "xxxxx" },
      properties = { 
         placement = awful.placement.centered,
         titlebars_enabled = false,
      }
   },

    -- Set Firefox to always map on the tag named "2" on screen 1.
    -- { rule = { class = "Firefox" },
    --   properties = { screen = 1, tag = "2" } },
}

43. emulator with bridge connection

via:

emulator -avd mmkk -verbose -writable-system -kernel /root/Code/commonout/kernel-qemu -show-kernel -partition-size 61240 -qemu -device virtio-net-pci,netdev=nic0,mac=00:16:3e:0c:12:78 -netdev tap,id=nic0,br=br0,helper=/usr/lib/qemu/qemu-bridge-helper -cpu host -m 16535M -smp cores=10,threads=1,sockets=1

Enter the emulator and find the eth1 to be the bridged connection

44. android 90 building issue

via:

$ make clean-apache-xml
$ make apache-xml
Then: 
$ make clean-ims-common
$ make ims-common
$ make apache-xml
$ make -j12

45. change adb port

via:

setprop service.adb.tcp.port 5555
stop adbd
start adbd

46. /dev/shm issue

via:

mount -t tmpfs tmpfs /dev/shm

47. pm install privileged

via:

adb install --user USER_ID YOUR_APK
adb shell pm install --user USER_ID YOUR_APK

48. card/driver

ethernet card and device driver:

# ls -1 /sys/class/net/ | grep -v lo | xargs -n1 -I{} bash -c 'echo -n {} :" " ; basename `readlink -f /sys/class/net/{}/device/driver`'