Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
50.  Copying UFS Files and File Systems (Tasks) Copying File Systems Between Disks Making a Literal File System Copy  Previous   Contents   Next 
   
 

How to Copy a Disk (dd)

  1. Make sure that the source disk and destination disk have the same disk geometry.

  2. Become superuser or assume an equivalent role.

  3. Create the /reconfigure file so the system will recognize the clone disk to be added when it reboots.

    # touch /reconfigure
  4. Shut down the system.

    # init 0
  5. Attach the clone disk to the system.

  6. Boot the system.

    ok boot
  7. Copy the master disk to the clone disk.

    # dd if=/dev/rdsk/device-name of=/dev/rdsk/device-name bs=block-size

    if=/dev/rdsk/device-name

    Represents the overlap slice of the master disk device, usually slice 2.

    of=/dev/rdsk/device-name

    Represents the overlap slice of the clone disk device, usually slice 2.

    bs=blocksize

    Identifies block size, such as 128 Kbytes or 256 Kbytes. A large block size value decreases the time it takes to copy.

    For more information, see dd(1M).

  8. Check the new file system.

    # fsck /dev/rdsk/device-name
  9. Mount the clone disk's root (/) file system.

    # mount /dev/dsk/device-name /mnt
  10. Edit the clone disk's /etc/vfstab to reference the correct device names.

    For example, change all instances of c0t3d0 with c0t1d0.

  11. Unmount the clone disk's root (/) file system.

    # umount /mnt
  12. Shut down the system.

    # init 0
  13. Boot from the clone disk to single-user mode.

    # boot diskn -s

    Note - The installboot command is not needed for the clone disk because the boot blocks are copied as part of the overlap slice.


  14. Unconfigure the clone disk.

    # sys-unconfig

    The system is shut down after it is unconfigured.

  15. Boot from the clone disk again and provide its system information, such as host name, time zone, and so forth.

    # boot diskn
  16. Log in as superuser to verify the system information after the system is booted.

    hostname console login:

Example--Copying a Disk (dd)

This example shows how to copy master disk /dev/rdsk/c0t0d0s2 to clone disk /dev/rdsk/c0t2d0s2.

# touch /reconfigure
# init 0
ok boot
# dd if=/dev/rdsk/c0t0d0s2 of=/dev/rdsk/c0t2d0s2 bs=128k
# fsck /dev/rdsk/c0t2d0s2
# mount /dev/dsk/c0t2d0s2 /mnt 
# cd /mnt/etc
# vi vfstab
(Modify entries for the new disk)
# cd /
# umount /mnt
# init 0
# boot disk2 -s
# sys-unconfig
# boot disk2

Copying Directories Between File Systems (cpio Command)

You can use the cpio (copy in and out) command to copy individual files, groups of files, or complete file systems. This section describes how to use the cpio command to copy complete file systems.

The cpio command is an archiving program that copies a list of files into a single, large output file. This command inserts headers between the individual files to facilitate recovery. You can use the cpio command to copy complete file systems to another slice, another system, or to a media device, such as a tape or diskette.

Because the cpio command recognizes end-of-media and prompts you to insert another volume, it is the most effective command (other than ufsdump) to use to create archives that require multiple tapes or diskettes.

With the cpio command, you frequently use commands like ls and find to list and select the files you want to copy, piping the output to the cpio command.

How to Copy Directories Between File Systems (cpio)

  1. Become superuser or assume an equivalent role.

  2. Change to the appropriate directory.

    # cd filesystem1
  3. Copy the directory tree from filesystem1 to filesystem2 by using a combination of the find and cpio commands.

    # find . -print -depth | cpio -pdm filesystem2

    .

    Starts in the current working directory.

    -print

    Prints the file names.

    -depth

    Descends the directory hierarchy and prints file names on the way back up.

    -p

    Creates a list of files.

    -d

    Creates directories as needed.

    -m

    Sets the correct modification times on directories.

    For more information, see cpio(1).

    The files from the directory name you specify are copied and symbolic links are preserved.

    You might also specify the -u option. This option forces an unconditional copy. Otherwise, older files do not replace newer files. This option might be useful if you want an exact copy of a directory, and some of the files being copied might already exist in the target directory.

  4. Verify that the copy was successful by displaying the destination directory contents.

    # cd filesystem2
    # ls
  5. If appropriate, remove the source directory.

    # rm -rf filesystem1

Example--Copying Directories Between File Systems (cpio)

# cd /data1
# find . -print -depth | cpio -pdm /data2
19013 blocks
# cd /data2
# ls
# rm -rf /data1

Copying Files and File Systems to Tape

You can use the tar, pax, and cpio commands to copy files and file systems to tape. The command you choose depends on how much flexibility and precision you require for the copy. Because all three commands use the raw device, you do not need to format or make a file system on tapes before you use them.

Table 50-3 Advantages and Disadvantages of tar, pax, and cpioCommands

Command

Function

Advantages

Disadvantages

tar

Use to copy files and directory subtrees to a single tape

  • Available on most UNIX operating systems

  • Public domain versions are readily available

  • Is not aware of file system boundaries

  • Full pathname length cannot exceed 255 characters

  • Does not copy empty directories or special files such as device files

  • Cannot be used to create multiple tape volumes

pax

Use to copy files, special files, or file systems that require multiple tape volumes or when you want to copy files to and from POSIX-compliant systems

  • Better portability than the tar or cpio commands for POSIX-compliant systems

  • Multi vendor support

Same disadvantages as for the tar command, except that the pax command can create multiple tape volumes

cpio

Use to copy files, special files, or file systems that require multiple tape volumes or when you want to copy files from SunOS 5.9 systems to SunOS 4.0/4.1 systems

  • Packs data onto tape more efficiently than the tar command

  • Skips over any bad spots in a tape when restoring

  • Provides options for writing files with different header formats (tar, ustar, crc, odc, bar) for portability between different system types

  • Creates multiple tape volumes

The syntax is more difficult than the tar or pax commands

 
 
 
  Previous   Contents   Next