1

I want to replace my system drive with a larger one and would prefer not to reinstall the main OS (OpenSUSE) or, even though seldom used, Windows. Installing Windows and Suse would take seemingly forever and I'd rather not have to rebuild my preferences and custom settings for the Suse install.

The other bootable systems are ephemeral for testing, so their loss would be insignificant. My system uses an MBR disk in BIOS boot with GRUB2 in the MBR of the first disk for the boot loader. All the GRUB stanzas use LABEL= rather than UUID= so that won't be a problem. Likewise, my /etc/fstab uses LABEL=, so changing, or duplicated UUIDs are not an issue. I believe I can use Clonzilla Live to migrate the Windows partition. I'm keeping that partition the same size and in the same place. If I understand Clonezilla correctly the UUID of that clone will be the same, so Windows shouldn't know anything has happened, or at least not enough to care.

My problems, or worries are that:

  1. With GRUB installed on the MBR I cannot, I think, directly clone it as the partitions are changing
  2. The Suse install uses BTRFS and I want to make its root partition larger
  3. I also want to increase the size of the Suse /boot partition (had a few rare events where more space was needed on /boot)
  4. I haven't found a Live USB distro which has partclone installed and drivers for BTRFS filesystems
  5. I only want to take one shot at it

My understanding of partclone is that the system has to be off-line for it to clone a BTRFS system. I know Clonezilla Live has to be as it's a bootable system anyway. Data loss is not an issue since all data is on other disks uninvolved in the OS migration.

I have found a tool, btrfs-clone which I am hoping will simplify the process, and increase my chance for success. I've already tested it, and it will clone the live system. Keeping the system fairly quiet in the process is, of course a good idea. Again, the UUID of the partitions is immaterial to everything except possibly Windows, which only sees its own partition anyway.

Short version of the question is what steps need to be done to the new disk, and partitions, to clone the existing system onto the new disk and have it bootable when I swap the cables?

As an extra note, there is an existing question which seems to be just about right. My concern is that using rsync on the BTRFS system will not get all the snapshots and the system won't be "as it was" on the new system. It is possible that merely using btrfs-clone in place of rsync resolves all issues. As it is my main (only) desktop system, I'd like to get it right in one shot.

7
  • Given that you have several different types of filesystem on the disk, the simplest way is probably to use clonezilla to clone the entire disk to the new, larger disk, and then used gparted to move and resize the partitions. Actually, you could do it all with just gparted live, and not bother with clonezilla.
    – cas
    Commented Apr 28, 2021 at 7:26
  • @cas I've not used Gparted-live in a long time. Usually I just use gparted in Knoppix. Last I knew, which could easily have changed in the time since last used, Gparted-Live didn't handle BTRFS. In addition to cloning the partitions, however, I also need to copy the boot code in the MBR. Will Gparted grab that was well?
    – Chindraba
    Commented Apr 28, 2021 at 8:00
  • 1. According to the changelog, gparted live has included btrfs-tools since v0.7.0-2 (2010). 2. re: MBR - my suggestion was to clone the entire disk (which includes the MBR) to the new disk (e.g. with dd or ddrescue or even cat), then use the gparted app to resize and move the partitions. 3. any live cd that has the gparted app and the other tools you need can be used if you don't want to use gparted live. If you have (or can create) a knoppix iso with gparted and the rest, that will be fine.
    – cas
    Commented Apr 28, 2021 at 8:11
  • Oh, dd on a 500 GB disk and then the resizing is likely to take longer than just reinstalling both systems.
    – Chindraba
    Commented Apr 28, 2021 at 8:13
  • you could do it entirely with command line tools for changing the partition table and resizing partitions and filesystems, but using the GUI gparted app will make it much, much easier. it will perform all the changes in the right order without you having to manually track what's been done, and what needs to be done next, and then manually do it yourself without making any mistakes. Highly recommended, doing this stuff manually is a tedious PITA with many opportunities for human error.
    – cas
    Commented Apr 28, 2021 at 8:14

1 Answer 1

1

Since I needed to get this done I had to use a process which I was reasonably sure would work, even if not the ideal I had hoped for. Until someone has a better answer, for later users, I'll answer with what I did do, successfully.

The initial problem statement included the information that BIOS boot was in use and the disk was partitioned in the DOS, or MBR, format. As such, the possible complications, if any, using UEFI boot or GPT partitioning are not considered here.

Note: almost every important process requires root privileges. This can either be done by logging in as root (not an option on some distributions), switching to the root user with sudo su, or prepending every command with sudo. The presumption here is that everything is being done as root, using one of the first two options. The commands are all written as if executed from roots account, not the user's account.

Needed for this are:

  • The existing system in a running state
  • A second disk, HDD or SSD, accessible to the system (internally or by USB)
  • A bootable version, CD or USB, of Clonezilla Live
  • A bootable disc of USB drive with either a live distro, or the ability to enter a recovery mode.

The last item is best if it's a version of the system being cloned with either the same, or a very close, kernel. Which ever tool is chosen the ability to mount and chroot into the new system is needed. No other tools are needed from the disc or USB drive.

1. Verify the disk names involved.

Run the mount | grep '/dev/sd'. This will show all currently mounted partitions. In the case of a BTRFS file system, as given in the question, there is likely to be several different mount points listed for the partition which has on / type btrfs given. All such partitions can be ignored as the process of cloning the root will clone them as well. If other partitions are mounted from a different physical disk, and that disk will remain after the migration, they can be skipped as well.

Also needed, and harder to find, is the partition on which Windows is installed. If, as is common, Windows was installed first, the Windows partition is very likely to be /dev/sda1, especially if the Linux system is also on a partition of /dev/sda.

Common partitions to look for are /home and /boot.

2. Create the needed partitions on the new disk

If the new disk is able to be connected by USB that makes things a bit easier.

  1. With the disk not connected run the command lsblk
  2. Connect the disk and run lsblk a second time
  3. The device in the second listing not it the first is the device to use

Caution: If you do a reboot at any time in the process, and have more than one USB disk attached, it is quite possible for the device name to change. Check each time to verify the correct device name before proceeding or you will probably loose data somewhere.

The tool to use is a personal choice, and depends on your preferences. Some options typically available in most systems could include parted, gparted, cfdisk, fdisk, and gdisk.

After the partitions are created, run partprobe to be sure the system "knows" about the new partitions. Some tools will notify the kernel that it needs to, others won't. Doing it yourself ensures that it did get done.

Verify that the partitions are made, and seen by the kernel with the lsblk command again.

3. Create the Linux file systems on new partitions

The BTRFS root partition can be made with the mkfs.btrfs command, and mkfs.ext4 could be used to make the /boot and /home partitions. For convenience sake, if the new disk has a swap partition, the new swap partition can be prepared with the mkswap command.

4. Clean up the BTRFS root partition to reduce the time spent on the clone operation

List the snapshots of the system, with snapper list and remove as many as possible, with snapper delete <number>. Rollback options will be quite limited as a result. If the system is being cloned it's probably in a stable state and rollbacks to prior conditions should not be needed.

Run the balance operation on the BTRFS filesystem. A full balance can be very time consuming! Limiting it to only balancing chunks which are utilized less than some percentage can accomplish a lot, while spending a lot less time waiting. Depending on how dirty the system is 50% might be the limit of your patience. My system is balanced often, so I can use a higher percentage (90%) and spend a tolerable amount of time. The -dusage option limits the balance operation to data chuncks utilized less than the given percentage.

For my system the command was btrfs balance start -dusage=90 /

5. Create mount points and mount the new partitions for cloning

The root partition is obvious in all cases. Also needed might be the /home and /bootpartitions.

6. Clone the non-BTRFS filesystems

The rsync command is a better choice than a simple cp as it can be used to preserve the ownerships and permissions of the copied files. It's also possible to have rsync restart the process if it gets interrupted.

An example would be rsync --archive -hh --hard-links --partial --info=stats1 --info=progress2 --modify-window=1 --one-file-system /boot/ /boot2/

7. Clone the root, BTRFS, partion

The btrfs-clone program was the tool I decided to trust. The documentation suggests that the best results (in terms of space used) are from the "generation" strategy, so that's the one I choose.

The command, simple as it is, to do that would be btrfs-clone --strategy generation / /mnt

Expect the operation to take a while.

8. Modify the "new" system

There may be changes you need to make to the /etc/fstab file to accommodate changes to the partitions you want mounted in the new system. The entire system does not have to remain exactly the same. Label names, UUIDs and even device names can be changed during the process of migration.

In the case of openSUSE there is another possible cause of trouble. The system setup includes a file used during GRUB configuration to hard code some kernel parameters in the grub.cfg menu. The file is /etc/default/grub and may contain a line similar to:

GRUB_CMDLINE_LINUX_DEFAULT="splash=silent resume=/dev/disk/by-label/Linux_swap quiet mitigations=auto"

Of concern is the section resume=..... This points to the swap partition used for suspend-to-disk operations. If the line is not commented out, has the resume=... in it, and the new disk has a different label, UUID or device name than the current disk, it has to be changed to reflect what the new version is. This will become important in a later step.

9. Use Clonezilla to clone the Windows partition.

I'm not an expert on Clonezilla. The option seems to be to use Clonezilla live on a bootable CD. Other than the langauge/keyboard options, the steps I followed were:

    device-device  work directly from a disk or partition to a disk or partition
    Expert  Expert mode: choose your own options
    part_to_local_part  local_partition_to_local_partition
Select the source partition
Select the target partition
    Options menu changes
        add  Reinstall grub on target hard disk
        drop Automatically adjust geometry ...
        drop sfdisk uses CHS ...
        drop Resize filesystem ...
        add  No GUI ...
        add  Remove NTFS volume dirty flag ...
    -sfck   Skip checking/repairing source file system
    -p choose  Choose reboot/shutdown/etc when everything is finished

After that completes the Windows partition has been cloned and GRUB might be added to the MBR.

10. Replace the old disk with the new disk

This is the point to get physical. Uninstall the old disk and install the new disk. If both disks stay installed, or connected, after this the system will probably get confused. As an alternative, if both disks are to be used, with the new one as the boot disk, the old, no-longer needed partitions need to be changed or reformatted, to give them new UUIDs and Labels.

11. Rebuild the boot process

From my experiment, the boot loader added to the MBR, if any, by Clonezilla is incomplete. The initrd of the old system may not be compatible with the new system, especially on openSUSE due to the /etc/default/grub setting above. Lastly, the grub.cfg file might have elements which are not compatible with the new system. Correcting all three is a straight forward process, if the preceding steps have been accomplished successfully.

Boot the live disc, and if needed select the option for recovery. If using a live CD, such as Ubuntu, it's possible to go all the way into the live system and then open a terminal. Using the terminal on a live system will also require the use of sudo su to have root privileges. Recovery mode on most systems is in root already.

The following presumes a disk of /dev/sdx with the following partitions:

/dev/sdx1  Windows
/dev/sdx2  `/boot`
/dev/sdx3  `/`
/dev/sdx4  swap

The partition numbers, and even the device name, could be different on your system, and the following steps need to be modified to match the situation

The steps

  1. Make a directory to work in, commonly /mnt, which may already exist
  2. Mount the new system's root partition:
    mount /dev/sdx3 /mnt
  1. Mount the new system's boot partition:
    mount /dev/sdx2 /mnt/boot
  1. Connect the existing system's processes to the new one
    for item in proc sys dev run; do
        mount /$item --rbind /mnt/$item
    done
  1. Switch into the mounted system
    chroot /mnt
  1. Mount any other partitions the new system normally mounts
    mount -a
  1. Create the new initrd
    mkinitrd
  1. Install GRUB to the MRB
    grub2-install /dev/sdx
  1. Generate new grub.cfg
    grub2-mkconfig -o /boot/grub2/grub.cfg
  1. Exit chroot and reboot
    exit
    reboot
  1. Remove the disk of USB drive with the live or recovery system on it.
  2. Check that the new disk can boot into both the Window and Linux systems.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .