Copy an existing installation to another disk with different partition sizes

Hello,

  • OpenMandriva Lx version: OpenMandriva Lx 3.0 Kernel 4.11.3-desktop-2omv

  • Desktop environment (KDE, LXQT…): KDE

  • Description of the issue (screenshots if relevant): After moving the system to the new disk, as described below, the boot process doesn’t start (Black screen).
    What did I forgot?

Situation

  • Boot from usb stick (/dev/sdb).

  • Mount the source disk as /dev/sdc.

  • Mount the destination disk as /dev/sdd.

  • Check the partition configuration of the source disk.

    parted /dev/sdc

    GNU Parted 3.2
    Using /dev/sdc
    Welcome to GNU Parted! Type ‘help’ to view a list of commands.
    (parted) unit GB
    (parted) print
    Model: Integral Courier (scsi)
    Disk /dev/sdc: 63.3GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:

      Number Start   End     Size    Type     File system     Flags 
      1      0.00GB  8.39GB  8.39GB  primary  linux-swap(v1) 
      2      8.39GB  61.9GB  53.5GB  primary  ext4 
    

    (parted) quit

  • Create the partition configuration of the destination disk /dev/sdd

    # **parted /dev/sdd**
    

    GNU Parted 3.2
    Using /dev/sdd
    Welcome to GNU Parted! Type ‘help’ to view a list of commands.
    (parted) print
    Model: USB DISK 2.0 (scsi)
    Disk /dev/sdd: 32.0GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:

      Number Start   End     Size    Type    File system  Flags 
      1      1049kB  2149MB  2147MB  primary              lvm 
    

    (parted) mklabel msdos
    Warning: The existing disk label on /dev/sdd will be destroyed and all data on this disk will be
    lost. Do you want to continue?
    Yes/No? Yes
    (parted) mkpart
    Partition type? primary/extended? primary
    File system type? [ext2]?
    Start? 1
    End? 8000
    (parted) print
    Model: USB DISK 2.0 (scsi)
    Disk /dev/sdd: 32028MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:

      Number Start  End    Size   Type    File system Flags 
      1      1.05MB 8000MB 7999MB primary ext2        lba 
    

    (parted) mkpart
    Partition type? primary/extended? primary
    File system type? [ext2]?
    Start? 8000
    End? 32000
    (parted) print
    Model: USB DISK 2.0 (scsi)
    Disk /dev/sdd: 32028MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:

      Number Start  End     Size    Type    File system Flags 
      1      1.05MB 8000MB  7999MB  primary ext2        lba 
      2      8000MB 32000MB 24001MB primary ext2        lba 
    

    (parted) quit
    Information: You may need to update /etc/fstab.

  • Format the new /dev/sdd1 partition as a swap partition using mkswap.
    Format the new /dev/sdd2 partition with the ext4 file system using mkfs.

    # mkswap /dev/sdd1
    mkswap: /dev/sdd1: warning: wiping old LVM2_member signature.
    Setting up swapspace version 1, size = 7.5 GiB (7998533632 bytes) 
    no label, UUID=924f3a08-29d8-4799-b130-76660a68c954
    # mkfs.ext4 /dev/sdd2
    mke2fs 1.43.4 (31-Jan-2017) 
    Creating filesystem with 5859584 4k blocks and 1466368 inodes 
    Filesystem UUID: 6c480049-6b6f-484c-93e0-9e3e2ea7d064 
    Superblock backups stored on blocks:  
         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 
    
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (32768 blocks): done 
    Writing superblocks and filesystem accounting information: done
    
    #
    
  • Verify the results, by printing the partition table of the /dev/sdd disk.

    parted /dev/sdd

    GNU Parted 3.2
    Using /dev/sdd
    Welcome to GNU Parted! Type ‘help’ to view a list of commands.
    (parted) print
    Model: USB DISK 2.0 (scsi)
    Disk /dev/sdd: 32.0GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:

      Number Start  End    Size   Type    File system     Flags 
      1      1049kB 8000MB 7999MB primary linux-swap(v1) 
      2      8000MB 32.0GB 24.0GB primary ext4 
    

    (parted) quit

  • Mount the /dev/sdc2 and /dev/sdd2 disk partitions:

    /dev/sdc2 as /media/5f6bfba0-401a-48f6-a76d-2c160a751d93
    /dev/sdd2 as /media/4cab8a7e-3c7f-43f7-a58c-45870642bc1f

  • Copy the content of /dev/sdc2 to /dev/sdd2

    rsync -avzr /media/5f6bfba0-401a-48f6-a76d-2c160a751d93/ /media/4cab8a7e-3c7f-43f7-a58c-45870642bc1f/

  • Update the bootloader configuration for Grub:

    • The new partition is mounted as: /media/4cab8a7e-3c7f-43f7-a58c-45870642bc1f (See above)
  • Make some in-memory file-systems available under the new root:

      # mount --rbind /dev /media/4cab8a7e-3c7f-43f7-a58c-45870642bc1f/dev
      # mount --bind /proc /media/4cab8a7e-3c7f-43f7-a58c-45870642bc1f/proc
      # mount --bind /sys /media/4cab8a7e-3c7f-43f7-a58c-45870642bc1f/sys
      # mount --bind /run /media/4cab8a7e-3c7f-43f7-a58c-45870642bc1f/run
    
  • Get a command line inside your system:

      # chroot /media/4cab8a7e-3c7f-43f7-a58c-45870642bc1f
    
  • Update the grub environment “/usr/sbin/update-grub2”

      # update-grub2`
    
  • Exit the chroot and unmount all the stuff.

      # exit
    
  • Update /etc/fstab to reflect the new partition locations. The UUID can be found in the above format step.

      # /etc/fstab: static file system information.
      #
      # Use 'blkid' to print the universally unique identifier for a device; this may
      # be used with UUID= as a more robust way to name devices that works even if
      # disks are added and removed. See fstab(5).
      #
      # <file system>                           <mount point>  <type>  <options>  <dump>  <pass>
    UUID=924f3a08-29d8-4799-b130-76660a68c954 swap           swap    defaults,noatime 0       0
    UUID=6c480049-6b6f-484c-93e0-9e3e2ea7d064 /              ext4    defaults,noatime 0       1
    
  • Reboot with the newly created disk

After ‘update-grub2’ does ‘grub2-install /dev/sdx’ need to be run?

Edit: ‘update-grub2’ only updates grub2 menu (/boot/grub2/grub.cfg) doesn’t install the boot loader. Probably need to run ‘grub2-install /dev/sdx’. That would be run while you are chrooted in to new system right after you run ‘update-grub2’.

Hello Ben79,

Thanks for the tip, it solved the problem.

    Regards,
    Albert
1 Like

Excellent news.

@vhelmont please mark Ben’s answer as solution.

1 Like

Hello mandian,

How do I mark an answer as a solution?

Regards,
Albert

Each post in a thread has a set of small icon near Reply button. Just select the post which solves your issues and click on the button as show in the image below.

2 Likes

All right, everyone, thanks for everything. Time to close this one.