Sunday, April 22, 2012

Remove carriage return ^M from a text file

Sometimes I have text files with a trailing carriage return character like this:

# vi file.txt
...
"foo"^M
"foo"^M
...

To remove them I use sed (when dos2unix is not available):

# cat file.txt | sed 's/\r//' > new.txt
# vi new.txt
...
"foo"
"foo"
... Print Friendly and PDF

Thursday, April 19, 2012

Creating empty files and using them as disks

If you ever needed some disks to test anything (eg. mdadm) then you can create your own harddisk in an existing filesystem. First create a 1GB file filled with zeros:

# dd if=/dev/zero of=/local/disk/vda bs=1 count=0 seek=1073741824
0+0 records in
0+0 records out
0 bytes (0 B) copied, 1.3252e-05 s, 0.0 kB/s

Set up the file as a loop device:

# losetup /dev/loop0 /local/disk/vda

Check that the loop device is available:

# losetup -a
/dev/loop0: [0803]:7605015 (/local/disk/vda)

Create a filesystem on the loop device:

# mkfs /dev/loop0
...

And mount it:

# mount /dev/loop0 /mnt/hd/
# df -h /mnt/hd
Filesystem            Size  Used Avail Use% Mounted on
/dev/loop0           1008M  1.3M  956M   1% /mnt/hd

To detach the loop device unmount the filesystem first:

# umount /mnt/hd

Then detach the loop0 device with losetup:

# losetup -d /dev/loop0

It is not possible to create one or more partition on a loop device this way! Print Friendly and PDF

Sunday, April 15, 2012

Accessing CD-ROM with FreeDOS

Today I decided to get my CD-ROM in FreeDOS running. As I have a nice old machine this was somekind tricky again. First I tried to load the uide caching driver:

C:\>devload uide.sys /D:CDROM01
...
XMS init error; UIDE not loaded!
...

No matter which option I used (/S5, /R63...) I got the above error. A closer look to the manual brought the solution:

...
/N3  Requests no XMS memory.
...
/N3 loses much speed, as "misaligned" or other I/O unsuited to UltraDMA must use BIOS logic for disks or "PIO mode" for CD/DVD input.
...

My machine has only 5MB of RAM, so I gave it a try:

C:\>devload uide.sys /N3 /D:CDROM01
...
UIDE, 10-16-2011.      Cache, CD-DVD name is CDROM01
No V2.0C+ PCI, BIOS I-O only!
CD0:  IDE0 Primary-Slave, CD-524E, PIO.
...

No error. I don't care if uide operates in slow motion now, the machine itself has only 16MHz with 5MB RAM - a 386 without a co-processor unit (playing Dune II is a pain in the rear on this machine - nevertheless: it works).
After the caching driver loaded succesfully, I have to run the CD-ROM redirector shsucdx:

C:\>shsucdx /D:CDROM01
...
SHSUCDX installed.
  Drives Assigned
Drive  Driver   Unit
  D:   CDROM01    0
...

Perfect. Just a quick test:

C:\>dir D:
...

And my CD-ROM was accessable.
To make the CD-ROM accessable after rebooting I have to add to above lines to FDCONFIG.SYS:

C:\>edit FDCONFIG.SYS
...
DEVICE=C:\FDOS\BIN\UIDE.SYS /N3 /D:CDROM01
...

And AUTOEXEC.BAT:

C:\>editAUTOEXEC.BAT
...
REM CDROM
C:\FDOS\BIN\SHSUCDX.COM /D:CDROM01
...

During booting I got the same messages:

...
UIDE, 10-16-2011.      Cache, CD-DVD name is CDROM01
No V2.0C+ PCI, BIOS I-O only!
CD0:  IDE0 Primary-Slave, CD-524E, PIO.
...
SHSUCDX installed.
  Drives Assigned
Drive  Driver   Unit
  D:   CDROM01    0
...

Links:
http://www.bootablecd.de/fdhelp-internet/en/hhstndrd/base/uide.htm
http://www.bootablecd.de/fdhelp-internet/en/hhstndrd/base/shsucdx.htm Print Friendly and PDF

Friday, April 13, 2012

Check CPU in FreeDOS

