How to show progress while dd is copying

14 02 2013

In computing, dd is a common program for Unix and Unix-like operating systems whose primary purpose is to “convert and copy a file.” On Unix, device drivers for hardware (such as hard disks) and special device files (such as /dev/zero and /dev/random) appear in the file system just like normal files; dd can also read from (and in some cases write to) these files. As a result, dd can be used for tasks such as backing up the boot sector of a hard drive, and obtaining fixed amount of random data. The dd program can also perform conversions on the data as it is copied, including byte order swapping and conversion to and from the ASCII and EBCDIC text encodings. [http://en.wikipedia.org/wiki/Dd_%28Unix%29]

When you run DD command and you are copying few TB of data, you don’t know how much dd copied after some time.

To get status of DD we can do following steps:

– First run DD

dd if=/dev/zero of=/dev/null bs=1M count=100000

This DD is useless used only for demonstration (copy zeroes to null)

– Next we need to know pid of DD

 

root@gato:~# ps aux |grep dd
root 2 0.0 0.0 0 0 ? S lut05 0:00 [kthreadd]
root 1118 0.0 0.0 103624 1592 ? Ss lut05 0:00 /usr/sbin/winbindd -F
root 1173 0.0 0.0 0 0 ? S< lut05 0:00 [ib_addr]
root 1310 0.0 0.0 103624 912 ? S lut05 0:00 /usr/sbin/winbindd -F
gato 2045 0.0 0.0 25740 2020 ? Ss lut05 0:04 //bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
root 5581 100 0.0 13700 1724 pts/7 R+ 12:38 1:33 dd if=/dev/zero of=/dev/null bs=1M count=100000
root 5735 0.0 0.0 10644 932 pts/4 S+ 12:39 0:00 grep --color=auto dd
root 10141 0.0 0.0 23944 924 ? Ss lut11 0:00 //bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session

– After that we can send USR1 signal from different terminal
kill -USR1 5581

– Finally in terminal where we run DD we will see following information

dd if=/dev/zero of=/dev/null bs=1M count=100000
6135+0 przeczytanych recordów
6135+0 zapisanych recordów
skopiowane 6433013760 bajtów (6,4 GB), 120,943 s, 53,2 MB/s
^C27466+0 przeczytanych recordów
27466+0 zapisanych recordów
skopiowane 28800188416 bajtów (29 GB), 529,659 s, 54,4 MB/s

Cheers!





Sample script for internet connection failover between WAN and 3G on OpenWRT / Gargoyle

7 02 2013

First you need to check if your modem is properly recognized by OpenWRT.
Then you need to configure your 3G interface. Edit /etc/config/network:

# vi /etc/config/network

...
config 'interface' '3g'
option 'proto' '3g'
option 'auto' '0'
option 'ifname' '3g'
option 'device' '/dev/ttyUSB0'
option 'service' 'umts'
option 'apn' 'your_APN_name'
option 'username' ''
option 'password' ''
option 'defaultroute' '0'
option 'peerdns' '0'
option 'keepalive' '3'
option 'maxwait' '20'
option 'dns' '8.8.8.8'
...

You need to customize your firewall config file in order to apply your rules to both WAN and 3G interfaces. To do so edit /etc/config/firewall:

# vi /etc/config/firewall

...
config 'zone'
option 'name' 'wan'
option 'network' 'wan 3g'
option 'input' 'REJECT'
option 'output' 'ACCEPT'
option 'forward' 'REJECT'
option 'masq' '1'
option 'mtu_fix' '1'
...

Below you can find sample bash script that is responsible for moving internet connection between WAN and 3G interface in case of failure.

# cat /etc/net_failover.sh

#!/bin/bash
#
#set -x
#### configuration ####
DEVPATH=/sys/bus/usb/devices
VID=12d1
PID=1506
WAN_IF='eth0.2' # enter name of WAN interface
WAN_GW='192.168.211.1' # enter IP for default gateway on WAN interface
WAN_IP='192.168.211.33' # enter IP for WAN interface
WAN_NETMASK='255.255.255.0' # enter netmask for WAN interface
GSM_IF='3g-3g' # enter name of 3G interface
GSM_GW='10.64.64.64' # enter IP for default gateway on 3G interface
PING_HOST='8.8.8.8' # enter IP of host that you want to check,
                    # if you lose connection to this host failover occurs
#### EOF configuration ####

#### functions ####
function 3g_connect
{
        # this function connects modem to 3G network -
        # usually used when we lose internet connection on WAN interface and failover occurs
        # or when 3G connection is disconnected by operator (example: Aero2 operator in Poland)
        for dev in $DEVPATH/*; do
                cvid=$([ -f $dev/idVendor ] && cat $dev/idVendor)
                cpid=$([ -f $dev/idVendor ] && cat $dev/idProduct)
                #echo "$dev, $cvid:$cpid"
                [ "$VID" = "$cvid" ] && [ "$PID" = "$cpid" ] && devdir=$dev
        done
        echo 0 > $devdir/bConfigurationValue
        sleep 3
        echo 1 > $devdir/bConfigurationValue
        sleep 5
        logger -t wan_failover "Connecting to 3G network..."
        ifup 3g
        sleep 15
}

function 3g_disconnect
{
        # this function disconnects modem from 3G network -
        # usually used when we recover internet connection on WAN interface
        for dev in $DEVPATH/*; do
                cvid=$([ -f $dev/idVendor ] && cat $dev/idVendor)
                cpid=$([ -f $dev/idVendor ] && cat $dev/idProduct)
                #echo "$dev, $cvid:$cpid"
                [ "$VID" = "$cvid" ] && [ "$PID" = "$cpid" ] && devdir=$dev
        done
        echo 0 > $devdir/bConfigurationValue
        sleep 5
        echo 1 > $devdir/bConfigurationValue
        sleep 5
        logger -t wan_failover "Disconnecting from 3G network..."
        ifdown 3g
        sleep 5
}

function 3g_gateway
{
        # this function add default gateway for 3G interface -
        # usually executed when moving internet connection from WAN to 3G interface
        logger -t wan_failover "Moving internet connection to $GSM_IF (3G) via gateway $GSM_GW..."
        route add default gw $GSM_GW
}

function wan_gateway
{
        # this function remove default gateway for 3G interface -
        # usually executed when moving internet connection from 3G to WAN interface
        logger -t wan_failover "Moving internet connection to $WAN_IF (WAN) via gateway $WAN_GW..."
        route del default gw $GSM_GW
}

#### EOF functions ####

modem_chk=`lsusb |grep ${VID}:${PID}`
wan_chk=`ifconfig |grep "$WAN_IF"`

if [[ ! "$modem_chk" && "$wan_chk" ]]; then
        # case info: 3G modem not found, WAN interface is up and running - exiting
        # you can put some actions here, if needed
        exit 1
elif [ ! "$wan_chk" ]; then
        # case info: WAN interface down or not configured - trying to up interface and exit
        # you can put some actions here, if needed
        ifup wan
        exit 2
fi

wan_ping=`ping -q -4 -c 3 -I $WAN_IF $PING_HOST | grep received |awk '{print $4}'`
gsm_chk=`ifconfig |grep "$GSM_IF"`

if [[ "$wan_ping" -gt 0 && ! "$gsm_chk" ]]; then
        # if there is ping reply from PING_HOST IP on WAN interface and 3G interface is down then exit
        # you can put some actions here, if needed
        exit 0
elif [ ! "$gsm_chk" ]; then
        # else if 3G interface is down (and there is no connection PING_HOST IP on WAN interface)
        # then establish 3G connection
        # you can put some actions here, if needed
        3g_connect
fi

gsm_ping=`ping -q -4 -c 3 -I $GSM_IF $PING_HOST | grep received |awk '{print $4}'`

if [[ "$wan_ping" -eq 0 && "$gsm_ping" -eq 0 ]]; then
        # if there is no connection to PING_HOST from WAN nor 3G interface then exit
        # you can put some actions here, if needed
        exit 5 # brak pingu do hosta przez obydwa interfejsy
fi

default_gw=`ip route|grep default|head -n1|awk '{print $3}'`

if [ -z $default_gw ]; then
        # if default gateway not set then add gateway IP from WAN interface,
        # NOTE: ifconfig is used here to make sure that WAN interface is up and running.
        # you can put some actions here, if needed
        ifconfig $WAN_IF $WAN_IP netmask $WAN_NETMASK
        route add default gw $WAN_GW
fi

if [[ "$wan_ping" -eq 0 && "$gsm_ping" -gt 0 && "$default_gw" = "$WAN_GW" ]]; then
        # case info: move internet connection from WAN to 3G interface.
        # if connection to PING_HOST is: broken on WAN, available on 3G.
        # and default gateway IP is set to WAN interface then add gateway from 3G interface
        # you can put some actions here, if needed
        3g_gateway
elif [[ "$wan_ping" -gt 0 && "$default_gw" = "$GSM_GW" ]]; then
        # case info: move internet connection from 3G to WAN interface only if default gw set to 3G.
        # if connection to PING_HOST is: available on WAN and default gateway IP is set to 3G interface
        # then remove gateway from 3G interface and disconnect 3G modem
        # you can put some actions here, if needed
        wan_gateway
        3g_disconnect
elif [[ "$wan_ping" -gt 0 && "$gsm_ping" -gt 0 ]]; then
        # case info: move internet connection from 3G to WAN interface if PING_HOST is available on both.
        # if connection to PING_HOST is: available on WAN and 3G interface
        # then disconnect 3G modem
        # you can put some actions here, if needed
        3g_disconnect
fi




How to build Debian kernel using multiple cores

7 02 2013

The base problem is a question – how to use make-kpkg with multiple cores support while building Debian kernel?
When you are build kernel manually it is not a problem because you can use -j parameter to make command.

eg.

make -j 5

but how to use it with make-kpkg?

First we need to have kernel-package installed

apt-get install kernel-package

next we need to add line CONCURRENCY_LEVEL to /etc/kernel-pkg.conf

echo "CONCURRENCY_LEVEL= num_of_cores+1" >> /etc/kernel-pkg.conf
eg.
echo "CONCURRENCY_LEVEL= 5" >> /etc/kernel-pkg.conf

then we can build kernel using make-kpkg with 5 threads

make-kpkg --initrd kernel_image kernel_headers

Voila!





How to clear SAMBA passwords in Windows

7 02 2013

Sometimes happens that Windows cache passwords for SAMBA shares.

One of method is to reboot or logout from Windows, but it is annoying and not comfortable.

To avoid reboot of Windows you can try these steps.

First method:

Open command line console (menu start -> run -> cmd (ctrl + shift +enter will open with Administrator privilages))

net use \\address_ip\share /del
eg.
net use \\192.168.1.1\photos /del

or try second method:

Open menu start and type:

rundll32.exe keymgr.dll, KRShowKeyMgr





Welcome

7 02 2013

Welcome to IT Busters blog!

“The question of whether computers can think is like the question of whether submarines can swim.”
(Edsger W. Dijkstra)