0

(how) Is it possible to move a linux system to another disk in a virtual machine? For a client I have to support a VMware ESXi virtual machine that has been set up somewhat clumsily: the whole virtual disk contains only one partition (plus the "BIOS boot") for system and data.

Now, I would like to create a new small virtual disk and want to move the BIOS boot and a small system partition to that new disk thus using the old big disk only for the data (home). How can I get the system to start from that new disk/partition?

Maybe it would be more easy to create a new big disk, move all the data to that disk and then shrink the old big disk, but we don't have enough disk space to duplicate the data. Furthermore it's a life system and we need to minimize the downtime.

Is that possible?

The current disk layout is as follows

Disk /dev/sda: 1,6 TiB, 1717986918400 bytes, 3355443200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 8DA273A9-ACAB-46F4-8DEE-0C90499286F9

Device     Start        End    Sectors  Size Type
/dev/sda1   2048       4095       2048    1M BIOS boot
/dev/sda2   4096 3355441151 3355437056  1,6T Linux filesystem

The desired new layout should be as follows

Disk /dev/sda: 1,6 TiB, 1717986918400 bytes, 3355443200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 8DA273A9-ACAB-46F4-8DEE-0C90499286F9

Device     Start        End    Sectors  Size Type
/dev/sda1   2048 3355441151 3355439104  2048 Linux filesystem


Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 2E74BFF1-AEBC-6F47-B887-BE1FCEE5EA60

Device     Start      End  Sectors Size Type
/dev/sdb1   2048     4095     2048   1M BIOS boot
/dev/sdb2   4096 41943006 41938911  20G Linux filesystem

What do I have to do to get the system started from sdb? Maybe there is a more elegant solution for this problem? Maybe an option is to leave the BIOS boot partition on the big disk and only move the system to the smaller partition, but in my eyes this looks ugly.

0

The "BIOS boot" partition is essentially just a place for embedding the core image of a legacy BIOS-style GRUB on GPT-partitioned disks. For a MBR disk, the area after the MBR but before the beginning of the first partition would be used for this purpose instead - but on a GPT-partitioned disk, this area holds the structures of the GPT partition table so it cannot be used.

The initial part of GRUB embedded in the MBR will have the LBA block number of the first block of the GRUB core image hardcoded into it at GRUB installation time; the MBR code will load that block, which will include a list of subsequent blocks to load. At this phase, GRUB will not understand any kind of partitioning: it works exclusively on LBA block numbers at this point, so it does not matter for GRUB whether the core image is in a BIOS boot partition or in an unallocated space between the classic MBR and the beginning of the first partition.

If the smaller disk is GPT-partitioned, you'd have to create another BIOS boot partition on it, to ensure there is a well-defined space to which the GRUB core image can be written. The next step would typically be to modify /boot/grub/device.map file to assign the GRUB disk identifier hda to the new smaller disk, as the BIOS-style boot disk selection usually happens by manipulating the BIOS disk identification order so that the first BIOS HDD device number (0x80) maps to the disk the system is booting from.

At boot time, the BIOS-style GRUB maps the BIOS HDD device numbers to names, so that 0x80 => hda, 0x81 => hdb and so on. So your device.map file must anticipate what your BIOS disk numbering order will be when you're booting from the new disk.

Once that is done, you can install GRUB in the MBR + the BIOS boot partition of the new disk. Depending on Linux distribution, the core image will include some selection of essential GRUB modules, and a path prefix (e.g. hd0,msdos1/boot/grub) that identifies the filesystem/partition and pathname to load the GRUB main configuration file (and if necessary, additional GRUB modules) from. The grub-install command should handle all that automatically for you.

Finally, you'll need to update /etc/default/grub to match your new layout and recreate the GRUB configuration file to update the GRUB disk name references in it. Debian and related distributions have update-grub for that; other distributions will have grub-mkconfig or some distribution-specific tools.

  • Thank you very much for the detailed explanation. – Paul Sommer Mar 5 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.