VMX type KIWI builds and swap partitions

279 views
Skip to first unread message

Rob Sutherland

unread,
Apr 4, 2012, 3:05:27 PM4/4/12
to kiwi
My apologies if I'm missing something obvious but there doesn't seem
to be a vmx analogue of the <oem-swap> and <oem-swapsize> tags for vmx
images. I've tried all sorts of things and have read the XML schema
carefully but I'd really like an LVM swap file for my ovf images.

Thanks in advance,

Rob

Marcus Schäfer

unread,
Apr 5, 2012, 5:20:55 AM4/5/12
to kiwi-...@googlegroups.com
Hi Rob,

I'm not sure if I got the question right but imho it seems obvious
to me that no oem type specific settings exists for the vmx image
type. The main difference between oem and vmx is that an oem can
apply such changes like, repartition system and add swap on first
boot of the system. The vmx was designed to be a simple virtual
disk which boots up as it is.

Maybe you consider to create an oem instead of a vmx e.g

<type image="oem" filesystem="ext3" boot="oemboot/suse-12.1">
<oemconfig>
<oem-swapsize>2048</oem-swapsize>
</oemconfig>
</type>

The result is the same raw disk as with a vmx but the first boot
code will resize the disk to fit the real geometry and will also
create a swap space of 2G

Hope that helps ?

Regards,
Marcus
--
Public Key available
gpg --keyserver gpg-keyserver.de --recv-keys 0xCCE3C6A2
-------------------------------------------------------
Marcus Schäfer (Res. & Dev.) SUSE LINUX Products GmbH
Tel: 0911-740 53 0 Maxfeldstrasse 5
FAX: 0911-740 53 479 D-90409 Nürnberg
GF: Jeff Hawn,Jennifer Guild, Felix Imendörffer
HRB: 21284 (AG Nürnberg) Germany
http://www.suse.de
-------------------------------------------------------

Rob Sutherland

unread,
Apr 5, 2012, 9:12:12 AM4/5/12
to kiwi
Marcus,

Actually, we already make oem images using Kiwi (with swap, of
course). These images are intended for certain target hardware. We're
exploring the possibility of virtualizing the product, though, and I
wanted VM images with swap. Is there no way that the vmx first boot
code can rearrange the LVM partition to create a swap partition?

Thanks,

Rob

Marcus Schäfer

unread,
Apr 5, 2012, 9:49:21 AM4/5/12
to kiwi-...@googlegroups.com
Rob,

> Actually, we already make oem images using Kiwi (with swap, of
> course). These images are intended for certain target hardware. We're
> exploring the possibility of virtualizing the product, though, and I
> wanted VM images with swap.

ok got that but you also can use oem images on VM systems

> Is there no way that the vmx first boot
> code can rearrange the LVM partition to create a swap partition?

there is a way but it involves some image postprocessing

1) build the vmx as usual

2) increase the size of the .raw disk file according to the
amount of swap space you want: e.g file.raw is 1G and you
want 500M swap

dd if=/dev/zero of=file.raw bs=1 count=1 seek=1500M conv=notrunc

3) update the partition table

losetup /dev/loop0 file.raw
fdisk /dev/loop0
d
2
n
p
2
<return>
<return>
t
2
8e
w

4) activate the LVM (I assume volume group name is kiwiVG)

kpartx -a /dev/loop0
vgchange -ay kiwiVG

5) resize physical volumes

pvresize /dev/mapper/loop0p2

6) create swap volume

lvcreate -l +100%FREE -n LVSwap kiwiVG

7) create swap signature

mkswap /dev/mapper/kiwiVG-LVSwap

8) update the fstab entry

/dev/kiwiVG/LVSwap swap swap defaults 0 0

==> kiwi's vmx code overwrites the fstab on first boot. You
have to update the fstab in a first boot script

9) clean up

vgchange -an kiwiVG
kpartx -d /dev/loop0
losetup -d /dev/loop0

Rob Sutherland

unread,
Apr 5, 2012, 10:27:54 AM4/5/12
to kiwi
Marcus,

Thanks for the suggestion!

Q: Couldn't the image resizing etc be avoided if a dummy LVM partition
to be used for swap? i.e. alter fstab and use mkswap in the vms first
boot script.

Marcus Schäfer

unread,
Apr 5, 2012, 10:33:43 AM4/5/12
to kiwi-...@googlegroups.com
Hi,

> Q: Couldn't the image resizing etc be avoided if a dummy LVM partition
> to be used for swap? i.e. alter fstab and use mkswap in the vms first
> boot script.

Ah clever :) yes this would also work

Rob Sutherland

unread,
Apr 5, 2012, 3:13:12 PM4/5/12
to kiwi


On Apr 5, 10:33 am, Marcus Schäfer <m...@suse.de> wrote:
> Hi,
>
> > Q: Couldn't the image resizing etc be avoided if a dummy LVM partition
> > to be used for swap? i.e. alter fstab and use mkswap in the vms first
> > boot script.
>
> Ah clever :) yes this would also work

Just to update you, Marcus: it *DOES* work!

Thanks for your help,

Rob

Peter Simms

unread,
Dec 4, 2018, 12:14:50 PM12/4/18
to kiwi
Sorry for replying to an old post, however I am experiencing the same issue

We need a ova image but the size of the drive extended, and in doing that the swap doesn't seem to get created

Can you talk through the steps you did to resolve the swap issues?

David Cassany

unread,
Dec 10, 2018, 11:34:10 AM12/10/18
to kiwi-...@googlegroups.com
Hi Peter,

Sorry for late answer, there have been a couple of bank holidays here in Spain
last week.

Well, this is quite old post what are you referring to, it rained quite a lot
since 2012. I'd say it would be better to just start from scratch again.

First question I have is which kiwi version are you using and which distro you
aim to build? Just to make sure we are on the same page.

Anyway, if you are using recent kiwi versions I'd say you have aASny couple of
options:

1-> Build a vmx image include and some unpartitioned area to the disk. The
swap partition then could be created manually after booting or it could be
created using some kind of firstboot service.

In order to create a disk with unpartitioned area consider:

<type image="vmx"....>
<size unpartitioned="2" unit="G">10</size>
</type>

Whith it the resulting disk will be a 10G disk without partitioning the last
2G.

Then creating the swap partition could be done with a oneshot firstboot
service that executes some script to create the swap.


2-> Build a oem image configured with the desired swap space and after build
resize the image to the desired disk size. Then booting it as a VM will result
on resizing partitions at boot time according to the given configuration.

Consider something like

<type image="oem"....>
<oemconfig>
<oem-swap>true</oem-swap>
<oem-swapsize>1024</oem-swapsize>
</oemconfig>
</type>

Build it with

kiwi-ng system build --description <imageprojectfolder> --target-dir
<destinationdir>

Then after the build try running:

kiwi-ng image resize --target-dir <destinationdir> --size 40g

and the result will be an image with a disk of 40GB that will resize at boot
time to expand all over the disk using 1024MB for swap.

I hope it helps,
David
signature.asc
Reply all
Reply to author
Forward
0 new messages