Thursday, 23 January 2020

mount drive in VirtualBox linux

prerequisites

Assume local Shared Folder: sfolder; VM mount: /home/<user>/vfolder

Insert Guest Additions CD Image
sudo apt-get install virtualbox-guest-dkms
sudo apt-get install virtualbox-guest-utils

cd /opt/VBoxGuestAdditions-*/init  
sudo ./vboxadd setup

touch ~/
vfolder

chmod 777 ~/vfolder

sudo vim /etc/modules 
=>
vboxsf


mount the local Shared Folder

sudo vim /etc/fstab 
=>
sfolder /home/<user>/vfolder vboxsf defaults 0 0

mount the network Windows Shared Folder

cifs
//[localip]/[folder] /mnt/[localfolder] cifs credentials=/XXXX/.credentials,vers=3.0,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=[USERNAME],gid=[USERNAME],nofail,sec=ntlmssp       0       0

Tuesday, 21 January 2020

[linux] changes

Duplicating your current config

cp /boot/config-`uname -r`* .config

Making the default config

make defconfig

Change a module

vim drivers/net/ethernet/intel/e1000e/netdev.c
=>
......
struct e1000_hw *hw;

printk(KERN_ALERT "DEBUG: Passed %s %d \n",__FUNCTION__,__LINE__);

Compile a kernel

make M=drivers/usb/serial -j8 # Build only a portion of the kernel with 4 core CPU
lscpu # check how many core the pc has
make -j8 # Build entire kernell with 4 core CPU

make localmodconfig

Build kernel

make -JX

Run on QEMU

qemu-system-x86_64 -no-kvm -kernel arch/x86/boot/bzImage -hda /dev/zero -append "root=/dev/zero console=ttyS0" -serial stdio -display none

Install a kernel

sudo make install

Build a module 

make modules SUBDIRS=drivers/the_module_directory

Install a module

sudo make modules_install SUBDIRS=drivers/the_module_directory

OR (if the driver installed as a module, just recompile it)

make drivers/usb/host/xhci-hcd.ko

Reload the module

sudo rmmod xhci-hcd && sudo insmod drivers/usb/host/xhci-hcd.ko

Remove kernel from boot

sudo rm -rf /lib/modules/3.3.7*
sudo rm -rf /usr/lib/modules/$(uname -r)
/boot
/lib/modules

update-grub

Remove kernel from grab


Now I understand the difference between an updated kernel and install and compile a kernel. I compiled all this kernel and the solution to delete was:
I went to nautilus as root sudo nautilus and just deleted:
/boot/vmlinuz "kernel I want to delete"
/boot/initrd "kernel I want to delete"
/boot/System "kernel I want to delete"
/boot/config "kernel I want to delete"
/lib/modules "kernel I want to delete"
and updated the grub sudo update-grub2
OR

locate *5.5.0-rc6*
sudo rm /lib/modules/5.5.0-rc6+
sudo rm -rf /lib/modules/5.5.0-rc6+

Loadable Kernel Modules


list modules

lsmod
......
e1000e                249856  0
......

module info

modinfo e1000e
......
name:           e1000e
vermagic:       5.3.0-26-generic SMP mod_unload 
signat:         PKCS#7
signer:         
sig_key:        
sig_hashalgo:   md4
parm:           debug:Debug level (0=none,...,16=all) (int)
parm:           copybreak:Maximum size of packet that is copied to a new buffer on receive (uint)
parm:           TxIntDelay:Transmit Interrupt Delay (array of int)
parm:           TxAbsIntDelay:Transmit Absolute Interrupt Delay (array of int)
parm:           RxIntDelay:Receive Interrupt Delay (array of int)
parm:           RxAbsIntDelay:Receive Absolute Interrupt Delay (array of int)
parm:           InterruptThrottleRate:Interrupt Throttling Rate (array of int)
parm:           IntMode:Interrupt Mode (array of int)
parm:           SmartPowerDownEnable:Enable PHY smart power down (array of int)
parm:           KumeranLockLoss:Enable Kumeran lock loss workaround (array of int)
parm:           WriteProtectNVM:Write-protect NVM [WARNING: disabling this can lead to corrupted NVM] (array of int)
parm:           CrcStripping:Enable CRC Stripping, disable if your BMC needs the CRC (array of int)

search the module

git grep e1000e -- '*Makefile'

load module at boot

normally

sudo vim /etc/modules
=>
......
e1000e

with params

sudo vim /etc/modprobe.d/e1000e.conf
=>
option e1000e debug=11

mutt esmpt

Yahoo:

https://help.yahoo.com/kb/generate-password-sln15241.html

Under "Account Security", In "Manage app passwords"
Generate 2 passwords, one for smtp <SMTP_PASS> and one for imap <IMAP_PASS>

esmtp:
vim ~/.esmtprc

identity "name@yahoo.com"
hostname smtp.mail.yahoo.com:587
username "name@yahoo.com"
password "<SMTP_PASS>"
starttls required

mutt:
vim ~/.muttrc

set sendmail="/usr/bin/esmtp"
set envelope_from=yes
set from="NAME <name@yahoo.com>"
set use_from=yes
set edit_headers=yes

set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates

set folder = "imaps://export.imap.mail.yahoo.com:993"
set spoolfile="imaps://imap.mail.yahoo.com/INBOX"
set postponed="imaps://imap.mail.yahoo.com/Drafts"
set record="imaps://imap.mail.yahoo.com/Sent"

set imap_user = 'name@yahoo.com'
set imap_pass = "<IMAP_PASS>"

set timeout = 10

Google:

mutt:
vim ~/.muttrc

set realname = "XXXXXXXX"
set from = "XXXXXXXX@gmail.com"
set use_from = yes
set envelope_from = yes
set edit_headers=yes

set smtp_url = "smtps://XXXXXXXX@gmail.com@smtp.gmail.com:465/"
set smtp_pass = "XXXXXXXX"
set imap_user = "XXXXXXXX@gmail.com"
set imap_pass = "XXXXXXXX"
set imap_keepalive = 900
set timeout = 10
set ssl_force_tls = yes
set ssl_starttls = yes

# G to get mail
bind index G imap-fetch-mail
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "imaps://imap.gmail.com/INBOX"
set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates
set record = ""
set postponed = "imaps://imap.gmail.com/[Gmail]/Draft"
set editor = "vim"
set charset = "utf-8"

Saturday, 18 January 2020

[git] changes

https://www.youtube.com/watch?v=_uWjGagIQcs

select branch

git checkout test
git branch

delete branch (locally)

git branch -d localBranchName

build

make M=drivers/staging/comedi/

auto-check

./scripts/checkpatch.pl --file --terse drivers/staging/comedi/drivers/ssv_dnp.c

verify

git status
git diff

revert changes (before patch)

git checkout test /xx/xx/xx

commit changes

add file to commit

git add <file>
git diff --cached

revert file from commit

git reset <file>

finally

#git commit -a
git commit -s -v

view the log

git log
git show
git show --pretty=full


who're the maintainers

perl scripts/get_maintainer.pl --separator , --nokeywords --nogit --nogit-fallback --norolestats -f drivers/staging/most/aim-sound/sound.c

format the changes (save to /tmp/)

git format-patch master..test
0001-XXX-XXX-XXX-XX.patch
./scripts/get_maintainer.pl 0001-XXX-XXX-XXX-XX.patch

git format-patch -o /tmp/ HEAD^

check the format of patch mail

./scripts/get_maintainer.pl 0001-XXX...patch

send mail

git send-email --to XX@XX.XX --cc XX@XX.XX -cc ... 0001-XXX...patch

git send-email --annotate HEAD^

revert changes (after patch)

git log --oneline
14u7289ykdja (HEAD -> test) Staging: XXX: XXX: XXXXX issue
git revert 14u7289ykdja


Who wrote that line?

git blame xxxx/xxxx.c



[linux] codingstyles

Resources

https://www.youtube.com/watch?v=LLBrBBImJt4
https://gist.github.com/17twenty/8154928

