Any way to convert my iohyve VMs from a MBR to a GPT partition table?

Status
Not open for further replies.

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
Is there any way to convert an MBR partition table to a GPT partition table within an iohyve created VM? Or would it just be easier to start over? Normally on a bare metal machine I would boot into gparted and make the modifications, however I don't think this will work with iohyve.
 
Last edited by a moderator:

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Create a blank disk with GPT partitions in the correct sizes, than dd(1) over the partitions' contents?

My only idea.
Patrick
 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
Create a blank disk with GPT partitions in the correct sizes, than dd(1) over the partitions' contents?

My only idea.
Patrick

What would be the best tool to do this? On bare metal I would use gparted. Would this work with iohyve?
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
I assume iohyve creates zvols for the emulated disk devices. So roughly:

1. use zfs list -t all to find the sizes
2. use the UI or zfs create -V to create an additional zvol
3. find out where the devices for your zvols live, guess: /dev/zvol/xyz...
4. use gpart on the new one to set up the partitions
5. use dd with appropriate offsets and counts to copy over the contents
6. tell iohvve to use the new disk image

HTH,
Patrick
 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
Hey I'm really sorry to keep bothering you. I upgraded since I've first written this post to FreeNAS 11. Haven't had any problems with the old linux jails booting and running.

With the iohyve linux install this is what I found:

Code:
[kevdog@freenas /dev/zvol/tank/iohyve/ubuntu]$ sudo fdisk disk0
Password:
******* Working on device disk0 *******
parameters extracted from in-core disklabel are:
cylinders=3916 heads=255 sectors/track=63 (16065 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=3916 heads=255 sectors/track=63 (16065 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 131 (0x83),(Linux native)
	start 2048, size 58718208 (28671 Meg), flag 80 (active)
	beg: cyl 0/ head 32/ sector 33;
	end: cyl 1023/ head 254/ sector 63
The data for partition 2 is:
sysid 5 (0x05),(Extended DOS)
	start 58722302, size 4190210 (2046 Meg), flag 0
	beg: cyl 1023/ head 254/ sector 63;
	end: cyl 1023/ head 254/ sector 63
The data for partition 3 is:
<UNUSED>
The data for partition 4 is:
<UNUSED>


I believe this information to be correct.
Partition 1 - Is the entire system
Partion 2 - Is the swap partition

As an experiment however I went ahead and created a new zvol and actually created a new Ubuntu jail with the FreeNAS gui. (Side note -- much easier than the old Iohyve way of doing things with the new ability to use VNC viewer).
Anyway during the installation I created three partitions - vda1, vda2, vda3.
vda1 -> /boot/efi
vda2 -> /
vda3 -> swap

My problem is when actually examining the zvol created for this installation. It shows just one partition

Code:
[kevdog@freenas /dev/zvol/tank/iohyve/Ubuntu-FreeNAS]$ sudo fdisk disk0
******* Working on device disk0 *******
parameters extracted from in-core disklabel are:
cylinders=52216 heads=255 sectors/track=63 (16065 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=52216 heads=255 sectors/track=63 (16065 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 238 (0xee),(EFI GPT)
	start 1, size 838860799 (409599 Meg), flag 0
	beg: cyl 0/ head 0/ sector 1;
	end: cyl 1023/ head 254/ sector 63
The data for partition 2 is:
<UNUSED>
The data for partition 3 is:
<UNUSED>
The data for partition 4 is:
<UNUSED>
[kevdog@freenas /dev/zvol/tank/iohyve/Ubuntu-FreeNAS]$


I'm very confused. In fact it doesn't make a lot of sense to me. I would have thought I would be shown in this instance three partitions. I was hoping to take my old root partition and dd to the new root partition, however that doesn't seem possible.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
fdisk is for MBR partitioned disks, only. And probably legacy/deprecated by now. You need to use gpart.

Patrick
 

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506
Is there any way to convert an MBR partition table to a GPT partition table within an iohyve created VM? Or would it just be easier to start over? Normally on a bare metal machine I would boot into gparted and make the modifications, however I don't think this will work with iohyve.
An MBR partition table is, depending on how you count, either one or two 512-byte blocks long. A standard GPT table is 34 blocks, at both the beginning and end of the disk. Unless that space is unused, something is going to have to be moved.

The safe way to do that, particularly with VMs, is to back up at a file level, create a new disk image, partition it as desired, mount it, then restore files.

I've had mixed success with gparted, although mostly with partition resizing on questionable filesystems like NTFS.

As Patrick says, fdisk is essentially obsolete. It only understands MBR, and will be confused by the PMBR that is present on GPT disks. gpart is much more capable, and understands lots of partitioning types including both MBR and GPT.
 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
This seems much harder than it needs to be:

Code:
1. Create zvol:
#sudo zfs create -V 400G tank/iohyve/Ubuntu-FreeNAS/disk1

2.Partition zvol with gpart
#sudo gpart create -s gpt /dev/zvol/tank/iohyve/Ubuntu-FreeNAS/disk1

gpart: arg0 'zvol/tank/iohyve/Ubuntu-FreeNAS/disk1': Invalid argument
 

KrisBee

Wizard
Joined
Mar 20, 2017
Messages
1,288
This seems much harder than it needs to be:

Code:
1. Create zvol:
#sudo zfs create -V 400G tank/iohyve/Ubuntu-FreeNAS/disk1

2.Partition zvol with gpart
#sudo gpart create -s gpt /dev/zvol/tank/iohyve/Ubuntu-FreeNAS/disk1

gpart: arg0 'zvol/tank/iohyve/Ubuntu-FreeNAS/disk1': Invalid argument

Not really, how would you achieve this on a linux install on a real machine? Something like this, perhaps:

https://askubuntu.com/questions/845...-mbr-drive-to-a-gpt-and-make-ubuntu-boot-from
 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
Not really, how would you achieve this on a linux install on a real machine? Something like this, perhaps:

https://askubuntu.com/questions/845...-mbr-drive-to-a-gpt-and-make-ubuntu-boot-from

Still working on this -- but to answer your question specifically to do this on bare metal, I would do something like boot from CD and then use something like a chroot to change the partition table. In a nutshell, I'd do it something like an Arch Linux installation which uses the same principle. I don't think however this chroot method is valid when working with jails however in this case is it?
 

KrisBee

Wizard
Joined
Mar 20, 2017
Messages
1,288
My comment was meant to be a rhetorical question, i.e. it's long winded for a FreeNAS VM but that's of similar complexity to having to deal with the same issue on a real machine.
 
Last edited:

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
Thanks for followup.

I'm still receiving similar error:

Code:
1. Create zvol:
#sudo zfs create -V 400G tank/iohyve/Ubuntu-FreeNAS/disk1

2. Hack mentioned above
#zfs set volmode=geom tank/iohyve/Ubuntu-FreeNAS/disk1

3.Partition zvol with gpart
#sudo gpart create -s gpt /dev/zvol/tank/iohyve/Ubuntu-FreeNAS/disk1

gpart: arg0 'zvol/tank/iohyve/Ubuntu-FreeNAS/disk1': Invalid argument

Ive tried also the following (from within the /dev/zvol/tank/iohyve/Ubuntu-FreeNAS directory)

#sudo gpart create -s gpt tank/iohyve/Ubuntu-FreeNAS/disk1
#sudo gpart create -s gpt disk1

All iterations get gpart: arg0 'zvol/tank/iohyve/Ubuntu-FreeNAS/disk1': Invalid argument


 
Status
Not open for further replies.
Top