Posts

Showing posts with the label Linux

How to install a linux system by copy disk partition

 If you can copy the whole disk, then do it, it works better. 1. copy your old alpine system partition as a iso file, especially make sure the `/boot` folder has files: `vmlinuxz-grsec` and `initramfs-grsec`. `dd if=/dev/sdb2 of=xx.iso` 2. use dd to copy that disk partiton to your new computer partition, a ext4 would be fine. `dd if=xx.iso of=/dev/sdb2` 3. i am using `lubuntu16_i386` system to work as a PE system, all you have to do is install lubuntu16_i386 to another partition of your disk. It will generate a not working version of grub boot menu for you, you can see "unknown linux distrubution" when you boot your computer. you need to fix it later. 4. boot into lubuntu16, `sudo su`, `vim /etc/grub.d/40_custom`, add following to the bottom: ``` menuentry 'Alpine' { insmod part_msdos insmod ext2 set root='hd0,msdos5' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root -...

How to sync data betwen 3 disk storage?

How to sync data in 3 disk storage? 1. You have diskA, diskB, and diskC. diskC should have biggest storage. 2. You compare diskA, diskB and diskC, find common things in 3 disk. find different parts in 3 disk. 3. You manually choose what folder or file in diskA need to get saved. A software will remember that. 4. You manually choose what folder or file in diskB need to get saved. This time it would be easier for you because software remembers some choice you did last time. 5. You copy everything need to get saved from diskA and diskB to diskC. 6. You delete unwanted difference data in diskC. 7. You re-manage diskC data. 8. You copy diskC data into diskA and diskB directly by overwrite everything.

How to set up a socket service as VPN with pure python?

 # Big direction 1. pure python socket proxy service, one py file 2. ufw allow port 3. use proxy_switch extension in broswer 4. "ssh -L 141:127.0.0.1:141 root@5.3.7.5", connect local 141 as remote 141 # Python script ``` """ Small Socks5 Proxy Server in Python from https://github.com/MisterDaneel/ Modified by yingshaoxo """ # Network import socket import select from struct import pack, unpack # System import traceback from threading import Thread, activeCount from signal import signal, SIGINT, SIGTERM from time import sleep import sys from multiprocessing import Process # # Configuration # MAX_THREADS = 200 BUFSIZE = 2048 TIMEOUT_SOCKET = 5 LOCAL_ADDR = '0.0.0.0' LOCAL_PORT = 2121 # Parameter to bind a socket to a device, using SO_BINDTODEVICE # Only root can set this option # If the name is an empty string or None, the interface is chosen when # a routing decision is made # OUTGOING_INTERFACE = "eth0" OUTGOING_INTERFACE = ...

How to set up a webpage_based virtual desktop for your remote linux VPS?

``` docker stop webtop docker rm webtop docker run -d \   --name=webtop \   -e PUID=1000 \   -e PGID=1000 \   -e TZ=Europe/London \   -p 19999:3000 \   -v ~/.webtop:/config \   --shm-size="100mb" \   --restart unless-stopped \   ghcr.io/linuxserver/webtop ``` username abc password abc   http://your_ip:19999  

How to set up jupyter notebook in your server or VPS remotely with subdomain and cloudflare?

 How to set up jupyter notebook in server? # new jupyterlab does not allow cloudflare subdomain access no matter how you try, so we use old pip install jupyterlab==3.2.8 # set up password jupyter lab password # then modify a file 'vim ~/.jupyter/jupyter_server_config.json' to allow subdomain ``` {   "ServerApp": {     "password": "JkZ12Ij",     "allow_origin": "*",     "allow_remote_access": true   } } ~       ``` # new jupyterlab does not have 'jupyter lab' command, so you can only use 'jupyter server'. But it does not allow subdomain access. jupyter lab --ip 127.0.0.1 --port 9998 --allow-root /root/ # I use traefik to do proxy from subdomain to localhost, but use nginx will be easyer since nginx has many tutorial online # auto start, with "crontab -e" @reboot /usr/local/bin/jupyter lab --ip 127.0.0.1 --port 19998 --allow-root /root/

How to make small software project?

How to reduce the burden on developers, reduce software size, optimize program performance, and increase compatibility? For different hardware, systems, and architectures, build different software packages or repositories and let different programmers manage them. For example, vim can be divided into vim_linux, vim_windows, vim_mac, vim_android, etc. If need more precise, it can be divided into vim_linux_amd64, vim_linux_arm64 In this way, you may find that only the developers of Unix are the smartest, and their project have the least amount of code, and their software are most stable. If the project has 0 dependencies, in theory, in that hardware machine it targets to, you can use that software forever without updating or internet access. For people who are looking for general cross platform project, they are stupid. They do not own those hardware or operation systems, so they can't make sure in the future, those stuff won't change. So cross platform software is the most unsta...

Linux USB midi driver in c or python

C: ``` // Linux MIDI input driver, protocol 1.0, there is no need to upgrade to protocol 2.0 // Author: yingshaoxo // Run it in root shell // gcc main.c -o main.run // ./main.run #include <sys/soundcard.h> #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #define  MIDI_DEVICE  "/dev/midi1" //#define  MIDI_DEVICE  "/dev/dmmidi1" //#define  MIDI_DEVICE  "/dev/snd/midiC1D0" int main(void) {     unsigned char inpacket[4];     // first open the sequencer device for reading.     int seqfd = open(MIDI_DEVICE, O_RDONLY);     if (seqfd == -1) {         printf("Error: cannot open %s\n", MIDI_DEVICE);         exit(1);     }     // now just wait around for MIDI bytes to arrive and print them to screen.     while (1) {         read(seqfd, &inpacket, sizeof(inpacket));    ...

Try to stop using Ubuntu and PopOS

Because they starting to become evil. 1. They force you use apt even if you got pip or something like that. And apt software is controlled deeply by them. You can't freely publish your apps. 2. They force you to update the linux_kernel by updating the libc. So for all other software, you have to update linux-kernel to use them. 3. They automatically update snap application without asking users. You can't disable it. 4. They spawn a 'tracker-miner-fs-3' service to spy on your disk. It takes a lot of CPU. And take a lot of space in '~/.cache'. Most of all, you can't directly search files by using that service. It is not open to user. It slow down the computer but gives you no benefit. If you already has an SSD disk, why you need further speed up on file search?   5. They have a service called 'fwupd' to do 'Firmware update' automatically without asking you. If update failed or success, it will auto reboot, which make the linux an unstable syste...

General Linux Install toturial

1. Make sure your disk has 4 partitions: 500MB fat32, 34GB swap, 60GB ext2, 200GB ext4   2. When you install a system, you choose advanced manual install. And don't encrypt your system and data, otherwise you will lose all of them in the future when your system broken.   3. Use fat32 as "/boot/efi", ext2 as "/", ext4 as "/home". Sometimes, you need to format fat32 and ext2.   4. After the installation, the boot menu would be in 500MB fat32 partition, the linux core system would be in 60GB ext2 partition, the home folder would in in 200GB ext4 partition. So that even if you massed up with your system next time, you won't lose your home folder data.   5. If you installed a lot of other system, you can use "sudo update-grub" to add those new system into the boot menu.   6. I would suggest you not to update your bios software because they normally make you harder to install multi-system.

How to compress video and mp3 file with ffmpeg command under Linux?

 How to compress video file by using ffmpeg: ffmpeg -i input.mp4 -c:v libx264 -vf scale=640:360 -r 23.98 -b:v 498k -c:a copy output.mp4 or ffmpeg -i input.mp4 -c:v libx264 -vf scale=640:360 -r 23.98 -b:v 498k -c:a aac -b:a 128k output.mp4 ______ How to compress audio file by using ffmpeg: ffmpeg -i input.mp3 -b:a 128k output.mp3

How to use Linux hibernate (it save the current memory before shut down)

# All in all Hibernate is better than suspend, because it saves memory into disk, so even if your computer power is off, next when you reboot, you won't lose your current working process. # For ubuntu ``` sudo systemctl hibernate ``` https://askubuntu.com/a/1358453 # For PopOS I don't recommend you use newer version that higher than 18.04 or 20.04. Because it will force you upgrade system and adds more restrictions to your computer. It seems all you need to do is: 1. create a swap partition that bigger than your memory. 2. add swap uuid to /etc/fastab. 3. add resume from uuid command to /etc/default/grub. Don't use encrypted stuff, it adds complexity. If you can't prevent your computer physically access from others, why you create gun? ``` # /etc/fstab UUID=3823625d-8404-4774-8346-7d762f63a052 none swap sw 0 0 /dev/mapper/data-swap  none  swap  defaults  0  0 ``` ``` # /etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=3823625d-8404-4774-8346...

Does Android and MacOS created by microsoft secretly?

I recently face a problem from Android system. Syncthing can't sync 'two files with same name but have different case' between Linux and Android. It seems like the Android is working just like Windows system. They do not distinguish `~/Download/HI.png` and `~/Download/hi.png`. Both android and windows will think `~/Download/HI.png` and `~/Download/hi.png` as the same file. Which is not right, which means their storage system is case-insensitive. But for general Linux system, it is fine, linux storage are case-sensitive. Does this mean the android enginner secrectly come from microsoft? I don't know. #android #storage #bug #yingshaoxo

How to draw image directly into a Linux System LCD screen by using frame buffer? (It works in virtualbox)

