CF card partitioning with rdbtool

Here is my little easter present for you: I finished the first release of rdbtool. “What’s that?” you may ask. It’s a new member of amitools, a family of cross-platform Classic Amiga tools I am developing. rdbtool is a command line utility that allows you to inspect, change or create new disk images or even real disks with Amiga’s RDB partitioning format. Its a companion tool to xdftool that handles Amiga’s file system in disk images or on the RDB partitions.

I had the idea for this tool while changing the CF flash card of my A1200. I removed the old card, had look at the files found there and wanted to retrieve files from there and then set up a new shiny card and build up partitions there. The current way to accomplish this, is to dump the card’s raw data from the block device and use this image as a RDB hard disk image in UAE to retrieve the files from there. Same thing with partitioning the new card: mount the block device or an empty image in UAE, run HDToolBox there, format partitions and copy files around in the virtual Amige environment… This works, but its a roundabout way. I wanted to have a nifty tool the works directly on my Mac’s Terminal… 🙂

Read on to see how this task (and lots more!) can be achieved with rdbtool…

Inspecting an old CF Card

Ok, here we go: I unmount the CF card from the A1200 and insert it into my CF card USB reader on my Mac. Mac OS X tells me that it can’t find a valid file system on it (and that’s true for osx :)) – we ignore this and cancel the request to initalize (= format) it. First thing is now to find out the block device for this disk. On OS X I call a:

> diskutil list

and it gives me:

/dev/disk2
 #:                       TYPE NAME                    SIZE       IDENTIFIER
 0:                                                   *4.0 GB     disk2

The empty Type Name gives you the hint that the partioning format is not recognized by OS X! So, it’s /dev/disk2… On Linux or other Posix systems the naming of raw block devices is slighty different (e.g. /dev/sd?). Just have a look at your system manuals (or dmesg) for details…

Now I use rdbtool to list the partition setup directly on the card:

> rdbtool /dev/disk2 info
PhysicalDisk:               0     7817     7880544  3.8Gi  heads=16 sectors=63
LogicalDisk:                2     7817     7878528  3.8Gi  rdb_blks=[0:2015,#2016] used=[hi=60,#61] cyl_blks=1008
Partition: #0 'CDH0'        2      103      102816   50Mi    1.31%  DOS3 bootable pri=0
Partition: #1 'DH0'       104      205      102816   50Mi    1.31%  DOS3
Partition: #2 'DH1'       206     2035     1844640  900Mi   23.41%  DOS3
Partition: #3 'DH2'      2036     3763     1741824  850Mi   22.11%  DOS3
Partition: #4 'DH3'      3764     3909      147168   71Mi    1.87%  DOS3
Partition: #5 'CDH1'     3910     3971       62496   30Mi    0.79%  DOS3
Partition: #6 'DH4'      3972     4124      154224   75Mi    1.96%  DOS3
Partition: #7 'DH5'      4125     5953     1843632  900Mi   23.40%  DOS3
Partition: #8 'DH6'      5954     7817     1878912  917Mi   23.85%  DOS3
FileSystem #0 DOS1 version=40.1 size=24588 seg_list_blk=0xb global_vec=0xffffffff

Wow! Got a lot of partitions there… With the drive names (DH0, …) at hand you use xdftool to access the file system on each partition (I use -r option here to enable read-only mode – just for safety reasons):

> xdftool -r /dev/disk2 open part=DH1 + list
Games 1                                          VOLUME  --------  29.03.1993 11:35:33 t46  
  Disk.info                                         364  ----rw-d  29.03.1993 11:35:33 t47
...

With the unpack command of xdftool I was able to easily recover all files of a partition into a directory structure on my Mac.

The info output also showed that a file system driver was also embedded in the RDB structure. You can use the fsget command to retrieve the Amiga loadSeg()able binary:

> rdbtool /dev/disk2 fsget 0 ffs

0 is the number of the first and only file system driver on this disk and “ffs” is the local Mac file name for the binary:

> ls -la ffs
-rw-r--r--  1 chris  staff  24588  6 Apr 13:48 ffs

You can also have a closer look of the internals of the RDB structure with the map and show commands. Map shows the contents of the RDB area and describes the contents of each block (see rdbtool page for details) while show dumps all blocks describing the RDB:

> rdbtool /dev/disk2 map
000000:  RD P0 P1 P2 P3 P4 P5 P6 P7 P8 F0 F0 F0 F0 F0 F0
000016:  F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0
000032:  F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0
000048:  F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 F0 -- -- --
...
> rdbtool /dev/disk2 show
RigidDiskBlock(0):
 types:     5244534b/0 (valid: 5244534b/0)
 chksum:    0x7471bb06 (got) 0x7471bb06 (calc)
 valid:     True
 size:           64
 host_id:        7
 block_size:     512
 flags:          0x00000017
 badblk_list:    none
 part_list:      1
 fs_list:        10
 init_code:      none
...

While working on a real disk you do not want to alter, it is advisable to either use the -r switch to enable read-only mode in rdbtool or simply copy the whole disk into a disk image and work on the image (if you have the disk space available, of course!):

> dd if=/dev/disk2 of=disk.rdb bs=512
> rdbtool disk.rdb list

That’s it for inspecting an existing RDB disk. Now let’s create an own, new one…

Partitioning a new Disk

Insert a shiny new CF card into your card reader. Typically some FAT file system already resides on a partition of the card. First thing is to remove the existing partioning layout. On OSX I do (for /dev/disk1):

> diskutil partitionDisk disk1 free none 100%

Now rdbtool can access the disk. The first command we will issue is an init, it will create an empty RDB block on the disk. The info will show an empty layout:

> rdbtool /dev/disk1 init + info
PhysicalDisk:               0    61999     1984000  968Mi  heads=1 sectors=32
LogicalDisk:                1    61999     1983968  968Mi  rdb_blks=[0:31,#32] used=[hi=0,#1] cyl_blks=32

A logical RDB disk is created automatically but no partition exist yet. So let’s add some! The add command adds a partition and only requires a size given either in percent (20%), bytes (2Mb), KiBytes (2Mib), or cylinders (20). If no start is given then the next free region on the logical disk is chosen:

> rdbtool /dev/disk1 add size=50Mib + add size=100Mib + fill + info
PhysicalDisk:               0    61999     1984000  968Mi  heads=1 sectors=32
LogicalDisk:                1    61999     1983968  968Mi  rdb_blks=[0:31,#32] used=[hi=3,#4] cyl_blks=32
Partition: #0 'DH0'         1     3200      102400   50Mi    5.16%  DOS3
Partition: #1 'DH1'      3201     9600      204800  100Mi   10.32%  DOS3
Partition: #2 'DH2'      9601    61999     1676768  818Mi   84.52%  DOS3

Note the fill command: It will create a partition to fill the remaining space on the logical disk.

You can alter settings of a partition with the change command: I use it to make the first partition bootable and set its priority:

> rdbtool /dev/disk1 change DH0 bootable pri=10 + info
...
Partition: #0 'DH0'         1     3200      102400   50Mi    5.16%  DOS3 bootable pri=10
...

(See rdbtool manual page for more options). You can also pass these options to the add command in the previous step for a more compact usage of the tool.

The partition layout is already finished, the only thing I’d like to add to my RDB is the FFS file system driver restored from the old card (see above):

> rdbtool /dev/disk1 fsadd ffs + info
ERROR adding filesystem! (no space in RDB left)

Oops! There is not enough space left for the file system. I have to recreate the RDB with more space reserved for the filesystem (see rdb_cyls = reserve a number of cylinders for RDB usage):

> rdbtool /dev/disk1 init rdb_cyls=2 + add size=50Mib bootable pri=10 + add size=100Mib + fill + fsadd ffs + info
PhysicalDisk:               0    61999     1984000  968Mi  heads=1 sectors=32
LogicalDisk:                2    61999     1983936  968Mi  rdb_blks=[0:63,#64] used=[hi=54,#55] cyl_blks=32
Partition: #0 'DH0'         2     3201      102400   50Mi    5.16%  DOS3 bootable pri=10
Partition: #1 'DH1'      3202     9601      204800  100Mi   10.32%  DOS3
Partition: #2 'DH2'      9602    61999     1676736  818Mi   84.52%  DOS3
FileSystem #0 DOS1 version=40.1 size=24588

Voila! Everything set up in a single command 😉

RDB work is done now! (See rdbtool page for lots of more commands available in this tool). Now let’s head over to xdftool and format the partitions:

> xdftool /dev/disk1 open part=dh0 + format System
> xdftool /dev/disk1 open part=dh1 + format Work
> xdftool /dev/disk1 open part=dh2 + format Data

Now everything is partitioned and formatted for AmigaDOS use. Typically, you want to boot from the first partition, so its advisable to fill it now. In my case I used the pack command of xdftool to restore the Workbench files I recovered with unpack from my old card…

With this approach, setting up an Amiga disk drive on your Mac is done in seconds with rdbtool and xdftool. No need to boot up an emulator, just plain native tools 😉 I hope you enjoyed this little introduction and find the tools as useful as I do…

Leave a Reply