Migration from One Server to Another

  • I am dumb.. I didnt realise I could use GUI apps like Gparted using the VNC option... Can I fix this mess with Gparted?

    Tricky question... Just a quick visualisation of what has gone wrong:

    I assume some partition setup like this:

    Partition 1 | Partition 2 | Partition 3

    XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZ


    The above partitions are the ones, which the partition table defines. X Y and Z are the drive spaces that are occupied with data from the filesystem (fat, ext4, btrfs, ZFS, etc.).


    By using parted to just shrink the partition, we got the following scenario:

    Partition 1 | Partition 2 | Partition 3 | Unused disk space

    XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZ


    Now the Partition 3 won't work, as part of the data for the filesystem is outside of the partition boundary.


    Currently there is no data lost, just the partition table is messed up. This can be fixed by manually adjusting the partition table or using "parted rescue" or testdisk.

    But there might be the case, that fsck or something else has corrupted the data (like creating a new partition and formatting it in the unused disk space). This is the bad case, where you probably need some data recovery tool (like photorec).


    The correct way of shrinking is the following (which GParted does automatically):

    Partition 1 | Partition 2 | Partition 3

    XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZ


    Shrink the filesystem down first (resize2fs does this):

    Partition 1 | Partition 2 | Partition 3

    XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZ


    Then change the partition table to actually shrink the partition:

    Partition 1 | Partition 2 | Partition 3 | Unused disk space

    XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZ


    Enlarging a partition works the other way around. First the partition table is modified:

    Partition 1 | Partition 2 | Partition 3

    XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZ


    And now the filesystem is resized (again with resize2fs) according to the partition boundaries:

    Partition 1 | Partition 2 | Partition 3

    XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZ



    Why is this necessary to know?
    Because the resize2fs part changes actual data on the disk. As GParted does this automatically, it might overwrite something (i don't know, maybe it's smart), as usually the partition you expand is in a working state.


    Therefore I would suggest the following steps:

    1. Backup your partition tables before and after every attempt to fix something, as you maybe want to revert back at some point to an old partition table: https://www.cyberciti.biz/faq/…able-with-sfdisk-command/
    2. Try "parted rescue" or testdisk to automatically recreate a working partition table
    3. Try gparted
    4. Recover your files the hard way using photorec or similar tools


    Edit: Just for your information: You can use X11 tunneling to use GUIs via SSH: https://wiki.archlinux.org/index.php/OpenSSH#X11_forwarding

  • ThomasChr  7c00 I am really grateful for your time and patience - THANK YOU


    I have managed to resize Old server partition back to original size AND repair the damaged inodes etc with GRML liveCD and e2fsck.ext4

    https://linuxexpresso.wordpres…xt4-superblock-in-ubuntu/ helped


    I can now boot my OLD server.


    Now if I want to try again the DD route (as I am finding the re-install tedious and forget some of the tricks used when I built server in 1st place)...


    (1) Resize with Gparted (NOT parted) and test the Old server boots and still works fine with smaller partition size. Let's say I make it 100GB


    (2) Login to Old server and copy with DD to new server @ IP aaa.bbb.ccc.ddd


    dd if=/dev/sda bs=1Gb count=101 status=progress | ssh root@aaa.bbb.ccc.ddd dd of=/dev/sda bs=1Gb count=101


    (3) Resize New Server /dev/sda3 to max size using Gparted


    (4) My domain points to old IP so fix that to new IP.


    Anything else? I think it best I confirm BEFORE i do..... ;)

  • I'm glad to hear, that you've got your data back8).


    First of all, I would suggest to backup/download the most important files. If something else goes wrong and the rescue attempt fails (shit happens...), you at least can setup a new server manually.


    Then check your partition setup. We want the unused space at the end of the disk. If we shrink a partition that is not the last, we also need to move other partitions to the front, so that the empty space is at the end (so the dd copy only leaves out unused disk space instead of some partitions).


    Now you can shrink the partition with gparted. I would suggest to shrink it, so that only 1Gb of free space remains on the partitions (so the system can boot and run without a problem). This reduces the amount of data that needs to be transferred via dd.


    now continue with your list of steps. The most important thing is to check, that the shrinking worked fine. Everything else doesn't risk your data, as you only read from the old servers harddisk.


    And probably you won't reach your new server after booting, as it probably has a static IP, which is the one from the old server. So don't worry;), if you don't reach it via SSH, you can still fix it via VNC. Just look up where your OS stores the IP address configuration.


    Sincerely

    7c00

  • Thanks AGAIN guys. The resize worked fine with Gparted overnight. And I can access system fine. Rebooted both into Rescue system and running DD now.


    FYI, 1Gb isnt accepted as block size neither is 1G (it stopped after about 5M). Basically all large sizes gave incomplete reads.


    dd if=/dev/sda bs=1M count=200000 status=progress | ssh root@aaa.bbb.ccc.ddd dd of=/dev/sda bs=1M count=200000


    Seems to be working (I've got about 180GB to copy).


    ThomasChr so where do I get these badges then? :) Seriously though, I'll be happy if it works!


    EDIT: Barfs, with several possibilities... Incomplete reads (can be over-ridden) but more importantly stops after about 3GB (first 2 partitions, isnt doing the important one!)


    UPDATE: dd if=/dev/sda bs=2M status=progress | ssh root@1aaa.bbb.ccc.ddd dd of=/dev/sda bs=2M Seems to get past the 3GB mark, but without count I will just have to manually stop it once its done comfortably past 180GB....


    That SHOULD work???

  • Nope, complete failure... If I boot new server into Gparted it reports corrupted GPT table...


    I have wasted more than enough time on this.. (surprised Netcup dont provide a migration guide themselves)


    I'm rebuilding new server and copy across odd files as needed. It's tedious but it *will* work