Thursday, June 1, 2023

Install grub boot loader + Fix Windows instalation

GRUB (GRand Unified Bootloader)

BIOS will read the first sector of a storage device for a boot partition table.
MBR( master boot record) - 4 partitions
To boot mbr you need UEFI set to boot mode:  Legacy BIOS.

For UEFI - you need a GPT partition table and a fat16/fat32 - mkfs.vfat partition anywhere on the disk  with an EFI folder - 100mb for windows 200mb linux (has all drivers here).
Kernel 10mb + initramfs 75mb ~ 100mb + 30mb windows bcd.
Dont store kernel and initrd here, store them in /boot on the partition you install the linux os.
GPT (Globally Unique Identifier Partition Table) - 128 partitions
EFI partition - FAT16, FAT32 or VFAT

UEFI will look into
<EFI_SYSTEM_PARTITION>\EFI\
Will read folders from here - and display them in UEFI boot menu
Everyfolder must have a xxx.efi boot file

FIX Windows BOOT

The System Reserved partition is optional and is created by the windows setup for the BitLocker only as it stores un-encrypted data in order to decrypt and boot main partition
It also has the BCD (Boot Configuration Data) folder.

To avoid it press SHIFT+F10 at windows setup it opens a cmd :
diskpart
select disk 0
create partition primary
and continue with graphical setup.

Install a boot manager - boot windows install media, press SHIFT+F10 to open a CMD promt

diskpart
select disk 0
list volume
select volume 2 (pick the fat32 one)
assing letter k:
exit

Create a BCD store. - required to boot windows.
bcdboot c:\Windows /l en-GB /s K: /f ALL
Bcdboot.exe c:\windows /s c:
 
/s k: = install to k:

Grub doesnt see ext4 unknown filesystem --- remove metadata_csum
sudo dump2fs /dev/sda1 | head -20

install package e2fsprogs
sudo tune2fs -O ^metadata_csum /dev/sda1  -- remove
sudo tune2fs -O metadata_csum /dev/sda1  -- add
sudo e2fsck -f /dev/sda1

Edit grub on windows

open diskpark - type ar run or cmd
list volume
select volume 1
assign letter=z

You will get access denied efi partition windows when you try to access the partition.
Right click on start menu - and select PowerSheel (admin)
Type z:  then use cd and ls to navigate
To edit grub.cfg type notepad grub.cfg at the proper path

remove letter=z in diskpart again to remove it from explorer

Install GRUB

mount /dev/xxx /mnt  --- efi partition
--boot-directory=/mnt -- it will install under /mnt/grub - grub files
--efi-directory=/mnt -- it will install under /mnt/EFI/os_name (Microsoft/Debian/Ubuntu etc)
grub-install --boot-directory=/mnt/linux/boot --efi-directory=/mnt/linux/boot/efi --target=x86_64-efi
grub-mkconfig > /mnt/grub/grub.cfg
grub-update is equivalent to grub-mkconfig
grub-mkconfig -o /boot/efi/EFI/grub/grub.cfg

ls 
grub> ls (hd1,gpt3)/
grub> set root=(hd0,1) grub> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1 grub> initrd /boot/initrd.img-3.13.0-29-generic grub> boot

optional (insmod part_gpt, insmod chain)
set root=(hd0,gpt1)
use tab after / or after each folder to explore contents - bootmgr is for bios, bootmgfw.efi for uefi.
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
boot

Grub: no suitable video mode found boot in blind mode
insmod all_video

Edit grub.cfg :

insmod all_video
insmod part_gpt
insmod ext2
insmod gzio
insmod gfxterm
insmod gettext

font=unicode

set gfxmode=auto
set lang=en_US
set timeout=5
set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue

# For booting Microsoft Windows
menuentry "Microsoft Windows 7" {
    set root=(hd0,2)
    chainloader +1
}

menuentry 'Debian' {
set root='hd0,gpt2'
echo 'Loading Linux ...'
linux /boot/vmlinuz-5.10.0-11-amd64 root=/dev/sda2 ro
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-5.10.0-11-amd64
}

menuentry 'UEFI Firmware Settings' $menuentry_id_option 'uefi-firmware' {
fwsetup
}

Manual boot from GRUB menu

chainloader /efi/Microsoft/Boot/bootmgfw.efi
boot

iso images:
loopback lo (hd0,4)/image.iso
linux (lo)/artix/vmlinuz boot=casper iso-scan/filename=${isofile}
initrd (lo)/artix.initrd.gz
boot

ls - shows disks
ls (hd0,1)/    +tab = browse partitions

If you get to grub boot menu grub 0.x
root (hd0,0) --- this will mount the partition
kernel /boot/vmlinuz... root=/dev/sda1
initrd /boot/initrd....
boot

Grub 2
ls
set root=(hd0,msdos1)
linux /boot/vmlinuz... root=/dev/sda1
initrd /boot/initrd...
boot

Grub custom font

# Generate a GRUB-compatible font with specified size
# from a TTF (type-type font)

sudo grub-mkfont --output=/boot/grub/fonts/DejaVuSansMono36.pf2 --size=36 /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf


Slow loading of linux from USB on old laptops

Grub calls the BIOS to read from the USB.
Some usb sticks are not compatible with bios drivers for high speed usb. Other sticks might work at faster speeds.
 
 Grub uses bios driver to load vmlinuz and initramfs from usb and it is using USB 1.0 - it has a speed of around 1.5Mbps = 0.2MB/s. 75mb/0.2 = 375 = 5-10 min.

For old laptops / pcs:

The Plop Boot Manager is a small program to boot different operating systems.
The boot manager has a built-in ide cdrom and usb driver to access that hardware without the help/need of a bios.

https://www.plop.at/en/bootmanager/intro.html

Connect to Wifi internet linux

echo 127.0.0.1    laptop > /etc/hosts
echo pcname > /etc/hostname


Connect to WIFI
sudo systemctl enable iwd

Enable dhcp client
/etc/iwd/main.conf
[General]
EnableNetworkConfiguration=true
[Rank]
BandModifier5Ghz=100.0

DNS
Either use resolv.conf for a static dns or enable systemd-resolved
/etc/resolv.conf
nameserver 1.1.1.1
#cloudflare
nameserver 4.4.4.4  
nameserver 8.8.8.8
# google public dns

/etc/runit/sv/iwd/run
#!/bin/sh
exec /lib/iwd/iwd 2>/dev/null
ln -s /etc/runit/sv/iwd /run/runit/iwd


Connect to AP
rfkill 
rfkill unblock all
* if it is powered off - press FN+Wifi or Fn+Airplane Mode twice

iwctl device list
iwctl station wlan0 scan
iwctl station wlan0 get-networks
iwctl station wlan0 connect NETWORK_NAME
iwctl station wlan0 disconnect
iwctl station wlan0 show
iwctl known-networks list
iwctl known-networks NETWORK_NAME forget

Install iwgtk. On debian it must be compiled.

ifconfig - temporary settings in kernel, not persistent at reboot
ifup/down - config /etc/network/interfaces

Don't install networkmanager 
If you do, sudo systemctl disable NetworkManager-wait-online
Systemd - waits for - multi-user environments - for the network to connect and then continues to load services and you get a long wait at boot.

===========================

ip a
dhclient -v eth0
route
ping
netstat -tapn
namp
iptables -L (INPUT - FORWARD - OUTPUT)

wpa_supplicant
wpa_password wifi_network password > wifi
ip a
rfkill -- check it is enabled
wpa_supplicant -B -i wlan0 -c ./wifi
sudo dhclient wlan0

wpa_supplicant -B -i wlan0 -c <(wpa_passphrase "Your_SSID" Your_passphrase) && dhclient wlan0

Link service to runit by 
# ln -s /etc/sv/wpa_supplicant /var/service
or systemctl enable wap_supplicant

Manual install debian or arch linux from scratch

Boot  Arch linux image from USB. Use rufus to burn it windows, balenaetcher or dd in linux.
dd if=~/Download/arch.iso of=/dev/sdb bs=1M status=progress oflag=direct

* Install base packages distro

Wifi - internet
iwctl station wlan0 connect SSDID_name

Partition
lsblk
cfdsik -> sda1 100-200MB efi , sda2 20GB
mkfs.ext4 /dev/sda2
mount /dev/sda2 /mnt/linux

Install:
- from arch: pacman -Sy debootstrap
- from debian: apt install debootstrap arch-install-scripts

Install debian: debootstrap --arch amd64 stable /mnt/linux

genfstab /mnt/linux >> /mnt/linux/etc/fstab
Chroot into the new install
arch-chroot /mnt/linux     --- this will auto mount /dev /proc etc from current system

[manual without arch-chroot]
sudo mount -t proc /proc /mnt/linux/proc
sudo mount -o bind /dev /mnt/linux/dev
sudo mount -o bind /sys /mnt/linux/sys
chroot
[/manual]

Set Time Zone:
ln -sf /usr/share/zoneinfo/Europe/Bucharest /etc/localtime
date

apt install sudo
passwd   --- create password for root or you cant login after reboot

adduser username
usermod -aG sudo user

Kernel
apt install linux-image-amd64
or 
copy /boot/vmlinuz 
copy /usr/lib/modules/uname -r/ /mnt/linux/.... same path

Install GRUB
mount /dev/sda1 /mnt/efi
grub-install --boot-directory=/mnt/efi --efi-directory=/mnt/efi --target=x86_64-efi
ln -s /boot/vmlinuz-xxxx vmlinuz
ln -s /boot/initrd-xxxx initrd
nano /mnt/efi/grub/grub.cfg
menuentry 'Linux' {
    set root ='hd0,gpt2'
    linux    /boot/vmlinuz root=/dev/sda2 ro
    initrd    /boot/initrd
}

WIFI

nano /etc/apt/sources.list - add non-free-firmware
apt update
apt install firmware-misc-nonfree    --- othter wifi boards - realtek asus
apt install firmware-iwlwifi    --- mostly intel wifi boards

apt install iwd (alternative is wpa_supplicant)
Enable dhcp client + dns
/etc/iwd/main.conf
[General]
EnableNetworkConfiguration=true
/etc/resolv.conf
nameserver 1.1.1.1

nano /etc/hostname
nano /etc/hosts    - 127.0.0.1 hostname


Reboot

sudo dpkg-reconfigure locales

* Video system

You can install here a desktop/login manager - gdm3, lightdm etc OR just use xinit without an GUI interface
apt install xfce4   --- it will install xorg as a requirement

Xwayland works with gdm3 and gnome only for now.
Xfce4 works with lightdm and xorg/x11.

Change active Display Manager:
sudo dpkg-reconfigure gdm3
sudo dpkg-reconfigure lightdm

To start video mode:
systemctl start lightdm 

sudo apt install wget
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google.....deb
sudo apt -f install  --- to fix dependencies error from above

Change console FONT size

Go to directory /usr/share/kbd/consolefonts - and ls to see all available fonts

then setfont iso01-12x22.psfu.gz 
or any other fonts you like from there

dpkg-reconfigure console-setup


https://www.linuxfromscratch.org/

ArchLinux - https://wiki.archlinux.org/title/Installation_guide

https://gist.github.com/myTerminal/4f1d26eaf32cdc5bcc9fb19f594c03d2

https://www.debian.org/releases/stretch/amd64/apds03.html.en

https://wiki.debian.org/Debootstrap

On xfce4 time will not update after sustend on the gui - but time sync works fine


Saturday, April 1, 2023

Storage partitions under linux - swap - ramdisk

Partitions

gparted, cfdisk, lsblk, df -h

mkfs.ext4 /dev/sda2 , mkfs.ntfs etc --- format the partition  

sudo fdisk -l     --- view disks
lsblk -f     --- view disks and filesystems
sudo blkid - partition UUID
df -h
df -ih --- innodes

sudo tune2fs -l /dev/sda8
sudo tune2fs -m 1 /dev/sda8
Reserved blocks for root - so when you run out of space you can still login. Set default to 5% of partition size..
*** merge online cu partitia mounted = ok
After you rezise partition size with cfdisk you need to also resize the filesystem:
sudo resize2fs /dev/sdb

Mounting

/mnt : Mount point for a temporarily mounted filesystem - should not have subfolders
/media : Mount point for removeable media

These 3 are required for chroot, 

are interfaces to kernel data structures and not real files on hdd - they stay in ram.

Can check with the command findmnt /sys
/dev - file devices
/proc - running process table + some system info same as sys left for backward compatibility 
/sys - hardware information

/run - virtual ram runtime for udev - needed before /var/run is mounted

/etc - system config files - before changes would be done in source code and recompile
means etcetera - as in the rest of the files of a system

/var - variable stuff like logs
/opt - optional software not installed with system package manager
/usr - libraries, binaries, manuals - all the software

/etc/fstab --- automount at start-up - should at least have /

mount -a --- mount all from fstab

UUID=14D82C19D82BF81E /mnt/d auto nosuid,nodev,nofail,x-gvfs-show 0 0

1. partition id
2. mount point
3. partition type 
4. options

nosuid - specifies that the filesystem cannot contain set userid files. This prevents root escalation and other security issues.
nodev - specifies that the filesystem cannot contain special devices (to prevent access to random device hardware).
nofail - removes the errorcheck.
x-gvfs-show - show the mount option in the file manager. If this is on a GUI-less server, this option won't be necessary.
0 - determines which filesystems need to be dumped (0 is the default).
0 - determine the order in which filesystem checks are done at boot time (0 is the default).

mount /dev/sda1 /mnt

NTFS partition from windows closed without proper shutdown ---> ntfsfix /dev/sda1
If that doesn't work you need to boot a windows os and it will fix it. ntfs is not opensource.

See mounted filesystems and space usage : 
du -sh -- file/folder size

INODES on linux

The file system has an inode table - every file and directory on a disk requires one inode entry.

To have more inode you need to re-format the filesystem and reserve more space for the inode table.

Other filesystems dont allocate a fixed inode table like XFS, JFS, BtrFS or ZFS.

On ext3 and ext4 - the most common used filesystems on linux you get by default 1 inode for every 16kb of space.
using the -i flag to mkfs.ext4 to specify the bytes:inode ratio. 

This problem is most common on servers where you can get a lot of small files.
Apache’s disk cache system (mod_cache_disk) - creates a lot of small files - htcacheclean should clean it.

Swap

Instead of storage swap partition you can have a swap partition in ram.
Of course this will not work for hibernation.

Swap file

dd if=/dev/zero of=/swapfile bs=1M count=3064 status=progress
chmod 600 /swapfile
mkswap -U clear /swapfile
swapon /swapfile
Add it to fstab
/swapfile none swap defaults 0 0 >> /etc/fstab

Ram swap

When ram gets full, data is moved and compressed into this z swap partition.

To enable it, open a cmd and create these files :

sudo su
echo zram > /etc/modules-load.d/zram.conf
echo 'options zram num_devices=1' > /etc/modprobe.d/zram.conf
echo 'KERNEL=="zram0", ATTR{disksize}="512M",TAG+="systemd"' > /etc/udev/rules.d/99-zram.rules

touch /etc/systemd/system/zram.service

[Unit]
Description=Swap with zram
After=multi-user.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStartPre=/sbin/mkswap /dev/zram0
ExecStart=/sbin/swapon /dev/zram0
ExecStop=/sbin/swapoff /dev/zram0

[Install]
WantedBy=multi-user.target

sudo systemctl enable zram
reboot 

swapiness - sudo nano /etc/sysctl.conf

The default value is 60."
0 - does not disable swap

To use a swap partition instead

# mkswap /dev/sda5
# sync
# swapon /dev/sda5

Ram-disk

For windows :
The only free software that allows for more then 4gb is ImDisk Toolkit