import os import sys # for exit import mmap # shared memory frame_buffer_number = 'fb0' # device created by the device driver # get width and height f = open(f "/sys/class/graphics/{frame_buffer_number}/virtual_size" , "r" ) width_and_height = f.read() width_string, height_string = width_and_height.split( ',' ) width = int(width_string) # width height = int(height_string) # height f.close # get bits per pixel f = open(f "/sys/class/graphics/{frame_buffer_number}/bits_per_pixel" , "r" ) bpp = int(f.read()) if not bpp in ( 16 , 32 ): print( "Unsupported bpp" ) sys.exit() f.close() # open framebuffer and map it onto a python bytearray frame_buffer_device = open(f "/dev/{frame_buffer_number}" , mode= 'r+b' ) # open R/W frame_buffer_memory_map = mmap.mmap(frame_buffer_device.fileno(), width * height * bpp// 8 , mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ) color = 255 f...

How to download everything under a python HTTP file/folder servering:

 Download everything under a python HTTP servering: In host: ``` python -m http.server ``` In guest: ``` wget -r -np -nH -R / http://192.168.19.22:8000 ```

How to set up a tor website?

Install tor  sudo apt install tor sudo apt install obfs4proxy Modify configs # sudo vim /etc/tor/torrc HiddenServiceDir /root/a_website_config HiddenServicePort 80 127.0.0.1:8080 #ClientTransportPlugin obfs4 exec /usr/bin/obfs4proxy #UseBridges 1 #Bridge obfs4 85.22.11.28:443 alsdfkalhsdfkh cert=akdfkhdakjfdhkjahfkl iat-mode=0 Modify permissions sudo mkdir -p /root/a_website_config cd /root sudo chmod 700 a_website_config Start tor service sudo -u root tor Check the “/root/a_website_config/hostname” So you can get your union url: *.union Install tor browser https://www.torproject.org/download Set up obfs4 bridge When you connect successfully, go to settings, connections, copy a bridge link to somewhere, you may need it later Use tor browser to test if you can connect your website or not If you can connect to your service, go to next step. If you can’t connect to your service, you need to add a bridge for your hidden service. You need to sudo vim /etc/tor/torrc , unco...

How to let LinuxDeploy desktop audio input and output work

Install LinuxDeploy apk; Install busybox apk, install busybox payloads, reboot your phone https://github.com/meefik/linuxdeploy/releases/tag/2.6.0 https://github.com/meefik/busybox/releases/tag/1.34.1 Select Ubuntu, bionic, File, image size 60GB, set username and password, enable ssh, enable vnc gui, select xfce. Hit the install button, hit the configure button, hit the start button. Install “termux” apk, install “com.termux.api” apk https://github.com/termux/termux-app/releases/tag/v0.118.0 https://github.com/termux/termux-api/releases/tag/v0.50.1 In termux pkg update pkg install pulseaudio pkg install termux-api termux-microphone-record -l 3 pulseaudio --start --exit-idle-time=-1 pacmd load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 pacmd load-module module-sles-source pactl load-module module-sles-source In LinuxDeploy system, add “export PULSE_SERVER=127.0.0.1” to the end of “/etc/profile”, do a reboot Use fakestandby apk to make sure the netw...

How to install docker and docker-compose in ubuntu 22.04 with one command

sudo apt install docker-compose ​

How to set up ubuntu server netwrok under virtualbox and host-only adopter

Add another NAT adopter  preferences -> network -> nat networks -> add container settings -> network -> adopter2 -> nat Check available network adopters ls /sys/class/net Config netplan sudo vim /etc/netplan/99_config.yaml : network: version: 2 renderer: networkd ethernets: enp3s0: dhcp4: true sudo netplan apply ​

How to recovery mongodb data after a sudden server shutdown in docker under Linux

I suppose you have mounted the mongo /data/db into a local folder with this command:  volumes: - "./configs/mongodb_data:/data/db" Then you should run this command to recovery the data: chmod 777 /root/it_has_alternatives/configs/mongodb_data docker container run --rm -v /root/it_has_alternatives/configs/mongodb_data:/data/db mongo: 6.0 . 4 -jammy mongod --repair If your docker has some serious problem, you could run the following command to repair it: Make sure all docker containers are down: docker compose down Remove problematic overlay2: sudo rm -R /var/lib/docker/overlay2 Remove images: sudo rm -R /var/lib/docker/image Clear any other cached data: sudo docker system prune -f Restart docker service: sudo systemctl restart docker ​

How to install VirtualBox Guest Additions in ubuntu server 22.04 in terminal

Add you ~/.ssh/id_ed25519.pub key into ~/.ssh/authorized_keys , so you can use root@xx.xx.xx.xx sudo mount /dev/cdrom /media cd /media sudo apt install bzip2 sudo ./VBoxLinuxAdditions.run sudo reboot Then mount your host folder into guest os folder by using User Interface. Enjoy the life with virtualbox.  ​