程序员

Vagrant启动自己编译的内核

2018-04-09  本文已影响0人  独孤求真007

上一篇为Guest Ubuntu编译内核我们为Vagrant的Guest Ubuntu编译了内核,现在我们要在Vagrant的Guest OS中安装,并启动自己的内核。

root@ubuntu:~/vagrant# vagrant up
root@ubuntu:~/vagrant# vagrant ssh

# Guest Ubuntu shell
vagrant@ubuntu-xenial:~$ cd /vagrant/obj/
vagrant@ubuntu-xenial:~/vagrant/obj/$  ls -lah  --time-style='+'  *.deb
-rw-r--r-- 1 vagrant vagrant  11M  linux-headers-4.16.0+_4.16.0+-1_amd64.deb
-rw-r--r-- 1 vagrant vagrant  50M  linux-image-4.16.0+_4.16.0+-1_amd64.deb
-rw-r--r-- 1 vagrant vagrant 490M  linux-image-4.16.0+-dbg_4.16.0+-1_amd64.deb
-rw-r--r-- 1 vagrant vagrant 967K  linux-libc-dev_4.16.0+-1_amd64.deb

我们现在只需要安装linux-image和linux-headers,

vagrant@ubuntu-xenial:~/vagrant/obj/$  sudo dpkg -i  ./linux-image*.deb 
vagrant@ubuntu-xenial:~/vagrant/obj/$  sudo dpkg -i  ./linux-headers*.deb 

装好以后,就可以重新启动新的内核了,到Host Ubuntu的Shell中:

root@ubuntu:~/vagrant# vagrant reload

重启之后,再进入Guest Ubuntu验证内核版本:

root@ubuntu:~/vagrant# vagrant ssh
vagrant@ubuntu-xenial:~$  uname -r
4.16.0+
vagrant@ubuntu-xenial:~$  ls /vagrant

可以看到已经是新的内核了,但是共享目录/vagrant是空的,这是因为新的内核中还没有安装VirtualBox Guest Additions,首先我们要在Host中验证VirtualBox的版本号:

root@ubuntu:~/vagrant#  vboxmanage --version
5.1.34_Ubuntur121010

然后到这里下载相同版本的Guest Additions,我的版本是5.1.34,在Guest Ubuntu中,下载并安装:

vagrant@ubuntu-xenial:~$ wget http://download.virtualbox.org/virtualbox/5.1.34/VBoxGuestAdditions_5.1.34.iso
vagrant@ubuntu-xenial:~$ sudo mount -o loop ./VBoxGuestAdditions_5.1.34.iso /mnt/
vagrant@ubuntu-xenial:~$ sudo /mnt/VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.34 Guest Additions for Linux...........
VirtualBox Guest Additions installer
This system appears to have a version of the VirtualBox Guest Additions
already installed.  If it is part of the operating system and kept up-to-date,
there is most likely no need to replace it.  If it is not up-to-date, you
should get a notification when you start the system.  If you wish to replace
it with this version, please do not continue with this installation now, but
instead remove the current version first, following the instructions for the
operating system.

If your system simply has the remains of a version of the Additions you could
not remove you should probably continue now, and these will be removed during
installation.

Do you wish to continue? [yes or no]
yes
Copying additional installer modules ...
Installing additional modules ...
vboxadd.sh: Starting the VirtualBox Guest Additions.

Could not find the X.Org or XFree86 Window System, skipping.

安装完成以后,重启Guest Ubuntu,然后看到Mounting shared folders...不报错,就说明共享目录可以访问了。

root@ubuntu:~/vagrant# vagrant reload
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /root/vagrant
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
root@ubuntu:~/vagrant# vagrant ssh

下一篇介绍如何用kgdb调试这个内核。

上一篇下一篇

猜你喜欢

热点阅读