-   Linux - Software (
-   -   Translating Backup Media Capacity into Blocks (

josephj 12-01-2008 01:30 AM

Translating Backup Media Capacity into Blocks
I need help understanding how to calculate available media storage space in blocks for various removable media.

I have a script I wrote a few years ago for making file system backups using dump and partimage. When I originally wrote it, someone gave me a "magic" number, 614400, which translates into 600MB which was fine for low capacity cdroms. The line of code that does the dump work (in a loop) is:

/sbin/dump 0uMBzf 614400 /mnt/portable/${target[$i]} /dev/${filesys[$i]}

It writes a segmented dump in chunks that will fit on individual cdroms.

I looked up dump again and option B lets you specify the chunk size in 1024 byte blocks, but 614400 * 1024 doesn't equal 600MB (unless maybe it's a power of ten thing).

Also, I know that when I write to any media, some of the space is used for overhead like directory structures.

Now, I need to update the script for two different media types: Regular cdroms which supposedly hold 700MB and dvd+r's that hold 4.7GB.

If I just divide the bytes by 1024, that won't take into account overhead and I'm not sure whether the specs are measured in x * 1000 or x * 1024.

So, how do I calculate the new chunk sizes for these or other media types?



sundialsvcs 12-02-2008 11:38 AM

I would simply determine what is an appropriate "chunk size" that will easily fit on the smallest media that you need to deal with: the CD.

Larger-capacity media such as DVDs can then simply store "more than one of these chunks." (For that matter, CDs can do the same thing.)

This strategy has the compelling advantage that it will continue to work even as media-sizes continue to expand. "A media of a particular size 'x' will hold 'y' chunks, with some amount of wasted space." These media are so cheap that you just don't need to worry about squeezing just-a-little more out of each one. Build a solution that you can "just build once." Maybe you already have that solution...

josephj 12-03-2008 10:23 PM

Need specifics
That's good in principle, but I'm not going to put just 600MB on a DVD and I still don't know exactly how many 600MB's would fit on a DVD.

I just need to be able to calculate *usable* media size in bytes (after overhead) and then divide that by 1024. And, that's what I still don't know how to do.


josephj 07-13-2009 05:38 PM

This one took me forever to figure out, but it's pretty simple in the end.

Media manufacturers list capacities in MB and GB.
These units have been redefined in recent years to be 1000^2 and 1000^3. They used to be 1024^2 and 1024^3. These are now called MiB and GiB respectively.

Linux still does things in 1024 byte (1 KiB) blocks, so you have to convert between the two. The units command will do the math for you.

Below is a code sample from one of my bash scripts that sets the media size in blocks based on the media type I have set in a variable. The actual sizes are the result of division and then integer truncation along with a little wiggle room, so the real media is slightly larger.

Since these values (in my scripts) will be passed to dump or partimage, they are further divided so that no backup chunk will be greater than 2GiB which makes mkisofs happy when creating an image to burn to media. (I put 2 chunks on a DVD and 4 chunks on a DVD/DL.)


## Set media sizes - adjust if your media capacities differ

## mkisofs refuses to write a file bigger than 4GiB
## and one of the standards (somewhere) says individual files
## Can't be larger than 2GiB
## So split them by 2 and 4 for DVD and DVDDL
## But now they changed KB,MB, GB to x 1000 (decimal)
## and KiB, Mib, Gib are x 1024 (binary)
## God bless marketing ....
## And, the blinking capacity specs are in GB, MB
## So those have to be translated back into KiB
## 8.5GB = 8,500,000,000B
## divided by 1024
## then divided by 4

case "${MEDIA}" in
  SIZE="2294921";    ## 1/2 Size
  HSIZE="4.7GB";    ## Human-readable size
  SIZE="2075195";    ## 1/4 Size
  SIZE="683593";    ## Full Size
  echo "ERROR ${USAGE}"
  exit 1;

All times are GMT -5. The time now is 07:47 PM.