[CentOS-devel] Centos Wiki tip proposal: Copy/verify files from CD/DVD quickly

Wojciech Pilorz

wpilorz at gmail.com
Tue Mar 27 23:08:11 UTC 2007


Hi folks,

Could you please look at the text below and attachements and comment please?

Best regards,

Wojtek
---------------------------------
CentOS Wiki tip proposal: Copy/verify files from CD/DVD quickly

If you want to copy a lot of files from CD or DVD, or verify md5 or
sha1 of a large number of files, keep in mind that CD/DVD drive seeks
are expensive and if are avoided as much as possible, the task could
be completed faster (and quieter).

Method 1.
Copy the image to hard disk and loopback mount it.

a) copying image
assuming device is /dev/dvd and disk is either a single-session CD or
CD-RW single session recorded in DAO mode, or DVD+RW recorded with
growisofs
$ dd if=/dev/dvd bs=2k of=hard_disk_directory/imagename.iso

It the media is a single-session CD or CD-RW recorded in TAO mode,
there are unreadable sectors at end of session, you need to determine
size:

$ isosize -x /dev/dvd

results are like this:

sector count: 346739, sector size: 2048

note sector count and read image using dd:

$ dd if=/dev/dvd bs=2k count=sector_count_value of=destination_image_file_path

Then, become root (e.g. using su), and
make mount point if needed, mount the image:
# mkdir -p /mnt/loop/myimage
# mount -o ro,loop destination_image_file_path /mnt/loop/myimage

Now you can use files in /mnt/loop/myimage, CD/DVD media is not needed.

NOTES on loopback method:
- needs root for lopback mount
- will work only for single session media (or first session of
multi-session media)
- no seeks when reading DV/DVD media, but entire media is being read,
justified only if you need to read most of the files, or a number of
file multiple times

Method 2
Access files in physical media order

You could observe, that (most of the time) inode numbers of files in
ISO9660 filesystem mounted on Linux are increasing as the start sector
numer of file increase (within a single session).
So to minimize seek operations access files in increasing inode value order.

Please use attached scripts
flist_by_inum.pl - sort file list by file inode number
flist_by_inum.pl - sort md5/sha1 list by file inode number

Mount the CD/DVD media, let us assume the mount point is /mnt/dvd

If you want to copy some or all regular files to destination_directory, run

cd /mnt/dvd
find . -type f -print0 | flist_by_inum.pl -0 | cpio -p0md destination_directory

You can of course give find utility some files/directories instead of .,
as well as any criteria.
If you are sure no file name contain white-space, etc, you can remove -0 and 0:

find . -type f -print | flist_by_inum.pl | cpio -pmd destination_directory

If you want to verify SHA1 fo the files, do the following:
cd /mnt/dvd
cat sha1sum_file | mdlist_by_inum.pl | sha1sum -wc > ~/verify.rslt
2>~/verify.msg

NOTES:
- no root privileges needed
- should work for multi-session discs (although with some seeks)
- only files needed are accessed
- method also useful for accessing files on loopback-mounted images
located on DVD
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flist_by_inum.pl
Type: application/x-perl
Size: 2407 bytes
Desc: not available
URL: <http://lists.centos.org/pipermail/centos-devel/attachments/20070328/8ad812a2/attachment-0004.pl>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mdlist_by_inum.pl
Type: application/x-perl
Size: 2603 bytes
Desc: not available
URL: <http://lists.centos.org/pipermail/centos-devel/attachments/20070328/8ad812a2/attachment-0005.pl>


More information about the CentOS-devel mailing list