How to move Root and Home Partition to a new Disk (for opensuse 12.1 on btrfs file system)

Forword:

This how-to comes in handy if e.g. your current disk is getting to small or if you simply, as I want to change from a hard disk to a solid state disk.
Since I haven’t found a how-to on the web for 12.1 on btrfs file system and when having serveral disks, I thought I’ll write one while performing the tasks. I hope it is helpful to the community.
For this how-to you will need admin rights on the system.

Overview:

Prepare Target Disk
Copy almost everything to from source to target partition (exceptions see below)
Edit target fstab
Edit target grub
Optional: create grub boot memory stick
Reboot

Legend:

text in italic is code
red text has to be substituted with our settings
bold text is used for emphasis

In Detail:

[ol]
[li]Start Gparted[/li][LIST=1]
[li]note down existing partitions of source disk [/li][li]make them the same (sequence, name) on target disk [/li][li]execute actions (Attention ALL existing Data on Target Disk are lost at this step) [/li][li]Quit Gparted and log-off user and log-in again. (now newly created partitions are mounted and visible your computer) [/li][/ol]

[li]Create folders /run, /media /home /proc /sys on /dev/”target partition” as root but leave them empty[/li][ol]
[li] mkdir /mount_point_of_”target partition”/proc [/li][li]re-run same command for the above mentioned folders substitute the last part e.g. /proc by /run, /media etc. [/li][/ol]

[li]When using btrfs you will have a /. snapshots folder, this should be emptied out before doing the copy operation. Empty /.snapshots by using snapper command line interface (If you don’t want to empty it then create ./snapshot on the ”target partition” using the mkdir command (c.f. 2.1.) and remove the ./snapshot from cp command listed in ( 4.3.)[/li][ol]
[li]snapper list (this lists all snapshots) [/li][li] snapper delete 1 2 3 etc. (all no. form snapper list command) [/li][/ol]

[li]Run cp -av /bin /”target partition”/etc to copy all files from the root EXCEPT /proc /sys and mounted devices e.g. /windows (if you have a windows mounted here)[/li][ol]
[li]Look at your / directory and take all the folders names into the next command[/li][LIST=1]
[ul]
[LIST]
[LIST]
[li][except /proc /sys and mounted devices e.g. (/Data /windows /media )] [/li][/ul]

[/ol]

[/LIST]

[/LIST]

[li]check again if .snapshot is empty before doing the next step. If not repeate step 3.2. [/li][li]cp -av /.config /.snapshots /bin/ /dev/ /etc/ /lib/ /lib64 /mnt /opt/ /root/ /sbin/ /selinux /srv/ /tmp /usr/ /var/ /mount_point_of_target_partition/ [/li][/LIST]

[li]Copy /home and /boot to corresponding“target partitions”[/li][ol]
[li]Copy /home to /mount_point_of_corresponding_target_partion/home [/li][li]e.g. cp -av /home/* /media/newhome/ [/li][li]change owner for /newhome (recursivly) from root to (username of user) and group users. [/li] chown -R “username”:users /”mountpoint for /home on target_partition”
[li]e.g. cp -av /boot/* /media/”newboot” [/li][/ol]

[li]Edit fstab (/etc/fstab)[/li][ol]
[li]Backup old Fstab [/li][li]Change fstab e.g. /dev/sdd3(old partition) to /dev/sdc3(new partition in my case) for / , swap, home[/li] OLD: /dev/sdd3 / btrfs defaults 1 1
NEW: /dev/sdc3 / btrfs defaults 1 1
OLD: /dev/sdd2 swap swap defaults 0 0
NEW: /dev/sdc2 swap swap defaults 0 0
If you are also moving /home then change it in fstab accordingly after copying content of home to /home target partition location
OLD: /dev/sdd4 /home btrfs defaults 1 2
NEW: /dev/sdc4 /home btrfs defaults 1 2
If you have like me the /boot in a seperate partition then don’t forget to also adopt the /boot. If you forget your system will not boot correctly or boot using the original /boot
OLD: /dev/sdd1 /boot ext4 acl,user_xattr 1 2
NEW: /dev/sdc1 /boot ext4 acl,user_xattr 1 2
[/ol]

[li]Edit Grub [/li] Please note: (hd,x,y)/boot/vmlinuz
x == disk number starting at zero
y == partition number starting at zero
[ol]
[li]Get Info from /boot/grub/device.map - mapping of real device to grub device (no changes; here you can get device names and optionally ids, if needed for next step) [/li][li]edit /boot/grub/menu.lst - main configuration for sections[/li] Change following lines from source to target device. In my case b[/b] is source and b[/b] is target.
OLD: gfxmenu i[/i]/message
NEW: gfxmenu i[/i]/message (new gfxmenu location)
OLD: root (hd3,0)
NEW: root (hd2,0) (new root)
OLD:kernel /vmlinuz-3.1.0-1.2-desktop root=/dev/sdd3
NEW: kernel /vmlinuz-3.1.0-1.2-desktop root=/dev/sdc3 (target kernel location please take note that device has to be the same as in new fstab)
OLD: resume=/dev/sdd2 splash=silent quiet showopts vga=0x375
NEW: resume=/dev/sdc2 splash=silent quiet showopts vga=0x375 (new swap location, please take note that device has to be the same as in new fstab)
[li]edit /etc/grub.conf - batch file for grub (boot loader location) substitute all source references with target references [/li][li]OLD: setup --stage2=/boot/grub/stage2 --force-lba i [/i]i[/i] [/li][li]NEW: setup --stage2=/boot/grub/stage2 --force-lba i [/i]i[/i] [/li] (new target for stage2, please note that (hd0) has not changed in my case, this where partition flaged as bootable resides and in the mbr the first part of grub is installed.
[/ol]

[li]Optional: Create grub boot usb stick (to do below from usb boot disk)[/li] For use in steps 9.
[ol]
[li]cd /boot/grub/ [/li][li]dd if=stage1 of=/dev/sdi bs=512 count=1 [/li][li]dd if=stage2 of=/dev/sdi bs=512 seek=1 [/li][li]Reboot system from usb-stick (if needed change boot-settings in BIOS to do so) [/li][/ol]

[li] use grub command-line interface (cli) (to enter press “esc” in boot menu[/li][ol]
[li] We need to tell grub where the grub files are.[/li][LIST=1]
[li]If you know where they are, type something like:[/li]root i[/i] (my new root) c.f…root i[/i] (my old)
else if you have no idea, type:
find /grub/stage1
take the info from the output into root command with the correct parameters:
[/ol]

[li]setup on hd0, that is in MBR of the first HD, or substitute if you want it the MBR on e.g your target drive (precondition: it has to me flagged as bootable by e.g. using fdisk command or gparted.[/li][ol]
[li]Install on hd0:[/li] setup i[/i]
reboot
[/ol]

[li]After Reboot you should be able to boot your new target drive installation. [/li][/LIST]

[/LIST]