Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
boot same kernel as is on host OS using KVM
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
Wizumwalt
Guru
Guru


Joined: 20 Aug 2006
Posts: 547

PostPosted: Fri May 21, 2010 12:47 am    Post subject: boot same kernel as is on host OS using KVM Reply with quote

I've got a few questions about how to use KVM. I've got my host OS talking to the guest OS, but I haven't gotten it to work the other way around yet. But the issue I'd like to figure out is how to load the same custom kernel I'm running on my host OS for the guest OS instead of the livecd which I load above, it's loaded w/ stuff I don't want, too big, and it's way to slow to load.

Here's my cmd to start kvm.
Code:

kvm -net nic,macaddr=52:54:00:12:34:56 -net tap,ifname=qtap0,script=no,downscript=no -hda ./gentoo-i386.img -cdrom ./livecd-amd64-installer-2008.0.iso -boot d -m 512


I've been using the gentoo kvm page on the wiki to get this far. Any help much appreciated.
Back to top
View user's profile Send private message
Sadako
Advocate
Advocate


Joined: 05 Aug 2004
Posts: 3792
Location: sleeping in the bathtub

PostPosted: Fri May 21, 2010 2:13 am    Post subject: Reply with quote

So, what have you been doing, booting the livecd via kvm and chroot'ing to gentoo-i386.img?

With qemu you have two options for booting kernels, one is to do everything within the vm as an a real host, ie compile the kernel within the vm, install it to /boot (within the vm) and install a bootloader to the mbr of your virtual disk (ie grub within the vm).

The other rather nice option specific to qemu is the '-kernel' option, where you specify a kernel image residing on the host system to boot, a bzImage which you'd typically copy to /boot.
The only problem with this is modules, if you're using a bzImage you've compiled on the host you'll need to copy the modules to /lib/modules within the guest, but other than that it's fantastic.
_________________
"You have to invite me in"
Back to top
View user's profile Send private message
Wizumwalt
Guru
Guru


Joined: 20 Aug 2006
Posts: 547

PostPosted: Sat May 22, 2010 6:19 pm    Post subject: Reply with quote

I got it to boot the image on my hard drive which is what I wanted, but I'd just like for someone to check over this line to make sure I'm doing this right. When I booted my guest OS, it was checking my hard disk and seemed to do a lot of disk access that I didn't think it should be doing. I thought this would run as an "read-only" to my hard drive. It's mounted all my partitions as rw and run the same init scripts as my host OS.

I'm just trying to get the exact same kernel as is running on my host OS to run on the guest OS so that I can do kernel mod development and not risk anything on my host OS. Am I running this in a parallel way that is dangerous to my host OS?
Code:

kvm -net nic,macaddr=52:54:00:12:34:56 -net tap,ifname=qtap0,script=no,downscript=no -kernel /boot/kernel-2.6.32-gentoo-r7 -hda /dev/sda -boot c -m 512
Back to top
View user's profile Send private message
Sadako
Advocate
Advocate


Joined: 05 Aug 2004
Posts: 3792
Location: sleeping in the bathtub

PostPosted: Sun May 23, 2010 1:52 pm    Post subject: Reply with quote

That looks very dangerous to me, it might be okay if one of the two mounts are read-only, but otherwise I'd say it's almost as dangerous as running fsck on a mounted filesystem...

You were running from a disk image earlier, why stop now?
_________________
"You have to invite me in"
Back to top
View user's profile Send private message
Wizumwalt
Guru
Guru


Joined: 20 Aug 2006
Posts: 547

PostPosted: Sun May 23, 2010 5:29 pm    Post subject: Reply with quote

Hopeless wrote:

You were running from a disk image earlier, why stop now?


Because I don't know how to do it. If you know, please help w/ the command line so I can see what you mean.
Back to top
View user's profile Send private message
Sadako
Advocate
Advocate


Joined: 05 Aug 2004
Posts: 3792
Location: sleeping in the bathtub

PostPosted: Sun May 23, 2010 6:09 pm    Post subject: Reply with quote

Given what you've posted, this is all you should need;
Code:
kvm -net nic,macaddr=52:54:00:12:34:56 -net tap,ifname=qtap0,script=no,downscript=no -kernel /boot/kernel-2.6.32-gentoo-r7 -hda ./gentoo-i386.img -boot c -m 512

_________________
"You have to invite me in"
Back to top
View user's profile Send private message
Wizumwalt
Guru
Guru


Joined: 20 Aug 2006
Posts: 547

PostPosted: Wed May 26, 2010 12:32 am    Post subject: Reply with quote

Yeah, I've tried that very same line. Didn't work. I get these results.
Code:

...
VFS: Cannot open root device "<NULL>" or unknown-block(8,3)
Please append a correct "root=" boot option; here are the available partitions:
0800      10485760 sda driver:sd
0b00      1048575  sr0 driver:sr
kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(8,3)
Pid: 1, comm: swapper Not tainted 2.6.31-gentoo-r6 #2
Call Trace:
[<ffffffffff815e611>] panic+0xa0/0x14b
...


Then tried this line thinking I need a root= line like the error says, and even give it the cd image ...
Code:

kvm -net nic,macaddr=52:54:00:12:34:56 -net tap,ifname=qtap0,script=no,downscript=no -kernel /boot/kernel-2.6.31-gentoo-r6 -hda ./gentoo-i386.img root=/dev/sda -boot c -m 512 -cdrom ./livecd-amd64-installer-2008.0.iso

And I get the same results as above.
Back to top
View user's profile Send private message
Sadako
Advocate
Advocate


Joined: 05 Aug 2004
Posts: 3792
Location: sleeping in the bathtub

PostPosted: Wed May 26, 2010 4:12 pm    Post subject: Reply with quote

Try this;
Code:
kvm -net nic,macaddr=52:54:00:12:34:56 -net tap,ifname=qtap0,script=no,downscript=no -kernel /boot/kernel-2.6.31-gentoo-r6 -append root=/dev/sda -hda ./gentoo-i386.img -boot c -m 512

_________________
"You have to invite me in"
Back to top
View user's profile Send private message
Wizumwalt
Guru
Guru


Joined: 20 Aug 2006
Posts: 547

PostPosted: Wed May 26, 2010 4:30 pm    Post subject: Reply with quote

So I tried ...
Code:

ic,macaddr=52:54:00:12:34:56 -net tap,ifname=qtap0,script=no,downscript=no -kernel /boot/kernel-2.6.32-gentoo-r7 -append "root=/dev/sda" -hda ./gentoo-i386.img -boot c -m 512


And got some only slightly different results, instead of "Cannot open root device", I get "No filesystem could mount root".
Code:

...
List of all partitions:
0800   10485760 sda driver: sd
0b00    1048575 sr0 driver: sr
No filesystem could mount root, tried: ext3 ext2 vfat mdsod iso9660
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(8,0)
Pid: 1, comm: swapper Not tainted 2.6.32-gentoo-r7 #2
Call Trace
[<ffffffff81545eba>] panic+0xa0/0x152
...
Back to top
View user's profile Send private message
Sadako
Advocate
Advocate


Joined: 05 Aug 2004
Posts: 3792
Location: sleeping in the bathtub

PostPosted: Wed May 26, 2010 5:03 pm    Post subject: Reply with quote

What filesystem did you create on gentoo-i386.img when you formatted via the livecd?

I'm presuming you formatted the entire thing rather than partitioning?
_________________
"You have to invite me in"
Back to top
View user's profile Send private message
Wizumwalt
Guru
Guru


Joined: 20 Aug 2006
Posts: 547

PostPosted: Wed May 26, 2010 5:53 pm    Post subject: Reply with quote

I followed this howto ... http://en.gentoo-wiki.com/wiki/KVM

I'm a bit confused on your question. I used this command from the mentioned page to create a virtual disk image, gentoo-i386.img
Code:

qemu-img create -f qcow2 gentoo-i386.img 10G

But didn't format a livecd or see where in that page it mentioned to. I just downloaded the livecd image.
Could I be having problems because I'm trying to use a recent kernel (2.6.32) with an older livecd (livecd-amd64-installer-2008.0.iso).
I thought by giving the -kernel option, it would boot the kernel on the host os and override the kernel in the livecd.
Back to top
View user's profile Send private message
bbgermany
Veteran
Veteran


Joined: 21 Feb 2005
Posts: 1844
Location: Oranienburg/Germany

PostPosted: Wed May 26, 2010 5:57 pm    Post subject: Reply with quote

No, it would override the kernel on the system you want to boot inside your qcow image. You should mount the image and create a gentoo installation inside the image (basic stage3 should be fine). then boot with the following command. it should work then:

Code:

kvm -net nic,macaddr=52:54:00:12:34:56 -net tap,ifname=qtap0,script=no,downscript=no -kernel /boot/kernel-2.6.31-gentoo-r6 -append root=/dev/sda -hda ./gentoo-i386.img -boot c -m 512


it will boot the host kernel and changes into the system inside the ".img" file then.

bb
_________________
Desktop: Ryzen 5 5600G, 32GB, 2TB, RX7600
Notebook: Dell XPS 13 9370, 16GB, 1TB
Server #1: Ryzen 5 Pro 4650G, 64GB, 16.5TB
Server #2: Ryzen 4800H, 32GB, 22TB
Back to top
View user's profile Send private message
Wizumwalt
Guru
Guru


Joined: 20 Aug 2006
Posts: 547

PostPosted: Wed May 26, 2010 6:56 pm    Post subject: Reply with quote

bbgermany wrote:
No, it would override the kernel on the system you want to boot inside your qcow image.

yeah, sorry, I mispoke, that's what I meant.

And if I understood you correctly ... you mean just create a directory with a complete gentoo installation where I'd chroot into and finish off as a stage 3, just like in the docs? Then step out of that, mount it, and run kvm as you stated? Then where on that command line does it know where the mounted installation is?
Back to top
View user's profile Send private message
bbgermany
Veteran
Veteran


Joined: 21 Feb 2005
Posts: 1844
Location: Oranienburg/Germany

PostPosted: Wed May 26, 2010 7:03 pm    Post subject: Reply with quote

Yeah, kinda. You have created a qcow image. You need to run losetup and format it with a filesystem. Then you mount the image and extract a stage3 archive where you have mounted it. Then set a passwort for root, edit /etc/fstab for your root device (/dev/sda) and dont forget to set the right networkdevice. You will need a driver for this (virtio_net is doing fine for me, since i justed tested it right now). Then unmount the file and remove the loop device. Now you should be able to boot the system and start configuring your virtual gentoo.

if you need further help (especially the needed commands for this setup) just lemme know. Ill post it then.

bb
_________________
Desktop: Ryzen 5 5600G, 32GB, 2TB, RX7600
Notebook: Dell XPS 13 9370, 16GB, 1TB
Server #1: Ryzen 5 Pro 4650G, 64GB, 16.5TB
Server #2: Ryzen 4800H, 32GB, 22TB
Back to top
View user's profile Send private message
Wizumwalt
Guru
Guru


Joined: 20 Aug 2006
Posts: 547

PostPosted: Thu May 27, 2010 1:04 am    Post subject: Reply with quote

bbgermany wrote:

if you need further help (especially the needed commands for this setup) just lemme know. Ill post it then.


I'm definetly running into trouble with this. If you do happen to have those commands available, that would be a big help.
Back to top
View user's profile Send private message
bbgermany
Veteran
Veteran


Joined: 21 Feb 2005
Posts: 1844
Location: Oranienburg/Germany

PostPosted: Thu May 27, 2010 12:06 pm    Post subject: Reply with quote

Hi,

after you created your qcow image:

Code:

losetup /dev/loop0 gentoo-i386.img
mkfs.ext3 /dev/loop0
mount /dev/loop0 /mnt


now get the stage3 and maybe the portage-tree from the internet and continue with the installation doc at chapter 5: http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&chap=5 When you have finished installing up to the kernel, leave the chroot environment unmount the image and remove the loop device with the following commands and try starting with the kvm command from the previous posts:

Code:

umount /dev/loop0
losetup -d /dev/loop0


bb
_________________
Desktop: Ryzen 5 5600G, 32GB, 2TB, RX7600
Notebook: Dell XPS 13 9370, 16GB, 1TB
Server #1: Ryzen 5 Pro 4650G, 64GB, 16.5TB
Server #2: Ryzen 4800H, 32GB, 22TB
Back to top
View user's profile Send private message
Wizumwalt
Guru
Guru


Joined: 20 Aug 2006
Posts: 547

PostPosted: Fri May 28, 2010 1:18 am    Post subject: Reply with quote

After mounting /dev/loop0 to /mnt/loop, I downloaded the stage3-amd64-xxx.tar.bz2 and tried to copy it to /mnt/loop, but I didn't have the space on /mnt/loop to hold it.
Code:

$ sudo cp stage3-amd64-20100514.tar.bz2 /mnt/loop/
cp: writing `/mnt/loop/stage3-amd64-20100514.tar.bz2': No space left on device

Should I have used something like the following w/ the size of both the portage tree and the stage3...bz2?
Code:

$ losetup --sizelimit NNN /dev/loop0

Or am I missing something?
Here's the results of when I made this fs and shows it's size.
Code:

$ sudo mkfs.ext3 /dev/loop0
mke2fs 1.41.9 (22-Aug-2009)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
32 inodes, 256 blocks
12 blocks (4.69%) reserved for the super user
First data block=1
1 block group
8192 blocks per group, 8192 fragments per group
32 inodes per group

Writing inode tables: done                           

Filesystem too small for a journal
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
Back to top
View user's profile Send private message
bbgermany
Veteran
Veteran


Joined: 21 Feb 2005
Posts: 1844
Location: Oranienburg/Germany

PostPosted: Sun May 30, 2010 4:55 pm    Post subject: Reply with quote

Whats "df -h" showing for /mnt/loop?

May be your image is a bit small at all.

bb
_________________
Desktop: Ryzen 5 5600G, 32GB, 2TB, RX7600
Notebook: Dell XPS 13 9370, 16GB, 1TB
Server #1: Ryzen 5 Pro 4650G, 64GB, 16.5TB
Server #2: Ryzen 4800H, 32GB, 22TB
Back to top
View user's profile Send private message
Wizumwalt
Guru
Guru


Joined: 20 Aug 2006
Posts: 547

PostPosted: Thu Oct 07, 2010 9:39 pm    Post subject: Reply with quote

Ok, so I've got my qcow2 image created ...
Code:

qemu-img create -f qcow2 gentoo-i386.img 10G


Then I ran losetup and formated it with a filesystem.
Code:

$ losetup /dev/loop0 ./gentoo-i386.img
$ mkfs.ext3 /dev/loop0
$ losetup -a
/dev/loop0: [0811]:14655814 (/home/winky/kvm/gentoo-i386.img)


This has caused some confusion for me. My understanding is that I can't use a qcow2 image like a normal raw image and mkfs on top of it because the qcow2 structure would be destroyed.

I was able to create a larger loop device by running it with the --sizelimit 10000000 param.

Code:

$ mount /dev/loop0 /mnt/loop
$ mount
...
/dev/loop0 on /mnt/loop type ext2 (rw)
...


I am now able to copy a stage3 file from the gentoo installation of chapt. 5 from the handbook. But I am still confused on what I just did by mkfs.ext3 over a qcow2 formatted loop device.

Can anyone help clarify this here?
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