Re: Constructing a GPT disk image

2021-05-23 Thread Michael van Elst
br...@nmsu.edu (Brook Milligan) writes:

>- create an empty image file by, for example, dd if=3D/dev/zero of=disk.img ...
>- label image file with gpt create disk.img
>- create partitions on image file: gpt add disk.image -t ffs ...
>- configure vnconfig: vnconfig -c vnd0 disk.image
>- find wedges: dkctl vnd0 listwedges
>- create a filesystem: newfs /dev/rdkX
>- mount filesystem: mount /dev/dkX /mnt
>- populate filesystem with stuff
>- unmount filesystem: umount /mnt
>- unconfigure vnconfig: vnconfig -u vnd0
>- copy filesystem to a device: dd if=3Ddisk.img of=3D/dev/rXXX =E2=80=A6

You can also:

- create an empty image file by, for example, dd if=/dev/zero of=disk.img ...
- configure vnconfig: vnconfig -c vnd0 disk.image
- label vnd0 with gpt create vnd0
- create partitions on vnd0: gpt add -t ffs ... vnd0
and continue as above.

vnd also understands sparse files, with e.g.

   dd if=/dev/zero of=disk.img bs=1k count=1 seek=1048575

you would create a 1 GByte file but only allocate and write the last 1 kB.
When vnd0 then writes it allocates blocks as necessary. As long as the disk
image isn't filled completely, that method is more efficient.



Re: Constructing a GPT disk image

2021-05-23 Thread Brook Milligan



> On May 23, 2021, at 3:01 PM, Michael van Elst  wrote:
> 
> br...@nmsu.edu (Brook Milligan) writes:
> 
>> - vnconfig seems to want a file that corresponds to a single partition, =
>> not a partitioned disk.
> 
> vnconfig wants a file that corresponds to a partitioned disk.

Nice to know.  Thanks.

>> Is this a correct procedure?  Is it the best option?  What would be =
>> needed to recognize wedges in a GPT disk image so this could be =
>> simplified (i.e., create the GPT file image and mount the wedges =
>> directly)?
> 
> When you use vnconfig to attach a file as a disk, a GPT is detected
> and wedges are created automatically.

Perfect.  Got it.

So for the record, the procedure is:

- create an empty image file by, for example, dd if=/dev/zero of=disk.img ...

- label image file with gpt create disk.img

- create partitions on image file: gpt add disk.image -t ffs ...

- configure vnconfig: vnconfig -c vnd0 disk.image

- find wedges: dkctl vnd0 listwedges

- create a filesystem: newfs /dev/rdkX

- mount filesystem: mount /dev/dkX /mnt

- populate filesystem with stuff

- unmount filesystem: umount /mnt

- unconfigure vnconfig: vnconfig -u vnd0

- copy filesystem to a device: dd if=disk.img of=/dev/rXXX …

Thanks for your help.

Cheers,
Brook

Re: Constructing a GPT disk image

2021-05-23 Thread Michael van Elst
br...@nmsu.edu (Brook Milligan) writes:

>- vnconfig seems to want a file that corresponds to a single partition, =
>not a partitioned disk.

vnconfig wants a file that corresponds to a partitioned disk.

>Is this a correct procedure?  Is it the best option?  What would be =
>needed to recognize wedges in a GPT disk image so this could be =
>simplified (i.e., create the GPT file image and mount the wedges =
>directly)?

When you use vnconfig to attach a file as a disk, a GPT is detected
and wedges are created automatically.



Constructing a GPT disk image

2021-05-23 Thread Brook Milligan
I would like to construct a GPT disk image file, which I will later dd onto a 
real disk.  I am not sure how to do this, and so would appreciate any guidance. 
 Here is what I have found; please correct me if any of the following is 
incorrect.

- It seems that gpt will nicely label a file as if it were a disk and will add 
partitions as normal.

- I am not sure how to access those partitions, as dkctl complains if given a 
file as the first argument.

- vnconfig seems to want a file that corresponds to a single partition, not a 
partitioned disk.

This suggests one potential strategy:

- create a file for each partition

- mount it with vnconfig and populate the filesystem

- create a file for the disk image

- label the disk image with gpt

- dd each partition into the disk image with an appropriate seek= option to 
place it at the location of the partition

Is this a correct procedure?  Is it the best option?  What would be needed to 
recognize wedges in a GPT disk image so this could be simplified (i.e., create 
the GPT file image and mount the wedges directly)?

Any guidance is greatly appreciated.

Thanks a lot.

Cheers,
Brook