Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Is there a Gentoo raw / Virtual Machine Image Creation Tool?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
adrelanos
n00b
n00b


Joined: 11 Dec 2014
Posts: 6

PostPosted: Sat Jan 10, 2015 4:09 pm    Post subject: Is there a Gentoo raw / Virtual Machine Image Creation Tool? Reply with quote

Is there a tool to create bootable raw images?

Or is there a tool to create bootable virtual machine images?

All in an automated / scripted fashion.

Similar to these Debian / Ubuntu specific tools:
- grml-debootstrap: http://grml.org/grml-debootstrap
- vmdebootstrap: http://liw.fi/vmdebootstrap
- Kameleon: http://wiki-oar.imag.fr/index.php/Kameleon
- VMBuilder: https://launchpad.net/vmbuilder
_________________
...
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3136

PostPosted: Sat Jan 10, 2015 8:08 pm    Post subject: Reply with quote

I've been looking for a similar tool.

To make me happy it must:
- be easy and quick to run
- provide up-to-date system
- not require agent inside OS to be assembled.

So far I'm fairly happy about portage for the hard part - building up-to-date image - even though I'm still figuring it out.
Anyway, here what I have right now:
build directory contains:
etc/portage/ target/

etc/portage is there to let me have different keywords, use and mask atributes than host.

Components necessary to create a new system image:
- baselayout (USE build - important)
- stuff you want to have installed
optionaly:
- kernel (copy from host's /boot - or prepare dedicated kernel image on host. I'm not going to recompile it inside VM anyway :) )

to build new system use:
emerge -bk --config-root=./ --root=target/ baselayout <desired stuff>
Notice: the created system will not be self-sufficient. There will be no portage, no headers, etc. Just a single-purposed dummy.

Anyway, after emerge completes, it would be handy to tune configs a bit. E.g. creating users, changing passwords or enabling serial console. Probably sed or patch would do the trick.

Now, there are many ways to stuff that system into a VM. Raw image is one (reasonably easy to prepare), PXE is another (even easier, once you have all servers set up), qemu also supports direct boot, never tried it but there might not be any need to stuff it into an image at all. This being said, i'm gonna yet figure out what way of booting will be the most convenient. Qcow is interesting as it provides snapshots and live migration (also migration to a file, so we can dump the whole running VM to disk)
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Sat Jan 10, 2015 11:07 pm    Post subject: Reply with quote

You don't need distro-specific hacks to do this with Gentoo - just create the VM disk image, partition and mount it using qemu-nbd, then do a normal chroot install. (You could also try a non-chroot install from the host using the $ROOT variable, but that's undocumented.)
Back to top
View user's profile Send private message
adrelanos
n00b
n00b


Joined: 11 Dec 2014
Posts: 6

PostPosted: Sat Jan 10, 2015 11:29 pm    Post subject: Reply with quote

Ant P. wrote:
You don't need distro-specific hacks to do this with Gentoo

You don't need tools to do this for other distributions either. At least not for Debian centric ones. Those tools are in essence just scripts do only things that one could manually do as well.

Ant P. wrote:
just create the VM disk image, partition and mount it using qemu-nbd, then do a normal chroot install.

Partitioning and making the image grub bootable is non-trivial - at least for me. With the apparent absence of instructions for doing so, and without spending at least a few hours looking how other tools are doing and and replicating this, I couldn't do it. Hence, I asked if there is any existing automation for it. Also to prevent duplicating work.
_________________
...
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3136

PostPosted: Sun Jan 11, 2015 10:00 am    Post subject: Reply with quote

Ah, so that's the problem for you. Ok, here's a tip on turning filesystems into images:

Quote:
dd if=/dev/zero of=vmimage.img bs=50M count=200 # create roughly 10 GB empty file using 50MB buffer
mkfs.ext2 vmimage.img # format file with ext2, you can use any other format if you like it more
mkdir vmimage
mount -o loop vmimage.img vmimage # mount image so you can access and modify it's content
rsync -av <path to root directory of the filesystem you want inside the image> vmimage
umount vmimage


the bold line is the tricky part ;) the rest goes pretty much the same way handbook describes it. Including installing grub. You launch it the very same way you would on any other device\

I wonder if anyone has a better way to build the system from outside. I mean, better than mine, described earlier, with emerge (which is not good enough mostly because it's not yet complete)
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54237
Location: 56N 3W

PostPosted: Sun Jan 11, 2015 11:42 am    Post subject: Reply with quote

szatox,

You can even chroot into the image to install your boot loader so it just works when you boot the VM.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Progman3K
l33t
l33t


Joined: 03 Jan 2004
Posts: 773

PostPosted: Thu Jan 29, 2015 8:53 pm    Post subject: Reply with quote

NeddySeagoon wrote:
szatox,

You can even chroot into the image to install your boot loader so it just works when you boot the VM.


How would you do that if you were hosting an arm VM inside an amd64 host?

Thanks for your insight
Back to top
View user's profile Send private message
KaZeR
Apprentice
Apprentice


Joined: 04 Feb 2004
Posts: 291
Location: Au fond, à droite.

PostPosted: Thu Jan 29, 2015 11:15 pm    Post subject: Reply with quote

Have a look at this script to build an image :
https://github.com/pgrandin/builder/blob/master/build_ami.sh

and this one for an arm example ( raspberry pi )
https://github.com/pgrandin/builder/blob/master/build_pi.sh

(the last one builds a stage 4 but it's easy to adapt it to build a disk image instead )
_________________
Foo.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54237
Location: 56N 3W

PostPosted: Fri Jan 30, 2015 9:29 pm    Post subject: Reply with quote

Progman3K,

You can't use grub on ARM, its full of Intel 16 bit (real mode) and 32 bit asm.

However qemu can emulate ARM, so you can do any steps that need to be done inside the VM in qemu.
It will be slow but it still works.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Progman3K
l33t
l33t


Joined: 03 Jan 2004
Posts: 773

PostPosted: Thu Feb 05, 2015 9:36 pm    Post subject: Reply with quote

NeddySeagoon wrote:
Progman3K,

You can't use grub on ARM, its full of Intel 16 bit (real mode) and 32 bit asm.

However qemu can emulate ARM, so you can do any steps that need to be done inside the VM in qemu.
It will be slow but it still works.


Thanks for saving me the time trying to get it to compile for arm, NeddySeagoon!

I am trying to get a qemu (aqemu) arm vm operational but I'm having problems getting the networking to function. :-(
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3136

PostPosted: Fri Feb 06, 2015 8:13 pm    Post subject: Reply with quote

What about easy mode AKA user mode?
Don't provide any params regarding networking, it should use some defaults allowing your guest OS access the internet the same way any application could. You won't be able to access guest os from your pc, but this often is a minor problem.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum