[clug] duplicate a file system to a smaller hard disk

Brett Worth brett at worth.id.au
Mon Aug 10 06:35:52 MDT 2009

Chris Zhang wrote:

> I have been looking for a way to clone a complete working Linux system
> on a 250GB (22GB used) hard disk to a smaller hard disk. 

Here's a simple series of steps:

Boot the system with the target disk as sdb
List the first drive's partition table: fdisk -l sda
Use fdisk on /dev/sdb to create the new partions as required setting the "Type" flags to
match.  Just match the partitions from the first disk with adjusted sizes. Obviously at
least one of them will be a lot smaller.  Save the fdisk config.
Make the filesystems using mkfs.  The details will depend on what filesystem types you
have.  Look at the way your mounts are being done in /etc/fstab.  You might need to use
Initialise the swap partition with "mkswap".  Might also need a label.

Make a mountpoint for the new set of filesystems e.g. mkdir /new
Mount the new root there: mount /dev/sdbX /new
Mount the other filesystems: e.g. if you have a separate var:
	mkdir /new/var
	mount /dev/sdbX /new/var
Repeat with all the filesystems you've made.
Now for each filesystem:
	rsync -avHx / /new/
	rsync -avHx /var/ /new/var/
Umount the new disk in reverse order:
	umount /new/var
	umount /new
Remove sda
Configure new smaller disk as sda
Boot a rescue CD
Run grub from the CD
If you have a separate /boot partition:
	grub> find /grub/stage1
	grub> find /boot/grub/stage1
Set root to the returned value e.g.:
	grub> root (hd0,0)
	grub> root (hd0,1)
Write out the MBR:
	grub> setup (hd0)
	grub> quit
Remove rescue disk
Have a lot of fun.
Don't forget to remove the /new directory.

I'm sure there's a way to get the MBR on there without booting the CD but that's just the
way I've always done it.


More information about the linux mailing list