codingstyles

  • Use tabs (8 characters)
  • 80 character line limit
  • if-statement
if (error != -ENODEV) {
        foo();
        bar();} 
else {        report_error();        goto exit;}
if (error != -ENODEV)        foo();else        goto exit;
  • functions
int function(int *baz){        do_something(baz);        return 0;}

vim

  • modify default
vim ~/.vimrc
filetype plugin indent onsyntax on
set number
set title
set tabstop=8set softtabstop=8set shiftwidth=8set noexpandtab
  • or via commands
:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab
  • set /usr/bin/vim/basic as default editor 
sudo update-alternatives --config editor

scripts/checkpath.pl

./scripts/checkpatch.pl --file --terse drivers/staging/comedi/drivers/ssv_dnp.c


[xv6] adventure

Build & Startup

Every change has to be (re)built by
  • make
Run the xv6 OS (without pop-up) by

  • make qemu-nox

Or in debug mode by (cover elsewhere)

  • make qemu-nox-gdb

Add Command

says, there is sample.c to be a command in xv6

  • system call required?
    • vi defs.h     (add forward declaration)

    • // proc.c
      ......
      int             csc ( void ); 
    • vi proc.c     (add function to this)
//custom process named "csc()"intcsc(){......}
    • vi syscall.h  (define sys call vector)
// System call numbers #define SYS_fork    1 ......#define SYS_close  21 #define SYS_csc    22
    • vi syscall.c  (connect shell and kernel by extern)

extern int sys_chdir(void);
......
extern int sys_csc(void);
......
static int (*syscalls[])(void) = {
......
[SYS_csc]     sys_csc,
};    
    • vi user.h     (callable function via shell)

// system calls
......
int csc ( void );
    • vi sysproc.c  (implement the method)

......
int
sys_csc ( void )
{
  return csc ();
    • vi usys.S     (marco to connect user call to sys call)
......SYSCALL(csc)
    • vi sysfunc.h  (add sys call handler)
  • put sample.c into xv6 folder
#include "types.h"......intmain(int argc, char *argv[]){  csc();  exit();}
  • vi Makefile

UPROGS=\
        _cat\
        ......
        _sample\
        ......
......
EXTRA=\
        ......
        ln.c ...... sample.c ......\
        ......
  • make              (Build the whole OS)

  1. aas

Add Executable

says, step by step
  • prepare C++ codes and header files
    • vi example.cpp     (function)
using namespace std;
double example(double a, double b){
  return a + b;
}
    • vi plus.h
#ifndef A_Hdouble example(double a, double b);#endif
    • vi main.cpp    (main program)
#include <iostream>#include <stdlib.h>#include "plus.h"using namespace std;int main(int argc, char *argv[0]){  double x, y;  x = atof(argv[1]);  y = atof(argv[2]);  cout << plus(x, y) << endl;  return 0;}
  • compile the codes to objects (plus.o & main.o)
    • g++ -c example.cpp
    • g++ -c main.cpp
  • link objects to executable (plus)
    • g++ -o plus example.o main.o
  • execute it
    • ./plus
Or, in one go

  • create a Makefile
    • vi Makefile
# default targetplus: example.o main.o        # target: prerequistites/dependencies        g++ -o plus example.o main.oexample.o main.o:             # prerequistites/dependencies:        g++ -c example.cpp        g++ -c main.cppclean:                        # other target        rm example.o main.o plus
Or with marco constantPROG   = plusSRCS   = example.cpp main.cppOBJS   = $(SRCS:.cpp=.o)      # replace .o to .cpp in SRCS# default target$(PROG): $(OBJS)              # target: prerequistites/dependencies        g++ -o $@ $(OBJS)$(OBJS):                      # prerequistites/dependencies:        g++ -c $*.cppclean:                        # other target        rm $(OBJS) $(PROG)
  • simply use either
    • make
    • make plus
  • to remove generated files
    • make clean












g++ -o aShell aShell.cpp

vm - Centos - Boot into latest Kernel

sudo grub2-set-default 0 sudo grub2-mkconfig -o /boot/grub2/grub.cfg sudo reboot