Welcome to zewaren.net. This site presents myself and mostly archives the solutions to some problems I once had.

How to use FreeBSD as a ISCI Target and Initiator (with CHAP)

Not so frequently asked questions and stuff: 

How to use FreeBSD as a ISCSI Target and Initiator

FreeBSD 8 as a Target

System used:

uname -a
FreeBSD lan-test-pbx.example.fr 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:48:17 UTC 2009     root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

The server's IP address is 192.168.3.156 and the network is 192.168.3.0/24.

Install the iscsi target port:

cd /usr/ports/net/istgt/
make install clean

Copy and edit the sample configuration files

cd /usr/local/etc/istgt
cp auth.conf.sample auth.conf
cp istgt.conf.sample istgt.conf
cp istgtcontrol.conf.sample istgtcontrol.conf

istgt.conf:

[Global]
  Comment "Global section"
  NodeBase "iqn.2011-06.net.example.tests"
  DiscoveryAuthMethod CHAP
  DiscoveryAuthGroup AuthGroup9999

  #The following values were not editied
  PidFile /var/run/istgt.pid
  AuthFile /usr/local/etc/istgt/auth.conf
  MediaDirectory /var/istgt
  LogFacility "local7"

  Timeout 30
  NopInInterval 20

  MaxSessions 16
  MaxConnections 4
  MaxR2T 32
  MaxOutstandingR2T 16
  DefaultTime2Wait 2
  DefaultTime2Retain 60
  FirstBurstLength 262144
  MaxBurstLength 1048576
  MaxRecvDataSegmentLength 262144
  InitialR2T Yes
  ImmediateData Yes
  DataPDUInOrder Yes
  DataSequenceInOrder Yes
  ErrorRecoveryLevel 0

#Unit controller
[UnitControl]
  Comment "Internal Logical Unit Controller"
  AuthMethod CHAP Mutual
  AuthGroup AuthGroup10000
  Portal UC1 127.0.0.1:3261
  Netmask 127.0.0.1

#Portal of the Test Disk
[PortalGroup1]
  Comment "SINGLE PORT TEST"
  Portal DA1 192.168.3.156:3260

#Initiators for the Test Disk
[InitiatorGroup1]
  Comment "Initiator Group1"
  InitiatorName "iqn.2011-06.net.example.tests:virtual175"
  Netmask 192.168.3.0/24

#Test Disk
[LogicalUnit1]
  Comment "Test Disk"
  TargetName testdisk
  TargetAlias "ISCSI Test Disk"

  Mapping PortalGroup1 InitiatorGroup1
  AuthMethod CHAP
  AuthGroup AuthGroup1
  UseDigest Auto
  UnitType Disk
  LUN0 Storage /usr/local/iscsi/testdisk 100MB


auth.conf:

[AuthGroup1]
  Comment "Group for the Test Disk"
  Auth "iqn.2011-06.net.example.tests:virtual175"  "between12and16"

[AuthGroup9999]
  Comment "Group for discovery"
  Auth "iqn.2011-06.net.example.tests:discoverer"  "discovermenow"

[AuthGroup10000]
  Comment "Group for unit controller"
  Auth "ctluser" "test" "mutualuser" "mutualsecret"

istgtcontrol.conf:

[Global]
  Comment "Sample Configuration"
  Timeout 60

  AuthMethod CHAP Mutual
  Auth "ctluser" "test" "mutualuser" "mutualsecret"

  Host localhost
  Port 3261

  TargetName "iqn.2011-06.net.example.tests:testdisk"
  Lun 0

  Flags "ro"
  Size "auto"

Create the disk:

dd if=/dev/zero of=/usr/local/iscsi/testdisk bs=`expr 1024 \* 1024` count=100

Restart the server:

$/usr/local/etc/rc.d/istgt restart
Starting istgt.
istgt version 0.4 (20110223)
traditional mode
LU1 HDD UNIT
LU1: LUN0 file=/usr/local/iscsi/testdisk, size=104857600
LU1: LUN0 204800 blocks, 512 bytes/block
LU1: LUN0 100MB storage for iqn.2011-06.net.example.tests:testdisk
LU1: LUN0 command queuing disabled

Test the connection:

$istgtcontrol list
lun0 storage "/usr/local/iscsi/testdisk" 104857600
DONE LIST command

Windows XP as an initiator

Download and install the Microsoft iSCSI Software Initiator Version 2.08.

Start the initiator in your start menu. Configure it to have the right node name:
Image

Add a new portal to activate the discovery:
Image

Log in to the target:
Image

The disk is now present and can be formatted (here in FAT32).
Image

Once mounted, files and folders can be created:
Image

Once you're done, log off the target to disconnect it:
Image

FreeBSD 8 as an initiator

System used:

