LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Blogs > neonsignal
User Name
Password

Notices

Rate this Entry

migrating a system to a new disk

Posted 05-18-2011 at 05:16 AM by neonsignal
Updated 05-18-2011 at 05:18 AM by neonsignal

This is a procedure for migrating a whole system to a new disk (such as when upgrading the primary disk in a machine). The new disk is installed alongside the old one (either in a spare ATA port, or using a USB adapter).

First partition the new disk (the examples here assume the original disk is sda and the new disk is sdb):
Code:
fdisk /dev/sdb
Assuming all of the system is to be in a single partition, make a primary partition 'n', 'p', taking most of the drive (leaving just space for the swap partition). Then make an extended partition 'n', 'e', containing the rest of the space. Inside the extended partition create a logical drive 'n', 'l' that fills the extended partition. You can also set the first partition to be bootable 'a' '1'. Once all these changes are made, they can be written to the disk 'w'.

Then format the primary partition of the new disk, and the swap partition:
Code:
mkfs -t ext3 /dev/sdb1
mkswap /dev/sdb5
Now change the run level down to one (or reboot to maintenance mode):
Code:
telinit 1
The new main partition needs to be mounted somewhere, eg /mnt/new/, so that the file system can be copied over:
Code:
mkdir /mnt/new
mount /dev/sdb1 /mnt/new
cp -ax / /mnt/new
(the 'a' preserves the file attributes, and the 'x' prevents recursion across to the new file system)

Then install grub to the new system:
Code:
grub-install --root-directory=/mnt/new /dev/sdb
In older systems, no more needs to be done. In newer systems, disks are typically located using the UUID instead. The UUIDs can be obtained using blkid
Code:
blkid /dev/sdb1 /dev/sdb5
Update the UUIDs in /mnt/new/etc/fstab. Now the old disk can be switched out and the new one put in its place.

However, grub2 will be unable to boot normally, because it is still using the old UUID. To get around this, first do a minimal boot from the grub command line:
Code:
linux (hd0,1)/vmlinuz root=/dev/sda1
initrd (hd0,1)/initrd.img
boot
The grub configuration can now be updated:
Code:
grub-mkconfig -o /boot/grub/grub.cfg
There may also be an issue with errors from the initramfs resume (again because of mismatched UUIDs); update the UUID in /etc/initramfs-tools/conf.d/resume, and then regenerate the initramfs:
Code:
update-initramfs -u
Posted in Uncategorized
Views 257 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 03:17 AM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration