Answer the question
In order to leave comments, you need to log in
What is the correct way to migrate a virtual machine to a smaller disk?
Good day.
I have such a situation, I need to transfer the system from a larger disk to a smaller one, and the structure is like this. Disk 100GB, boot partition fat32, the rest in LVM - no more than 20GB is used in the system, you need to transfer it to a disk with 50GB while maintaining working condition, you can put out the machine for several hours.
For tests, I created a virtual machine and try it on it. Is everything correct and is there a way to simplify all this?
I see the general algorithm for transferring to a new disk as follows
: 1. Connect the new disk /dev/sdb
2. Boot from LiveCD (sysresccd)
3. Partition the new disk using fdisk as the target (sfdisk -d does not roll, because the new disk is smaller)
( Why it was not possible to create / dev / sdb5 with the beginning 501760, fdisk showed the first sector 501758, I did not understand)
fdisk -l /dev/sda
Disk /dev/sda: 10 GiB
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 501758 20969471 10233857 5 Extended
/dev/sda5 501760 20969471 6 10238 LVM
fdisk -l /dev/sdb
Disk /dev/sdb: 8 GiB
Device Boot Start End Blocks Id System
/dev/sdb1 * 2048 499711 248832 83 Linux
/dev/sdb2 501758 16777215 8137729 5 Extended
/dev/sdb5 503808 16773215 81 Linux LVM
4. Copy the boot partition
dd if=/dev/sda1 of=/dev/sdb1
5. The next question is how to copy LVM correctly
Add a new disk to the VG, reduce the current VG group so that it can be transferred to the new one, transfer the data with the pvmove command, and remove the old disk from the VG (can be disabled)
6. Again, install the bootloader in the LiveCD Mount the
LVM root partition, create symlinks to the directories proc, dev, sys we will make chroot and we will actually install grub
You can reboot and use it.
All these operations take a lot of time and cause some inconvenience, how can this be simplified? I tried to transfer Clonezilla device to device, but it turned out to be impossible.
I read that you can remove the dd image, fill it with zeros, and make a backup. But you need external storage or a flash drive, in short, all this is bad. I can write a step-by-step how to in the sandbox, do you need it? And is it possible to do this somehow in live mode without putting out the car? Thanks for answers.
UPD: Note. Maybe it will be clearer why this is done. After creating a virtual machine through Xen, VirtualBox, Hyper-V, WmWare, we specify the maximum size of the HDD, which is either reserved for the full amount, or takes the actual size and expands gradually - this disk can usually be increased when the machine is turned off, but not reduced. And inside, read the question above, already boot partition and lvm. By compressing the LVM partition inside the virtual machine, the external disk will not change - that is why, in order to migrate to a smaller disk, you need to do all of the above.
Answer the question
In order to leave comments, you need to log in
If you don't have 100500 files created every second, you may well be fine with regular rsync.
Boot from LiveCD, create the desired partition structure, create file systems on the partitions, synchronize files with the first machine, turn off the first, turn on the second. Everything will work perfectly in general if it is possible to transfer synchronized partitions to read-only mode on the first machine.
I don’t know what virtualization system you use, but in the one I use (vmware vsphere)
you can do the following, use thin provisioning, assign the task of migrating the VM to another storage, indicating that you don’t need to take up all the space at once. this allows you to place a VM with a 500 Gb disk on a 100 Gb disk, provided that less than 100 GB is currently occupied (used).
Lvm has native tools for volume reduction. The reduce keyword. You can make 1 volume on several disks, you can make several volumes per disk. The group does not need to be touched at all. Bacup data before operation is mandatory. For scill, you can play with snapshots. Google and search for a link to articles on LVM from a smartphone is not convenient. The only difficulty is to understand the command format, there are not enough examples. lvresize --size 80G /dev/vg0/foo.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question