Copy-rootfs: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(No difference)
|
Latest revision as of 03:44, 20 January 2016
This is a command to copy the current (running, live) root filesystem to another (attached) disk. Last tested with Debian 8.1 (Jessie) and all works fine.
- add the new disk (e.g. /dev/sdb) to the system
- set up a linux partition and make it active (enable boot flag)
- format the target filesystem to ext2
- mount the target filesystem to /mnt
- copy files across..
(cd / ; tar -cf - . --one-file-system) | (cd /mnt ; tar xvfpB - ) cp -r /dev/* /mnt/dev/
- find out new disk UUID (ls /dev/disk/by-uuid/....)
- update UUID's in fstab and grub.cfg
sed -i 's/old-uuid/new-uuid/g' /mnt/etc/fstab sed -i 's/old-uuid/new-uuid/g' /mnt/boot/grub/grub.cfg
- install grub
grub-install --root-directory=/mnt /dev/sdb
- shutdown system
- detach old disk
- move new disk to Primary Master (IDE)
- boot system with new disk
- reinstall grub one final time:
update-grub grub-install /dev/sda -or- dpkg-reconfigure grub-pc
TROUBLESHOOTING
- at the blue grub menu, enter the edit mode (press 'e') and change the UUID=xxxx to /dev/sda1
- if you've forgotten to update the uuid, you can still boot the disk
grub rescue> grub rescue> set prefix=(hd0,1)/boot/grub grub rescue> insmod ext2 grub rescue> set root=(hd0,1)
(find out the kernel image name using ls, ls (hd0,1)/, ls (hd0,1)/boot)
grub rescue> linux /boot/vmlinuz-3.16.0-4-686-pae root=UUID=xxxxx ro recovery nomodeset grub rescue> initrd /boot/initrd.img-3.16.0-4-686-pae grub rescue> boot
(instead of the UUID you can also use 'root=/dev/sda1') (you can also remove 'ro recovery nomodeset')