For linux  :
First check how much ram you got : free -h
Make a new directory and mount the ramdisk :

sudo mkdir /mnt/ramdisk
sudo mount -t tmpfs -o size=10g tmpfs /mnt/ramdisk
tmpfs - is mounted in ram
To make it available every time you boot edit /etc/fstab :

tmpfs       /mnt/ramdisk tmpfs   nodev,nosuid,noexec,nodiratime,size=1024M   0 0

Tuesday, March 28, 2023

Android on linux

 ADB - Android Debug Bridge - sudo apt install adb

To enable go to Settings - About phone - scroll to bottom - tap many times - Build number - until you get a message Developer mode enabled.
Now go to Settings - Developer mode - enable USB DEbugging

Connect android via usb to computer - you will get a message to allow connection.

sorin@hp250:~$ adb devices
List of devices attached
ZY326M79LR device

sorin@hp250:~$ adb tcpip 5555
restarting in TCP mode port: 5555

sorin@hp250:~$ adb connect 192.168.0.201:5555
connected to 192.168.0.201:5555

sorin@hp250:~$ adb devices
List of devices attached
192.168.0.201:5555 device

Then use scrcpy (sudo apt install scrcpy ) to connect to the phone from laptop.
Record screen with OBS Studio - and select scrcpy window.

DroidCam - use camera



Monday, January 30, 2023

Convert scanned document images to pdf

Rename the images with numbers 1, 2 ,3 etc 12.jpeg - the image view/print app from windows doesnt use the same order as you see it in explorer.

Select all scanned images, right click - Show more options - Print


Select Print to PDF, go to Options - Printer Properties -> and select Orientation - Portrait

Monday, December 12, 2022

Linux autologin + Sudo with yubikey

Authentification is done by PAM - Pluggable Authentication Modules
Passwords are stored in /etc/shadow

passwordless login with yubikey on linux

HMAC-SHA1 Challenge-Response is specific for Yubikey only.

yubiko-pam - is yubikey-specific and relay on it's specific features, 
pam-u2f - is generic and works with any keys supporting u2f and/or fido2.

auth required pam_u2f.so cue interactive

 Set authentification with yubikey off-line with Challenge-Response so you dont have to type a password just touch the keyyubikey

install yubico pam package
# install chalenge to slot 1
# generate challenge file for slot 1
ykpamcfg -1 -v
man ykpamcfg

/etc/pam.d/common-auth
#[success=1 new_authtok_reqd=ok ignore=ignore default=die]
auth required   pam_echo.so "Touch the key"
auth  sufficient      pam_yubico.so mode=challenge-response authfile=/home/user/.yubico/challenge-xxxx

Install xscreensaver if you want to lock the screen

Autologin with desktop/login manager

autologin with lightdm:
/etc/lightdm/lightdm.conf -- uncomment the lines
autologin-user = sorin
autologin-user-timeout = 0
*Note if you cannot login with the user but you can with root check if you ran out of space. (df -h)

Autologin with systemd directly

Agetty is called by /bin/INIT and this calls /bin/login 

/etc/systemd/system/getty.target.wants/getty@tty1.service
add -a my_username

ExecStart=-/sbin/agetty -a username - $TERM
remove the login options -o '-p -- \\u'

To start X11 with xfce
~/.bash_profile
if [ -z "${DISPLAY}" ] && [ $(tty) = /dev/tty1 ]; then
  startxfce4
fi

Tuesday, November 8, 2022

Mouse latency response time in linux

 lsusb

Find your mouse. 

Bus 001 Device 003: ID 1a7c:0191 Evoluent VerticalMouse 4

sudo usbhid-dump -s 1:3 -f -e stream

From the manual we get what the parameters mean:
man usbhid-dump
 -s =bus[:dev]
Replace -s 1:3 with the Bus Device for your device

Output is in the form
BUS:DEVICE:INTERFACE:ENTITY TIMESTAMP

.001:003:000:STREAM             1667902900.482858
 00 00 00 FC FF 00 00

.001:003:000:STREAM             1667902900.490787
 00 00 00 FE FF 00 00

.001:003:000:STREAM             1667902900.498863
 00 01 00 FC FF 00 00

Timestamp is in seconds before the point and subdivisions of seconds after the point.
First 3 digits milliseconds next 3 digits microseconds.
So the difference between two events is in my case is 8ms.
Note the speed dpi choise does not affect this. This is the maximum physical transmit speed.

usbhid-dump will disconect you mouse/device.
if you mess up just remove the receiver and plug-it back in or wait 60 seconds.

It is a WiFi Evoluent Vertical Mouse 4.

Configure Mouse Buttons X11
xinput
press a button and run in terminal to find the number associated with each button
xinput query-state id-nr
or
xev | grep button


xinput set-button-map "Kingsis Peripherals Evoluent VerticalMouse 4" 1 2 3 4 5 6 7 9 2 8

90-evoluent.conf /usr/share/X11/xorg.conf.d/conf
Section "InputClass" Identifier "Evoluent VerticalMouse 4" MatchUSBID "abcd:0123" # input id: 1 2 3 4 5 6 7 8 9 10 Option "ButtonMapping" "1 2 3 4 5 6 7 9 2 8" EndSection


Tuesday, November 1, 2022

Nofap - block porn

 Change the dns on your router in the DHCP section, with the dns from cisco OpenDNS  FamilyShield

https://www.opendns.com/setupguide/#familyshield

208.67.222.123
208.67.220.123

Use cloudflare warp - set it to familly mode full (malweare + adult)
Chrome - uses and external google dns to bypass it.
chrome://net-internals/?#dns  --- you can check here what dns record it returns
To disable external google dns go to:
Settings - Privacy and security - Security : chrome://settings/security - 
at the bottom of the page Use secure dns - With your current service provider - and it will use warp/cloudflare settings.

Youtube - click the profile picture in right top corner - and select Restrcited Mode - On - but the downside is it disables the comment section.

Android - Settings - Google  - Settings for Google apps (last one) - Search, Assitant & Voice (last one) - Hide Explicit results - On

Sunday, October 23, 2022

Hacker movies

 Takedown 2000 - computer hacker Kevin Mitnick

Antitrust 2001

The net 1995

Hackers 1995



Disable notification pop-ups in chrome

 Click on vertical 3dots icon for menu list and choose the Settings option.

  1. Switch to the Privacy and Security section and click on the Site Settings tab.
  2. Scroll down to the Permissions section and click on Notifications.
  3. Select 
  4. Don't allow sites to send notifications
    Features that need notifications won't work

Tuesday, September 20, 2022

Drone project

Battery LiPo

The voltage in LiPo (Lithium Polymer) batteries is determined based on the number of cells they have and we can easily identify this by referring to the "S" count. Each LiPo cell is rated at 3.7v so a 2S LiPo means it's a 2 cell battery and 7.4v, a 3S is 11.1v, 4S is 14.8v and 6S is 22.2v.

Motor

 2306 2555KV

Firmware - https://ardupilot.org/

Tuesday, September 6, 2022

Hosting server types

Hosting types

Shared hosting – many websites share the same os with same general settings
You get allocated a maximum usage - but the resources are not guaranteed - if one account uses all his allocated resources the others suffer
- easy to get started with, comes with some web admin panel like cpanel so no administration knowledge required

VPS hosting (Virtual Private Server) – independent os - can be customised as you like.
You can get it either managed by the hosting or unmanaged - where you have to take care of everything.
Resource can be shared just like a shared hosting for prices around 10$ or dedicated from 25-30$.
On shared you get a minimum of like 0.5 virtual cpu and a maximum of 2vcpu for example - but  they will list the package as 2cpu.
Whenever you dont use all your 2vcpu other account hosted on the same physical machine will use them - which can get you to a place where you can ony use 0.5 vcpu because the rest are busy for the moment.

Dedicated server – you are given a full physical machine just for yourself - might be usefull for special dedicated hardware needs. It is almost identical to a dedicated resources VPS.

Cloud Hosting same as the others but the virtual os is run on multiple physical machines instead on a single one. Has the advange that are highly scallable.

SQL cloud vs VPS SQL
SQL cloud - you dont have to install and update your DB but it is more expensive

You can have one FREE non-preemptible e2-micro VM instance in US
2 vCPU, 1 GB Ram, 30GB storage 2.000.000 inodes
https://console.cloud.google.com/compute/instancesAdd

CDNs - Content Delivery Networks
Cloudflare.com - offers FREE basic CDN
- free DNS server with instant propagation
- free SSL/TSL CA certificate
- CDN - cache servers - saves BANDWITH and offers faster response time

It is a distributed network of servers that are situated physically all over the world that cache your content from an origin location where your website is hosted.
The closer the server delivering the files is to the end user the faster the loading will be.
It is especially useful when you serve a lot if static resources like images.

Namecheap.com - register domains

 
Tools

Uptime – uptime monitor your hosting servers – Uptime Robot
Free VPN – to check how the site behaves from different locations – Tunnel bear
Load impact testing – test and know your hosting server limits – k6
Wayback Machine – useful for checking old domains or even for restoring your website in case of an emergency – https://archive.org/web/

Saturday, August 27, 2022

ffmpeg - fast audio video edit

 Cut video segment

 Download the ffmpeg.exe and run it from cmd. https://ffmpeg.org/

ffmpeg.exe -ss 00:12:58 -t 00:04:29 -i video.mp4 -acodec copy -vcodec copy segment.mp4

-ss -> set first time interval
-t -> how much to cut in hours minutes seconds
* note this is not the second time position in the original video but it is t2-t1 - where t1 is the time mentioned with -ss
-i -> the input video

For exemaple original video has 20 minutes and we want to cut a segment from time 00:12:58 to time 00:17:39. si 17:39-12:58 = 04:29 -> 4 minutes and 29 seconds.

 next two to copy both video and sound 
and last argument segment.mp4 the name of the output video.

Cut a song from a video and then convert to mp3. 

ffmpeg -i song2.mp4 -vn song2.mp3

-vn option explicitly drops video so the conversion is much much faster.

Repeat song / video

ffmpeg -stream_loop 3 -i input.mp4 -c copy output.mp4

Extract audio mp3

ffmpeg -i input.mp4 out.mp3

ffmpeg -i input.mp4 -vn -acodec copy out.aac/mp3 - check with mediainfo

ffmpeg -i out.aac out.mp3


Sample rate = 1 sec = 44.000 samples

44khz -> 2 chanells of 22 khz each 

human hearing 20hz - 20khz

CD 44khz. DVD 48khz HD 96khz

Subtitles

ffmpeg -i "in.mp4" -lavfi "subtitles=sub.srt:force_style='Alignment=2,OutlineColour=&H100000000,Outline=1,Shadow=0,Fontsize=18,MarginV=70'" "output.mp4"


Saturday, August 13, 2022

Heatbed MOSFET 3d printer

  HA210N06 -  210A 60V N-Channel MOSFET - datasheet

MB6S - Bridge Rectifier - it corrects reverse polarity to MOSFET gate - so you don't burn it. With this on the board you can connect the wire without worrying about polarity. - datasheet

EL 817 C915 - PHOTOCOUPLER - datasheet

The way it should be used it is like this:

MOSFET 25A

Voltage limits of the circuit

On the drive signal - the limiting factor is the optocoupler max forward current of 60ma. We have a 10k resistor so a maximum of 600v - that also coresponds to the bridge rectifier max voltage. So we have no maximum real limit but we have a problem with the minimum voltage.

The optocoupler support maximum 35v on the output side collector-emitter. The MOSFET takes 25v on the gate-source side, and it has a voltage divider of 50% so it takes a max of 50v DC IN but we have the 35v limit on the optocoupler. So 35v is maximum DC IN.

optocoupler input is connected through a 103 resistor - 10k - after it passes through the bridge rectifier first. If you are using a microcontroller with 3.3v logic voltage it will not open. You need to replace the 10k with 1k 102 resistor.