uname -a
FreeBSD fbsd.localdomain 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Fri Jun 10 10:17:58 CEST 2011     root@fbsd.localdomain:/usr/obj/usr/src/sys/ISCSIKERNEL  i386

Discovery

Without CHAP:

$iscontrol -d -t 192.168.3.156 firstBurstLength=65535 maxBurstLength=262144 InitiatorName=iqn.2011-06.net.example.tests:virtual175
0x0201: Authentication failure

With CHAP:

$iscontrol -d -t 192.168.3.156 firstBurstLength=65535 maxBurstLength=262144 InitiatorName=iqn.2011-06.net.example.tests:virtual175 authMethod=CHAP chapIName=iqn.2011-06.net.example.tests:discoverer chapSecret=discovermenow TargetName=iqn.2011-06.net.example.tests:testdisk TargetAddress=192.168.3.156:3260,1

Connection

Configure the connection in /etc/isci.conf:

port = 3260

testdisk {
  targetaddress = 192.168.3.156:3260,1
  targetname = iqn.2011-06.net.example.tests:testdisk
  initiatorname = iqn.2011-06.net.example.tests:virtual175
  authmethod = CHAP
  chapIName = iqn.2011-06.net.example.tests:virtual175
  chapsecret = between12and16
  firstBurstLength = 65535
  maxBurstLength = 262144
}

Connect:

$iscontrol -c /etc/iscsi.conf -n testdisk
iscontrol[4562]: running
iscontrol[4562]: (pass0:iscsi0:0:0:0):  tagged openings now 0

Check:

$ls -l /dev/iscsi*
crw-------  1 root  wheel    0,  29 Jun 21 10:02 /dev/iscsi
crw-------  1 root  wheel    0,  29 Jun 21 10:02 /dev/iscsi
crw-------  1 root  wheel    0,  95 Jun 22 14:04 /dev/iscsi0

$ls -l /dev/da*
crw-r-----  1 root  operator    0,  98 Jun 22 14:04 /dev/da0
crw-r-----  1 root  operator    0,  99 Jun 22 14:04 /dev/da0s1

The disk contains a single partition formatted as FAT32 by Windows.

$mount -t msdosfs /dev/da0s1 /mnt/iscsi
$ls -l /mnt/iscsi/
total 5
drwxr-xr-x  1 root  wheel  1024 Jun  8 16:26 System Volume Information
-rwxr-xr-x  1 root  wheel     3 Jun  8 16:26 fichier1.txt
-rwxr-xr-x  1 root  wheel     6 Jun  8 16:26 fichier2.txt
drwxr-xr-x  1 root  wheel  1024 Jun  8 16:26 poulet
-rwxr-xr-x  1 root  wheel     8 Jun 22 11:23 truite.txt

The files and folders are present.

When you're done:

$umount /mnt/iscsi/

$ps aux | grep iscontrol
root   4562  0.0  0.5  3460  1312  ??  Is    2:04PM   0:00.01 iscontrol -c /etc/iscsi.conf -n testdisk
$kill -s HUP 4562
iscontrol[4562]: trapped signal 1
trapped signal 1
iscontrol: supervise going down
iscontrol[4562]: sess flags=20000407
iscontrol[4562]: terminated

Sources:

How to configure the SPA500S Attendant Console with Asterisk/FreePBX

Not so frequently asked questions and stuff: 

What we have:

  • A Cisco SPA525G IP Phone with a SPA500S Attendant Console
  • A FreePBX Server
  • Some other SIP phones

We want to configure FreePBX and the attendant Console.

FreePBX

Make sure that picking up calls work.

See http://www.freepbx.org/support/documentation/howtos/how-to-use-callgroups-and-pickgroups to set up pickgroups.

Apart from that, FreePBX should configure the hints correctly without any additional configuration.

The phone


Make sure that the phones are allowed to dial feature codes like **1234. On the SPA525G, you must modify the dialplan in the phone's configuration (set it to something like (*xx.|**xx.|xx.)).

The Attendant Console


Attendant Console Call Pickup Code: **# (feature code for Directed Call Pickup + #, # will be replaced by the extension number). If you set it to *8 (feature code for Asterisk General Call Pickup), the console will pick _any_ ringing phone, so if two of them are ringing at the same time, you don't know which one will get chosen.

Unit keys: fnc=sd+cp+blf;sub=extension@server;nme=extension
Exemple: fnc=sd+cp+blf;sub=1742@192.168.3.156;nme=1742

Sources

Serve clonezilla using PXE on a freebsd host with nfs.

PXE: 
Not so frequently asked questions and stuff: 

System used

The server system used was a soekris net4801 running freebsd.

uname -a
FreeBSD net4801 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Fri Feb 18 02:24:46 UTC 2011     root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

Ports

You will need the following ports:

  • ftp/tftp-hpa (I tried using the builtin tftp server but it sometimes failed for no reason).
  • net/isc-dhcp41-server (or any other dhcp server you fancy)

DHCP server

Configure your dhcp server to serve pxelinux.0

#/usr/local/etc/dhcpd.conf
subnet 192.168.242.0 netmask 255.255.255.0 {
  range 192.168.242.4 192.168.242.250;
  next-server 192.168.242.3;
  filename "pxelinux.0";
}

TFTP server

Configure your tftp server to listen and serve the right folder.

#/etc/inetd.conf

#if you are using tftp:
tftp   dgram   udp     wait    root    /usr/libexec/tftpd      tftpd -l -s /usr/local/tftpboot

#if you are using tftp-hpa:
tftp    dgram   udp     wait    root    /usr/local/libexec/in.tftpd     in.tftpd -p -s /usr/local/tftpboot

Check that the server is running:

netstat -a | grep tftp
udp4       0      0 *.tftp                 *.*

TFTP files

  • Copy the kernel (vmlinux) and the initrd (initrd.img) from the cd/usb/zip to the folder /images/clonezilla.
  • Download or find elsewhere a working copy of pxelinux.0 and copy it to /
  • Add an entry to the file pxelinux.cfg/default
ls /usr/local/tftpboot/
images          pxelinux.0      pxelinux.cfg

ls /usr/local/tftpboot/pxelinux.cfg/
default

ls /usr/local/tftpboot/images/clonezilla/
initrd.img              vmlinuz

cat pxelinux.cfg/default
MENU LABEL Clonezilla live
DEFAULT clonezillanfs

label clonezillanfs
kernel images/clonezilla/vmlinuz
append initrd=images/clonezilla/initrd.img boot=live live-config noswap union=aufs netboot=nfs nfsroot=192.168.242.3:/usr/local/clonezilla_nfs ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_keymap="" ocs_live_batch="no" ocs_lang="" vga=788

NFS Server

Configure your nfs server to serve the folder /usr/local/clonezilla_nfs.

cat /etc/exports
/usr/local/clonezilla_nfs    -network 192.168.242 -mask 255.255.255.0

Copy or mount the cd into the folder.

ls /usr/local/clonezilla_nfs/
COPYING                 isolinux                syslinux
Clonezilla-Live-Version live                    utils

Run

Boot the client and use clonezilla.

References:

Android - Get a string (or any resource) dynamically by its name.

Not so frequently asked questions and stuff: 

res\values\truc.xml:

LapinPouletSaucisse

quelquepart.java:

for (Integer i=1; i

UTF-8 ISO8859-1 quick cheatsheet

Not so frequently asked questions and stuff: 

Here is a quick reference about utf-8 decoding/encoding:

Image

How to format a file size in Excel (B, KB, MB, GB)

Not so frequently asked questions and stuff: 

In French:

=SI(A1>=1024*1024*1024; TEXTE(A1/(1024*1024*1024); "0")&" GiB";
SI(A1>=1024*1024; TEXTE((A1/(1024*1024)); "0")&" MiB"; 
SI(A1>=1024; TEXTE((A1/(1024)); "0")&" KiB";
TEXTE(A1; "0")&" B")))

In English:

=IF(A1>=1024*1024*1024; TEXT(A1/(1024*1024*1024); "0")&" GiB";
IF(A1>=1024*1024; TEXT((A1/(1024*1024)); "0")&" MiB"; 
IF(A1>=1024; TEXT((A1/(1024)); "0")&" KiB";
TEXT(A1; "0")&" B")))

Using MySQL through ODBC on FreeBSD.

Not so frequently asked questions and stuff: 

Installation and configuration

Install the following ports:

  • databases/unixODBC
  • databases/mysql-connector-odbc

Use odbcinst to find where odbcinst.ini is located.

odbcinst -j
unixODBC 2.3.0
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 4
SQLLEN Size........: 4
SQLSETPOSIROW Size.: 2

Edit /usr/local/etc/odbcinst.ini

cat /usr/local/etc/odbcinst.ini
[MySQL]
Description=ODBC for MySQL
Driver=/usr/local/lib/libmyodbc3.so
UsageCount=20001

Install the driver.

odbcinst -i -d -f /usr/local/etc/odbcinst.ini

Edit odbc.ini

cat /usr/local/etc/odbc.ini
[dsn_name]
Driver=MySQL
SERVER=localhost
PORT=3306
DATABASE=db_name
USER=user_name
PASSWORD=user_password
OPTION=4194304

Configure more options using this page: http://www.verbose.fr/mysql_5.1_en/connectors.html#myodbc-configuration-connection-parameters. Use FLAG_AUTO_RECONNECT to reconnect automatically.

List the available DSNs to check the config.

odbcinst -s -q
[dsn_name]

See also:

  • http://www.unixodbc.org/odbcinst.html
  • http://www.webaj.com/how-setup-mysql-dsn-datasbase-source-centos-myodbc-and-unixodbc-command-line.htm
  • http://wiki.freeswitch.org/wiki/Mod_spidermonkey_odbc#General_Configuration

Known problems

Auto reconnect does not work

Check the version of mysql-connector-odbc.

pkg_info | grep mysql-connector-odbc
mysql-connector-odbc-unixodbc-mysql51-3.51.26_3 ODBC driver for MySQL51 / unixodbc

The Mysql Bug #37179 states that FLAG_AUTO_RECONNECT does not work using versions prior to 3.51.27.
(http://bugs.mysql.com/bug.php?id=37179)
Upgrade the port if available, or correct the bug manually in connect.c before recompiling.

How to get yesterday's date in bash

Not so frequently asked questions and stuff: 

How to get yesterday's date in bash:

$date  +"%y-%m-%d"
10-11-14
$date -d @`expr $(date +%s) - 86400` +"%y-%m-%d"
10-11-13

For an unknown reason, the parameter @epoch is not documented in "man date" but it is in "info date".

smbclient can't list shares of windows 7

Not so frequently asked questions and stuff: 

Problem:
smbclient can't list the shares of a windows 7 box, even if smbmount can without problem.

$ smbclient -L //SOMEBOX -I 192.168.xx.yy
Enter someones's password: 
Anonymous login successful
Domain=[REZID] OS=[Windows 7 Professional 7600] Server=[Windows 7 Professional 6.1]

        Sharename       Type      Comment
        ---------       ----      -------
Error returning browse list: NT_STATUS_ACCESS_DENIED
Anonymous login successful
Domain=[REZID] OS=[Windows 7 Professional 7600] Server=[Windows 7 Professional 6.1]

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------

You are running a version of samba with a problem.
https://bugzilla.samba.org/show_bug.cgi?id=7577

$ smbclient --version
Version 3.3.2

Update samba to latest 3.4 or 3.5 or patch your current and enjoy.

 smbclient -L \\SOMEBOX -I 192.168.xx.yy
Enter root's password: 
Domain=[SOMEBOX] OS=[Windows 7 Professional 7600] Server=[Windows 7 Professional 6.1]

   Sharename       Type      Comment
   ---------       ----      -------
   ADMIN$          Disk      Administration à distance
 C$              Disk      Partage par défaut
    F$              Disk      Partage par défaut
    I$              Disk      Partage par défaut
    IPC$            IPC       IPC distant
   Share 1       Disk      
    Share 2         Disk      
  Share 3      Disk      
Domain=[SOMEBOX] OS=[Windows 7 Professional 7600] Server=[Windows 7 Professional 6.1]

    Server               Comment
    ---------            -------

    Workgroup            Master
 ---------            -------

Don't forget to update libsmbclient and libsmbclient-dev if you are using them.Problem:
smbclient can't list the shares of a windows 7 box, even if smbmount can without problem.

$ smbclient -L //SOMEBOX -I 192.168.xx.yy
Enter someones's password: 
Anonymous login successful
Domain=[REZID] OS=[Windows 7 Professional 7600] Server=[Windows 7 Professional 6.1]

        Sharename       Type      Comment
        ---------       ----      -------
Error returning browse list: NT_STATUS_ACCESS_DENIED
Anonymous login successful
Domain=[REZID] OS=[Windows 7 Professional 7600] Server=[Windows 7 Professional 6.1]

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------

You are running a version of samba with a problem.
https://bugzilla.samba.org/show_bug.cgi?id=7577

$ smbclient --version
Version 3.3.2

Update samba to latest 3.4 or 3.5 or patch your current and enjoy.

 smbclient -L \\SOMEBOX -I 192.168.xx.yy
Enter root's password: 
Domain=[SOMEBOX] OS=[Windows 7 Professional 7600] Server=[Windows 7 Professional 6.1]

 Sharename       Type      Comment
   ---------       ----      -------
   ADMIN$          Disk      Administration à distance
 C$              Disk      Partage par défaut
    F$              Disk      Partage par défaut
    I$              Disk      Partage par défaut
    IPC$            IPC       IPC distant
   Share 1       Disk      
    Share 2         Disk      
  Share 3      Disk      
Domain=[SOMEBOX] OS=[Windows 7 Professional 7600] Server=[Windows 7 Professional 6.1]

    Server               Comment
    ---------            -------

    Workgroup            Master
 ---------            -------

Don't forget to update libsmbclient and libsmbclient-dev if you are using them.

How to remove all the windows 6.x 6to4 adapter automatically

Not so frequently asked questions and stuff: 

You can remove them manually in the device manager (be sure to click "Show hidden devices").

Or you can use devcon.

devcon remove @ROOT\*6TO4MP\*

Source:

  • http://support.microsoft.com/kb/311272

Pages

Subscribe to Front page feed