There are a lot of tools to get information and to measure the speed of your CPU, here is one which I think is compact and useful: CHKCPU    
It can be downloaded from http://web.inter.nl.net/hcc/J.Steunebrink/chkcpu.htm. Copy it to your FreeDOS machine and start it like this:

C:\>cd INSTALL
C:\INSTALL>unzip CKCPU121.ZIP
...
C:\INSTALL>CHKCPU.EXE

 CPU Identification utility v1.21         (c) 1997-2012 Jan Steunebrink
 ----------------------------------------------------------------------
 CPU Vendor and Model: 'classic' 386
 Internal CPU speed  : 16.0 MHz
 CPU-ID Vendor string: - No CPUID -
 Current CPU mode    : Virtual

When I release the 'Turbo' button on my case I only get the following:

C:\INSTALL>CHKCPU.EXE

 CPU Identification utility v1.21         (c) 1997-2012 Jan Steunebrink
 ----------------------------------------------------------------------
 CPU Vendor and Model: 'classic' 386
 Internal CPU speed  : 7.9 MHz
 CPU-ID Vendor string: - No CPUID -
 Current CPU mode    : Virtual

For my 486 I got the following:

A:\>CHKCPU.EXE
 
 CPU Identification utility v1.21         (c) 1997-2012 Jan Steunebrink
 ----------------------------------------------------------------------
 CPU Vendor and Model: AMD 486DX4 Enhanced or AMD 5x86 in 3x clock mode
 Internal CPU speed  : 100.6 MHz
 Clock Multiplier    : 3.0
 Bus clock speed     : 33.5 MHz
 CPU-ID Vendor string: AuthenticAMD
 CPU-ID Signature    : 000494
 ...
 Current CPU mode    : Real
 Internal (L1) cache : Enabled in Write-Back mode Print Friendly and PDF

Thursday, April 12, 2012

Basic networking with FreeDOS

Setting up a network with FreeDOS can be a little bit frustrating when you don't know how to do it (just like me). Here is a short description how I installed my network under FreeDOS. I am using my old 386 again with a 3COM EtherLink III (3C509B) ISA NIC.

Installing all software and drivers:

Before you begin you need to download a couple of additional software. The first software you need is the MSCLIENT software. The software can be downloaded from ftp://ftp.microsoft.com/bussys/Clients/MSCLIENT/. Download both packages, DSK3-1.EXE and DSK3-2.EXE. These packages contains the MS-DOS LAN-Manager and several drivers (various NIC's and the protocol driver).
The second software you need is the "Packet Driver to NDIS Converter", it can be download from http://www.shikadi.net/files/network/ndis2pd/dis_pkt9.zip.
Copy all three files to C:\INSTALL on your FreeDOS machine. Then change into that directory and begin to extract the MSCLIENT software. Start both exe files, these are self-extracting zip files:

C:\>cd \INSTALL
C:\INSTALL>DSK3-2.EXE
  Inflating: AM2100.DO_    -AV
  Inflating: AVEXTRA.TXT   -AV
...

When you try to run the second self-extracting exe file it will ask you to overwrite existing files, in case just type y:

C:\INSTALL>DSK3-2.EXE
...
PKSFX: (W18) Warning! AVEXTRA.TXT already exists.  Overwrite (y/n)?y
  Inflating: AVEXTRA.TXT   -AV
...

Finally extract the dis_pkt9.zip package:

C:\INSTALL>unzip DIS_PKT9.ZIP
Archive:  DIS_PKT9.ZIP
  exploding: ./DIS_PKT9.DOC         
  exploding: ./DIS_PKT9.ASM         
  exploding: ./DIS_PKT9.DOS

Next create your self a directory where you can store the minimum of files you need, eg. C:\TOOLS\NET:

C:\INSTALL>md \TOOLS
C:\INSTALL>md \TOOLS\NET

Now copy all needed files (LAN Manager, drivers etc) to C:\TOOLS\NET:

