You are here: GSI Wiki>Epics Web>DevelopersCorner (revision 24)EditAttach
Epics@GSI Webhome

Developers' Corner

Tips & Tricks and Examples

    Warning: Can't find topic Epics.TipsAndTricksAndExamples
    -- WikiGuest - 1970-01-01

Applications & Use Cases


Windows tricks & tips

    Resize Raw Img File Using VirtualBox

    Following the recommendation on http://raspberrypi.stackexchange.com/questions/4943/resize-image-file-before-writing-to-sd-card:
    • e.g. to resize to 15.5GB, approx. size 15500
    set VBOXMANAGE="C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
    IF NOT EXIST %VBOXMANAGE% (
       echo %VBOXMANAGE% does not exist ... exiting)
    )
    ELSE (
    	IF EXIST input.vdi   ( %VBOXMANAGE% closemedium disk input.vdi --delete)
    	IF EXIST output.vdi ( %VBOXMANAGE% closemedium disk output.vdi --delete) 
    	IF EXIST output.img (%VBOXMANAGE% closemedium disk output.img)
    	 
    	REM  use without .img
    	set /p INPUT_NAME="Enter input file name without .img: "; 
    	set OUTPUT_NAME=%INPUT_NAME%_resized 
    	set /p OUTPUT_SIZE="Enter Size (MB) (e.g. 15000): "  
    	 
    	ECHO "=========================================================================" 
    	%VBOXMANAGE% convertfromraw %INPUT_NAME%.img input.vdi -format VDI --variant Standard 
    	ECHO "=========================================================================" 
    	%VBOXMANAGE% createhd --filename output.vdi --size %OUTPUT_SIZE% --format VDI --variant Standard 
    	ECHO "=========================================================================" 
    	%VBOXMANAGE% clonehd input.vdi output.vdi --existing 
    	ECHO "=========================================================================" 
    	%VBOXMANAGE% clonehd output.vdi output.img --format RAW 
    	copy output.img %OUTPUT_NAME%.img 
    	%VBOXMANAGE% closemedium disk input.vdi --delete 
    	%VBOXMANAGE% closemedium disk output.vdi --delete 
    	%VBOXMANAGE% closemedium disk output.img 
    )
    

    -- WikiGuest - 1970-01-01

    Windows: How To Clone A SD Card

    Following the help of page https://startingelectronics.org/articles/raspberry-PI/ten-things-raspberry-PI chapter 10.

    This video View on YouTube → shows how to clone a SD card in Windows

    -- WikiGuest - 1970-01-01

    -- WikiGuest - 1970-01-01

Linux tricks & tips

    serial device settings - switch off every possible hidden manipulation feature

    TippsSerialDeviceSettingsToSwitchOffEveryHiddenManipulation (edit)

    $> stty -F /dev/ttySx -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke 19200

      • Output settings:
        -opost
        do not post-process output
        -onlcr
        do not translate newline to carriage return-newline
      • Local settings:
        -isig
        do not enable interrupt, quit, and suspend special characters
        -icanon
        do not enable erase, kill, werase, and rprnt special characters
        -iexten
        do not enable non-POSIX special characters
        -echo
        do not echo input characters
        -echoe
        do not echo erase characters as backspace-space-backspace
        -echok
        do not echo a newline after a kill character
        -echoctl
        do not echo control characters in hat notation ('^c')
        -echoke
        kill all line by obeying the echoctl and echok setting
        19200
        sets the speed to 19200 Bit/s

      Summarizing the settings prevent any additional manipulation of input or output.

    -- PeterZumbruch - 2017-11-30

    usbdev - dynamic device symlink and proper access rights

    udev/udevadm allows to automatically assign (fixed) symbolic links for USB devices connected to the system pointing the current /dev entry point.

    Prerequisites
    you have to have admin rights.

    How to
    • edit/create /etc/udev/rules.d/99-serial-permissions.rules
      • add the follwing line for general includes
        SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", SYMLINK+="$env{ID_SERIAL}", GROUP="users", MODE="0666"
        creates for every connected device of vendor id 0403 a symbolic link /dev/ to the connected device
      • for special devices those lines can be added in addition
        SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A100dQ2B", SYMLINK+="hadcon2", GROUP="users", MODE="0666"
        SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A600801P", SYMLINK+="olimex", GROUP="users", MODE="0666"

      • for special devices (e.g. HadCon2) those lines can be added in addition
        • SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A100*", RUN+="/usr/bin/stty -F /dev/$kernel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke 115200 "
        • SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A801*", RUN+="/usr/bin/stty -F /dev/$kernel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke 115200 "
    • to find out the IDs of connected systems
      udevadm info --export-db| grep FTDI| grep ID_SERIAL

    • Finally reload rules and trigger a reconnect:
      udevadm control --reload-rules
      udevadm trigger

    Links
    "Writing udev rules"
    http://reactivated.net/writing_udev_rules.html
    udev
    https://wiki.ubuntuusers.de/udev/
    "Tutorial on how to write basic udev rules in Linux"
    https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux

    -- PeterZumbruch - 2019-03-22

    SSH config: Host Specific Identity

    Using ssh config files in ~/.ssh/config allows to specify per host / host alias different user/identity to connect with and more necessary options.

    Using the features of the config file of ssh in ~/.ssh one can specify host specific ssh options, including varying identities and users.

    from: http://www.gelato.unsw.edu.au/archives/git/0611/31044.html

    Example:
    • connecting to a specific host using a different identity file and user
      $> cat ~/.ssh/config
         Host private.host.com
            User myname
            Hostname host.com
            IdentityFile ~/.ssh/private-identity
         Host public.host.com
            User anotherName
            Hostname host.com
            IdentityFile ~/.ssh/public-identity
         Host git.host.com
            User git
            Hostname host.com
            IdentityFile ~/.ssh/git-identity
           
    • allows to replace:
      • ssh host.com -l myname -i ~/.ssh/private-identity
        by
        ssh host.com
      • commands which internally use ssh but do not allow to pass ssh options, e.g. git
        git clone git.host.com

    -- PeterZumbruch - 2013-05-10

    Linux: dhclient - dynamic hostname

    Using dhclient exit hooks scripts allows to set e.g. the hostname dynamically

    Based on the articles: and its own origin

    dhclient and its scripting capabilities on enter and exit hooks allows to react on dynamic network environments.

    Provided you have root privileges this can be achieved by creating a script file hostname created in /etc/dhcp/dhclient-exit-hooks.d/ (on Debian), which is sourced by dhclient after having updated/received its DHCP informations.

    #!/bin/sh
       # Filename:     /etc/dhcp/dhclient-exit-hooks.d/hostname
       # Purpose:      Used by dhclient-script to set the hostname of the system
       #               to match the DNS information for the host as provided by
       #               DHCP.
       #
          
       # Do not update hostname for virtual machine IP assignments
       if [ "$interface" != "eth0" ] && [ "$interface" != "eth1" ] && [ "$interface" != "wlan0" ]
       then
               return
       fi
          
       if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
       then
          return
       fi
       
       echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address
       hostname=$(a=$(host $new_ip_address) || { false; } && { echo -n $a | cut -d ' ' -f 5 | cut -d "." -f 1; true; }) || unset hostname &&
       echo ${hostname?} > /etc/hostname &&
       hostname $hostname &&
       export HOSTNAME=$hostname &&
       echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname
    

    Applying those code lines:
    sudo curl -s https://wiki.gsi.de/foswiki/pub/Epics/TipsLinuxDhclientDynamicHostname/_etc_dhcp_dhclient-exit-hooks.d_hostname -o /etc/dhcp/dhclient-exit-hooks.d/hostname && 
      sudo dos2unix /etc/dhcp/dhclient-exit-hooks.d/hostname && 
      sudo chmod a+r /etc/dhcp/dhclient-exit-hooks.d/hostname
    

    Local testing at the prompt:
    dhclient

    -- PeterZumbruch - 2018-11-30

    Linux: dhclient - dynamic mount point

    Using dhclient exit hooks scripts allows to set a mount point depending on the network environment, in this example for the HADES setup

    Based on the articles: and its own origin

    dhclient and its scripting capabilities on enter and exit hooks allows to react on dynamic network environments.

    Provided you have root privileges this can be achieved by creating a script file mount_var_diskless created in /etc/dhcp/dhclient-exit-hooks.d/ (on Debian), which is sourced by dhclient after having updated/received its DHCP informations.

    #!/bin/sh
    # Filename:     /etc/dhcp/dhclient-exit-hooks.d/mount_var_diskless
    # Purpose:      Used by dhclient-script to set mount HADES's var/diskless filesystem 
    #               from either the local net (preferred) or the GSI network
    #
    
    # Do not update hostname for virtual machine IP assignments
    if [ "$interface" != "eth0" ] && [ "$interface" != "eth1" ] && [ "$interface" != "wlan0" ]
    then
    return
    fi
    
    if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
    then
    return
    fi
    
    var_diskless_hades=192.168.100.50
    var_diskless_gsi=140.181.75.158 
    var_diskless_path=/var/diskless/dreamplug
    var_diskless_mount=/var/diskless/dreamplug
    
    echo dhclient-exit-hooks.d/mount_var_diskless: new domain-name-servers: $new_domain_name_servers 
    
    echo "$new_domain_name_servers" | grep -q $var_diskless_hades && var_diskless_addr=$var_diskless_hades || var_diskless_addr=$var_diskless_gsi
    
    #clean up, but only different mounts
    grep -v "$var_diskless_addr:$var_diskless_path" /etc/mtab | grep -q "$var_diskless_mount" && umount $var_diskless_mount 
    
    #mount
    [ -d "$var_diskless_mount" ] || mkdir -p $var_diskless_mount
    grep "$var_diskless_addr:$var_diskless_path" /etc/mtab | grep -q "$var_diskless_mount" || mount $var_diskless_addr:$var_diskless_path $var_diskless_mount
    
    echo dhclient-exit-hooks.d/mount_var_diskless: mounted $var_diskless_addr:$var_diskless_path
    
    unset var_diskless_hades 
    unset var_diskless_gsi 
    unset var_diskless_path 
    unset var_diskless_mount
    

    Finally make sure the file is readable:
    chmod a+r /etc/dhcp/dhclient-exit-hooks.d/mount_var_diskless

    Local testing at the prompt:
    dhclient -v

    -- PeterZumbruch - 2013-10-21

    Linux: Hades Network - Allow Client To Connect Via Gateway

    To allow clients to connect outside of Hades network:
    • with root privileges
    ip r a default via 192.168.100.90 dev eth0

    -- WikiGuest - 1970-01-01

    Linux: How To Clone A SD Card

    Following the help of page https://startingelectronics.org/articles/raspberry-PI/ten-things-raspberry-PI chapter 10.

    This video View on YouTube → shows how to clone an SD card in Linux using the dd command line application.

    The command for copying an SD card to an image file on your computer is:
    sudo dd if=/dev/mmcblk0 of=~/raspi.img
    The command for copying an SD card image to a new SD card is:
    sudo dd if=~/raspi.img of=/dev/mmcblk0
    Where:
    • ~/raspi.img is the location and file name of the image file.
    • /dev/mmcblk0 is the SD card device on the Linux system.

    -- WikiGuest - 1970-01-01

    Linux: Resize Raw Img File

    see: http://www.vk3erw.com/index.php/16-software/33-raspberry-pi-how-to-resize-sd-card-image

    -- WikiGuest - 1970-01-01

    /sbin/reboot: Input/output error

    LinuxJournal-ReBootingTheMagicWay.png

    -- WikiGuest - 1970-01-01

    ProcServ: Remote Kill Via netcat

    ProcServ usually needs a login to its port to execute a "CTRL+X" sequence to kill/restart the current child process. Thanks to this cmdline it is also able without. Thanks to J.Michel / M.Traxler, afaik.

    Solution

    Assuming that procServ is running its telnet session on port 12345 on localhost
    echo -en "\x18" | netcat -w1 localhost 12345;
    

    -- WikiGuest - 1970-01-01

    -- WikiGuest - 1970-01-01

Hardware collection, evaluation


Git Tips & Tricks


-- PeterZumbruch - 11 Jun 2015
-- PeterZumbruch - 2015-11-18
Topic attachments
I Attachment Action Size Date Who Comment
cris-axis-setup.shsh cris-axis-setup.sh manage 0.8 K 2009-04-09 - 09:11 PeterZumbruch cris-axis-setup.sh: Bash script for cris-axis setup
Edit | Attach | Print version |  PDF | History: r25 < r24 < r23 < r22 | Backlinks | View wiki text | Edit WikiText | More topic actions...
Topic revision: r24 - 2015-11-18, PeterZumbruch
 
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GSI Wiki? Send feedback
Imprint (in German)
Privacy Policy (in German)