how to copy linux file system to another hard disk
* To: terrence@localhost.localdomain
* Subject: how to copy linux file system to another hard disk
* From: Terrence Miao <terrence@unimelb.edu.au>
* Date: Tue, 20 Jan 2004 15:35:19 +1100
* User-agent: Mutt/1.4.1i
how to copy linux file system to another hard disk
--------------------------------------------------
1. partition the new hard disk; create /boot, /, swap partitions; make file
system (including swap, use commands mkfs.ext3 and mkswap, swapon)
[root@esker root]# fdisk -l /dev/hda
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 2080 16707568+ 7 HPFS/NTFS
/dev/hda2 2081 2093 104422+ 83 Linux
/dev/hda3 2094 2347 2040255 82 Linux swap
/dev/hda4 2348 9729 59295915 f Win95 Ext'd (LBA)
/dev/hda5 2348 9729 59295883+ 83 Linux
2. use "cp -a" command, copy the following directories to new hard
disk (ignore "/proc" directory):
[root@esker /]# ls -1
bin
boot
dev
etc
home
initrd
lib
lost+found
misc
mnt
opt
root
sbin
tmp
usr
var
[root@esker /]# mkdir proc (on the new hard disk)
3. install grub boot loader:
[root@esker /]# cat /boot/grub/device.map
# this device map was generated by anaconda
(fd0) /dev/fd0
(hd0) /dev/hda
[root@esker /]# grub-install --root-directory=/boot '(hd0)'
OR
boot the new hard disk with GRUB Boot floppy, install GRUB natively:
[root@esker /]# cd /usr/share/grub/i386-pc
[root@esker /]# dd if=stage1 of=/dev/fd0 bs=512 count=1
1+0 records in
1+0 records out
[root@esker /]# dd if=stage2 of=/dev/fd0 bs=512 seek=1
153+1 records in
153+1 records out
Once booted from floppy, GRUB will show the command-line interface (*note
Command-line interface:
. First, set the GRUB's "root device"(1)
(*note Installing GRUB natively-Footnote-1:
to the boot directory,
like this:
grub> root (hd0,0)
Once you've set the root device correctly, run the command `setup'
(*note setup:
:
grub> setup (hd0)
4. modify file "fstab" and "grub.conf":
[root@esker /]# cat /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
none /proc proc defaults 0 0
none /dev/shm tmpfs defaults 0 0
/dev/hda3 swap swap defaults 0 0
/dev/cdrom /mnt/cdrom udf,iso9660
noauto,owner,kudzu,ro 0 0
/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0
0
[root@esker /]# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,1)
# kernel /vmlinuz-version ro root=/dev/hda5
# initrd /initrd-version.img
#boot=/dev/hda
default=0
timeout=30
splashimage=(hd0,1)/grub/splash.xpm.gz
title Red Hat Linux (2.4.20-
root (hd0,1)
kernel /vmlinuz-2.4.20-8 ro root=LABEL=/
initrd /initrd-2.4.20-8.img
title Red Hat Linux (2.4.20-8 with FrameBuffer)
root (hd0,1)
kernel /vmlinuz-2.4.20-8 ro root=LABEL=/ vga=773
initrd /initrd-2.4.20-8.img
title Windows XP
rootnoverify (hd0,0)
chainloader +1
--
[m[1;31m※ 来源:·北大未名站 bbs.pku.edu.cn·[FROM: 162.105.250.20][m