C:\INSTALL>copy DIS_PKT9.DOS ELNK3.DO_ EXPAND.EXE NETBIND.COM PROTMAN.DO_ PROTMAN.EX_ \TOOLS\NET2\
DIS_PKT9.DOS => \TOOLS\NET2\DIS_PKT9.DOS
ELNK3.DO_ => \TOOLS\NET2\ELNK3.DO_
EXPAND.EXE => \TOOLS\NET2\EXPAND.EXE
NETBIND.COM => \TOOLS\NET2\NETBIND.COM
PROTMAN.DO_ => \TOOLS\NET2\PROTMAN.DO_
PROTMAN.EX_ => \TOOLS\NET2\PROTMAN.EX_

If you have another NIC than me then copy the right driver for your hardware. Eg. for a NE2000 NIC copy the file NE2000.DO_.
The files that are ending with a trailing _ need to extract. To do so change into the C:\TOOLS\NET directory and run the expand tool which you have copied before:

C:\INSTALL>cd \TOOLS\NET
C:\TOOLS\NET>expand -r ELNK3.DO_ PROTMAN.DO_ PROTMAN.EX_
...
Expanding elnk3.do_ to elnk3.dos.
elnk3.do_: 9606 bytes expanded to 13014 bytes, 35% increase.
...

The files with the trailing _ can be removed now:

C:\TOOLS\NET>del ELNK3.DO_ PROTMAN.DO_ PROTMAN.EX_

Finally you are ready to configure your system. First open C:\FDCONFIG.SYS and add the drivers:

C:\TOOLS\NET>edit \FDCONFIG.SYS
...
DEVICEHIGH=C:\TOOLS\NET\PROTMAN.DOS /I:C:\TOOLS\NET
DEVICEHIGH=C:\TOOLS\NET\ELNK3.DOS
DEVICEHIGH=C:\TOOLS\NET\DIS_PKT9DOS
...

The first line will load the protocol driver. The option /I:C:\TOOLS\NET will tell the driver to look into C:\TOOLS\NET for the configuration file PROTOCOL.INI (I will show you this file later). The second line loads the driver for the NIC itself. The third line loads the TCP/IP driver. Next you need to edit C:\AUTOEXEC.BAT to load the LAN Manager during booting:

C:\TOOLS\NET>edit \AUTOEXEC.BAT
...
REM NETWORK
C:\TOOLS\NET\NETBIND.COM
...

Now create the configuration file for the protocol driver:

C:\TOOLS\NET>edit PROTOCOL.INI
[PROTMAN]
drivername=PROTMAN$

[NIC_ELNK3]
drivername=ELNK3$

[PKTDRV]
drivername=PKTDRV$
bindings=NIC_ELNK3
intvec=0x60
chainvec=0x68

So far that good, reboot your machine now and watch for some lines like this during booting:

...
3Com DOS EtherLink III Network Driver v2.0
MAC/DIS to Packet Driver converter loaded. Verison 1.09
...
MS-DOS LAN Manager v2.1 Netbind
...

If you see these messages (or similar depending on your hardware) then your machine is ready for basic networking.

Configuring a static IP:

To configure a static IP cange into the C:\FDOS directory and edit the MTCP.CFG file like this:

C:\>cd FDOS
C:\FDOS>edit MTCP.CFG
PACKETINT 0x60
IPADDR 192.168.1.99
NETMASK 255.255.255.192
GATEWAY 192.168.1.73
NAMESERVER 192.168.1.73
MTU 1500

Configuring a dynamic IP (dhcp):

To get an IP (and all other network settings) via DHCP run the dhcp command:

C:\>dhcp
mTCP DHCP Client by M Brutman (mbbrutman@gmail.com) (C)opyright 2008-2011
  Version: Oct 29 2011

Timeout per request: 10 seconds, Retry attempts: 3
Sending DHCP requests, Press [ESC] to abort.

DHCP request sent, attempt 1: Offer received, Acknowledged

Good news everyone!

IPADDR = 192.168.1.125
NETMASK = 255.255.255.192
GATEWAY = 192.168.1.73
NAMESERVER = 192.168.1.73
LEASE_TIME = 86400 seconds

Settings written to 'C:\FDOS\MTCP.CFG '

There you go. Your FreeDOS is now ready to use simple client applications like telnet or ftp (no more floppy disk changing).

Links:

http://sourceforge.net/apps/mediawiki/freedos/index.php?title=Networking_FreeDOS Print Friendly and PDF

Monday, April 9, 2012

PS2/Serial mouse in FreeDOS

I have a PS/2 mouse connected to PS/2-Serial converter which is plugged in my old 386 FreeDOS machine. Using the mouse with ctmouse gave me a little trouble but here is how I did it:

First I loaded ctmouse with the /M option (Mouse System / Genius):

C:\>ctmouse /M
CuteMouse v2.1 beta4 [FreeDOS]
Installed at COM1 (03F8h/IRQ4) in Mouse Systems mode

Then I forced ctmouse to use the mouse found at COM1 (S1) and IRQ4 (4):

C:\>ctmouse /S14
CuteMouse v2.1 beta4 [FreeDOS]
Resident part reset to COM1 (03F8h/IRQ4) in Microsoft mode

With these settings I was able to use my PS2 mouse on a serial adapter. When I loaded the driver directly with the /S14 option then it didn't worked anymore.
I tried a lot of options but these seems to be the best for me. The /3 option also works for a three button mouse (instead of the /S14 option). To use the correct driver settings I added the following lines to my AUTOEXEC.BAT:

C:\>edit AUTOEXEC.BAT
...
REM MOUSE
C:\FDOS\BIN\CTMOUSE /M
C:\FDOS\BIN\CTMOUSE /S14
REM C:\FDOS\BIN\CTMOUSE /3
... Print Friendly and PDF

Saturday, April 7, 2012

SoundBlaster (CT1350B and CT2960) in FreeDOS

CT1350B

The first soundcard I tested with FreeDOS was a SoundBlaster CT1350B which operates in 8Bit mode only, but it works out of the box. There is nothing more to tell, just set the correct BLASTER variable according as the jumpers on the soundcard.
There is a tool called SBCHECK.EXE (which seems to be a virus too so be careful when downloading it - I don't have any link for it) which will check your hardware:

C:\>TOOLS\MISC\SBCHECK.EXE
Sound Blaster compatible board found at hex 0220:
  DSP version 2.02
High-Speed Mono 8-bit board... use SB8.ADC driver.

CT2960

This soundcard was much more tricky to bring back to life. I don't have much experience with FreeDOS, no manual and no drivers for this soundcard. Of course I wanted this soundcard working because it operates in 16Bit mode already. Here is my description how to bring the CT2960 back to life (probably this description will help you with your soundcard too). First you need a software called Plug and Play Manager. Use your favorite search engine and search for pnp1632.exe (or see the link below). When you have found a suitable file then copy it to your FreeDOS machine and start it, eg:

C:\>cd install\drv\pnp1632
C:\install\drv\pnp1632>pnp1632.exe
...
Extracting DISK1
Extracting DISK1\README.COM
Extracting DISK1\INSTALL.EXE
...

Then change into the DISK1 directory and run INSTALL.EXE

C:\install\drv\pnp1632>cd DISK1
C:\install\drv\pnp1632\DISK1>INSTALL.EXE
...

Follow the options on the screen and install pnp1632 into eg. C:\TOOLS\PLUGPLAY\. When the installer asks for the second disk then change the path from eg. C:\install\drv\pnp1632\DISK1 to C:\install\drv\pnp1632\DISK2 (or where ever you have unpacked the installer). After the installer has finished it will change C:\CONFIG.SYS, the changes made in this file must be copied to C:\FDCONFIG.SYS manually:

C:\>edit FDCONFIG.SYS
...
DEVICE=C:\TOOLS\PLUGPLAY\DRIVERS\DOS\DWCFGMG.SYS
FILES=40
...

Before you continue reboot your machine and during booting you should see a line like this:

...
Found Plug and Play ISA card: Creative ViBRA16C PnP
...

Now you are ready to install the driver itself. Again, use your favorite search engine and search for sb16w31x.exe (or see the link below). Copy it to your FreeDOS machine and extract it, eg:

C:\>cd install\drv\sb16w31x
C:\install\drv\sb16w31x>sb16w31x.exe
...
Extracting DISK.ID
Extracting INSTALL.EXE
...

One more time, start INSTALL.EXE:

C:\install\drv\sb16w31x>INSTALL.EXE

Install the driver to eg C:\TOOLS\SB16 and follow the instructions on the screen. After the installer has finished it will change C:\AUTOEXEC.BAT like this:

C:\>more AUTOEXEC.BAT
...
SET SOUND=C:\TOOLS\SB16
SET BLASTER=A220 I5 D1 H5 P330 T6
SET MIDI=SYNTH:1 MAP:E
C:\TOOLS\SB16\DIAGNOSE /S
C:\TOOLS\SB16\MIXERSET /P /Q
...

Finally reboot your machine for the last time. Start the diagnose tool to check your soundcard:

C:\>TOOLS\SB16\DIAGNOSE.EXE

It will first check your soundcard and offers you to play a few samples. The driver installs a little mixer too:

C:\>TOOLS\SB16\MIXERSET.EXE

The mixer allows you to setup all volume level for all channels on the soundcard (CD-ROM, LINE-OUT etc).
There is a tool called SBCHECK.EXE (which seems to be a virus too so be careful when downloading it - I don't have any link for it) which will check your hardware:

C:\>TOOLS\MISC\SBCHECK.EXE
Sound Blaster compatible board found at hex 0220:
  DSP version 4.13
PnP Sound Blaster 16 / 32 / 64  board:
 16-bit ADC input stereo 8-bit DAC outputs
 (or 8-bit ADC with 16-bit DACs) using SB16.ADC driver.
   I:5   D:1   H:5

Links:
http://www.systemhaus-brandenburg.de/download/treiber/creative/creative.html Print Friendly and PDF

Monday, April 2, 2012

Measure network traffic in Solaris

Today I got stuck with a customer who was complaining that his local network was slow. Or as he said: "It feels slow"... What ever this means.
My task was to measure his network traffic on his Solaris 10 database machine and here is what I did. First I took a look at his network card:

# ifconfig -a
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        inet 127.0.0.1 netmask ff000000
ce0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
        inet 192.168.1.76 netmask ffffffc0 broadcast 192.168.1.127
        ether 0:3:ba:6e:aa:f4

The ce0 interface is his interface that is connected to the network. It has a default MTU of 1500 bytes set. The next thing I did was to keep track of his incoming network packages:

# netstat -I ce0 -i 1
    input   ce0       output       input  (Total)    output
packets errs  packets errs  colls  packets errs  packets errs  colls
574     0     405     0     0      632     0     463     0     0
...
1210    0     224     0     0      1210    0     224     0     0    
1165    0     192     0     0      1165    0     192     0     0
...

The -I option defines the interface to track (the customer has no logical interfaces otherwise I would use the -a option too) and the -i option defines the interval - in this case every second. Just like iostat, vmstat etc you can set an interval and a counter like -i 2 2. The first two lines of the netstat command is the usual header with input, output etc. The first line that appears after the header that starts with 574 represent all packages since system boot. All lines after that shows the current transmitted packages.
The next thing I did was the transfer a 177MB file while running the netstat command. I redirected the output to a file and told the customer not to use any network connection. The output I got was the following (only beginning and end):

...
0       0     0       0     0      0       0     0       0     0    
1       0     0       0     0      1       0     0       0     0    
16      0     32      0     0      16      0     32      0     0    
375     0     64      0     0      375     0     64      0     0    
689     0     96      0     0      689     0     96      0     0
...
1058    0     352     0     0      1058    0     352     0     0
889     0     320     0     0      889     0     320     0     0    
1920    0     640     0     0      1920    0     640     0     0    
222     0     96      0     0      222     0     96      0     0    
0       0     0       0     0      0       0     0       0     0
...

During the time range I received a sum of 130255 packages. With a MTU of 1500 bytes set I have to multiple these two numbers:

# echo 130255*1500 | bc -l
195382500

Dividing the 195382500 bytes by 1024 two time gives me the correct value in MB:

# echo 195382500/1024/1024 | bc -l
186.33127212524414062500

Including the transfer protocol (scp) and my own SSH session this value is close enough to 177MB.
During the copy process I got 124 lines of output (whitout the header etc). With an interval of one second I know that each line represent one second, so the server received 186MB in about 2 minutes. Which is pretty slow for a GB network. Print Friendly and PDF