old-www/HOWTO/Hard-Disk-Upgrade/copy.html

493 lines
8.7 KiB
HTML

<HTML
><HEAD
><TITLE
>Copy the files from the old disk to the new disk</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.56"><LINK
REL="HOME"
TITLE="Hard Disk Upgrade Mini How-To"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="Mount the new disk"
HREF="mount.html"><LINK
REL="NEXT"
TITLE="Modify /new-disk/etc/fstab as appropriate"
HREF="modify.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Hard Disk Upgrade Mini How-To</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="mount.html"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="modify.html"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="COPY"
>7. Copy the files from the old disk to the new disk</A
></H1
><P
>You might want to go to single-user mode before starting to copy the
disk, in order to shut down the system daemons and preserve the state of
the logs, and to prevent users from logging in:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>/sbin/telinit 1</PRE
></TD
></TR
></TABLE
></P
><P
>When copying the hard disk, you want to copy all directories and
files, including links.</P
><P
>However, you don't want to copy the directory
<TT
CLASS="FILENAME"
>/new-disk</TT
>, since this
would copy the new disk to itself!</P
><P
>Furthermore, you want to create the
<TT
CLASS="FILENAME"
>/proc</TT
> directory on the new disk,
but you don't want to copy its contents:
<TT
CLASS="FILENAME"
>/proc</TT
> is a
<I
CLASS="EMPHASIS"
>virtual</I
> file system and doesn't have any actual
files, but rather contains information on the processes running on the
system.</P
><P
>Here are three different ways to copy the old disk to the new
one. This may take quite a while, especially if you have a large disk or
little memory. You can expect to be able to copy 10 Mb per minute, and
possibly much more.</P
><P
>You can follow the copy's progress by using the command
<B
CLASS="COMMAND"
>df</B
> from another terminal. Try
<B
CLASS="COMMAND"
>watch df</B
> or <B
CLASS="COMMAND"
>watch ls -l /new-disk</B
>
to see a report updated every two seconds; press <B
CLASS="KEYCAP"
>Ctrl</B
>-<B
CLASS="KEYCAP"
>C</B
>
to end the display. Be aware that running the
<B
CLASS="COMMAND"
>watch</B
> program itself will slow down the copying.</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><B
CLASS="COMMAND"
>cp -ax / /new-disk</B
></DT
><DD
><P
>This is the simplest method, but will only work if your original
Linux system is on a single disk partition.</P
><P
>The <TT
CLASS="OPTION"
>-a</TT
> option preserves the original system as
much as possible. The <TT
CLASS="OPTION"
>-x</TT
> option limits cp to a
single file system; this is necessary to avoid copying the
<TT
CLASS="FILENAME"
>/new-disk</TT
>
and
<TT
CLASS="FILENAME"
>/proc</TT
> directories.</P
><DIV
CLASS="FORMALPARA"
><P
><B
>SuSE only. </B
>With this method only, you must also create the directory
<TT
CLASS="FILENAME"
>/dev/pts</TT
> on the new
disk. Use the command
<B
CLASS="COMMAND"
>mkdir /new-disk/dev/pts"</B
>.</P
></DIV
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>When using the <TT
CLASS="OPTION"
>-x</TT
> option, recent versions of
<B
CLASS="COMMAND"
>cp</B
> will create the directories
<TT
CLASS="FILENAME"
>/new-disk/new-disk</TT
> and
<TT
CLASS="FILENAME"
>/new-disk/proc</TT
>,
although the directories will be empty. If these directories are
created, you should delete
<TT
CLASS="FILENAME"
>/new-disk/new-disk</TT
>, and
keep <TT
CLASS="FILENAME"
>/new-disk/proc.</TT
>
</P
></BLOCKQUOTE
></DIV
></DD
><DT
><B
CLASS="COMMAND"
>cd / &#38;&#38; echo cp -a `/bin/ls -1Ab | egrep -v "^new-disk$|^proc$"` /new-disk | sh
</B
></DT
><DD
><P
><I
CLASS="EMPHASIS"
>(write this all on one line)</I
></P
><P
>This goes to the root directory and then copies all files and
directories except
<TT
CLASS="FILENAME"
>/new-disk</TT
> and
<TT
CLASS="FILENAME"
>/proc</TT
> to
<TT
CLASS="FILENAME"
>/new-disk</TT
>. Note that the
first option after ls is the number 1, not the letter L!</P
><P
>This command should work in all circumstances.</P
></DD
><DT
><B
CLASS="COMMAND"
>cp -a /bin /boot /dev /etc /home /lib /lost+found /mnt /root /sbin /tmp /usr /var /new-disk
</B
></DT
><DD
><P
><I
CLASS="EMPHASIS"
>(write this all on one line)</I
></P
><P
>The last directory,
<TT
CLASS="FILENAME"
>/new-disk</TT
>, is the destination
for the <B
CLASS="COMMAND"
>cp</B
> command. All the other directories are
the sources. Therefore, we're copying all the directories we're
listing to <TT
CLASS="FILENAME"
>/new-disk</TT
>.</P
><P
>With this method, you simply list yourself the directories you
want to copy. Here we listed all the directories except
<TT
CLASS="FILENAME"
>/new-disk</TT
>
and <TT
CLASS="FILENAME"
>/proc</TT
>.
If you can't use the other methods for any reason, you
can always use this command to manually specify the directories
you want to copy.</P
><P
>With this method only, if there are any files in the root
directory itself, you need another command to copy them. In
particular, this is required with Debian and Slackware, since these
distributions put files in the root directory:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cp -dp /* /.* /new-disk</PRE
></TD
></TR
></TABLE
></P
></DD
></DL
></DIV
><P
>Previous versions of the Mini How-To stated that you could also use
<B
CLASS="COMMAND"
>tar</B
> to copy the disk, but this method was found to have
a bug. There are of course many other ways to copy the disks, but these
three are the simplest, quickest, and most reliable.</P
><P
>After using any of these three methods, you must also create the
<TT
CLASS="FILENAME"
>/proc</TT
>
directory on the new disk, if it doesn't already exist:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>mkdir /new-disk/proc</PRE
></TD
></TR
></TABLE
></P
><P
>At this point, you may verify the file structure on the new disk, if you wish:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>umount /new-disk
fsck.ext2 -f /dev/hdb1
mount -t ext2 /dev/hdb1 /new-disk</PRE
></TD
></TR
></TABLE
>
</P
><P
>If the new disk has more than one partition, you must unmount them
from the <I
CLASS="EMPHASIS"
>bottom up</I
> before running
<B
CLASS="COMMAND"
>fsck.ext2</B
>: in the example mentioned above, you'd first
unmount the 3rd level partitions, then the 2nd level
partitions, and then the 1st level partition.</P
><P
>You may also compare the two disks, to ensure that the files were
copied properly:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>find / -path /proc -prune -o -path /new-disk -prune -o -xtype f -exec cmp {} /new-disk{} \;</PRE
></TD
></TR
></TABLE
></P
><P
><I
CLASS="EMPHASIS"
>(write this all on one line)</I
></P
><DIV
CLASS="FORMALPARA"
><P
><B
>Slackware only. </B
> A basic Slackware installation ("A" series only)
doesn't include the <B
CLASS="COMMAND"
>cmp</B
> command, so you won't be able
to run this command if you have only installed the basic files. The
<B
CLASS="COMMAND"
>cmp</B
> command is in the "AP1" series.)</P
></DIV
><P
>This will only compare regular files, not character or block special
files (in the
<TT
CLASS="FILENAME"
>/dev</TT
> directory), sockets, etc.,
since the <B
CLASS="COMMAND"
>cmp</B
> command doesn't work properly with
these. We would welcome suggestions on how to verify these "special"
files.</P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="mount.html"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="modify.html"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Mount the new disk</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Modify <TT
CLASS="FILENAME"
>/new-disk/etc/fstab</TT
> as appropriate</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>