searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

轻量化虚拟化方案crosvm介绍(二):自定义kernel和rootfs

2023-04-26 06:38:57
126
0
 

一,自定义kernel

使用ChromiumOS kernel测试:

1.1 代码下载

$ git clone --depth 1 -b chromeos-5.10 https://chromium.googlesource.com/chromiumos/third_party/kernel

1.2 编译

$ CHROMEOS_KERNEL_FAMILY=termina ./chromeos/scripts/prepareconfig container-vm-x86_64
$ make olddefconfig
$ make -j$(nproc) bzImage
在根目录生成`vmlinux`文件


二,自定义rootfs

制作debian的rootfs,可以用北外源加快制作速度 https://mirrors.bfsu.edu.cn/debian/
$ export CHROOT_PATH=./debian_rootfs
$ truncate -s 20G debian.ext4
$ mkfs.ext4 debian.ext4
$ mkdir -p "${CHROOT_PATH}"
$ sudo mount debian.ext4 "${CHROOT_PATH}"
$ sudo debootstrap stable "${CHROOT_PATH}" https://mirrors.bfsu.edu.cn/debian/
$ sudo chroot "${CHROOT_PATH}"
passwd
echo "tmpfs /tmp tmpfs defaults 0 0" >> /etc/fstab
echo "tmpfs /var/log tmpfs defaults 0 0" >> /etc/fstab
echo "tmpfs /root tmpfs defaults 0 0" >> /etc/fstab
echo "sysfs /sys sysfs defaults 0 0" >> /etc/fstab
echo "proc /proc proc defaults 0 0" >> /etc/fstab
exit
$ sudo umount "${CHROOT_PATH}"
 

三,使用crosvm启动

转到上一章编译好的crosvm镜像
cd crosvm
加载刚才编译好的kernel和rootfs启动:
$ ./target/debug/crosvm run --rwroot ../rootfs/debian.ext4 ../kernel/vmlinux
[2023-04-25T17:27:37.781092048+08:00 INFO  crosvm] crosvm started.
[2023-04-25T17:27:37.781575877+08:00 INFO  crosvm] CLI arguments parsed.
[2023-04-25T17:27:37.783494620+08:00 INFO  crosvm::crosvm::sys::unix] crosvm entering multiprocess mode
[2023-04-25T17:27:37.783806995+08:00 INFO  crosvm::crosvm::sys::unix::device_helpers] Trying to attach block device: ../rootfs/debian.ext4
[2023-04-25T17:27:37.783904916+08:00 INFO  disk] disk size 10737418240,
[2023-04-25T17:27:37.783961853+08:00 INFO  disk] Disk image file is hosted on file system type ef53
[2023-04-25T17:27:37.863979960+08:00 INFO  devices::proxy] begin child proc pcivirtio-block
[2023-04-25T17:27:37.864148849+08:00 INFO  devices::proxy] begin child proc pcivirtio-rng
[2023-04-25T17:27:37.901629786+08:00 INFO  devices::sys::unix::acpi] Listening on acpi_mc_group of acpi_event family
[    0.000000] Linux version 5.10.178-gcaf2a57efe0a (huangqw@DESKTOP-IE5EV1S) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1 SMP PREEMPT Tue Apr 25 11:22:43 CST 2023
[    0.000000] Command line: panic=-1 acpi=noirq console=ttyS0 root=/dev/vda rw
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x020: 'AVX-512 opmask'


....


[  OK  ] Reached target Graphical Interface.
         Starting Update UTMP about System Runlevel Changes...
[  OK  ] Finished Update UTMP about System Runlevel Changes.


Debian GNU/Linux 11 DESKTOP-IE5EV1S ttyS0


DESKTOP-IE5EV1S login: root
Password:
Linux DESKTOP-IE5EV1S 5.10.178-gcaf2a57efe0a #1 SMP PREEMPT Tue Apr 25 11:22:43 CST 2023 x86_64


The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.


Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@DESKTOP-IE5EV1S:~#
root@DESKTOP-IE5EV1S:~# uname -a
Linux DESKTOP-IE5EV1S 5.10.178-gcaf2a57efe0a #1 SMP PREEMPT Tue Apr 25 11:22:43 CST 2023 x86_64 GNU/Linux
root@DESKTOP-IE5EV1S:~#
root@DESKTOP-IE5EV1S:~# cat /proc/version
Linux version 5.10.178-gcaf2a57efe0a (huangqw@DESKTOP-IE5EV1S) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1 SMP PREEMPT Tue Apr 25 11:22:43 CST 2023
0条评论
0 / 1000
h****n
13文章数
0粉丝数
h****n
13 文章 | 0 粉丝
原创

轻量化虚拟化方案crosvm介绍(二):自定义kernel和rootfs

2023-04-26 06:38:57
126
0
 

一,自定义kernel

使用ChromiumOS kernel测试:

1.1 代码下载

$ git clone --depth 1 -b chromeos-5.10 https://chromium.googlesource.com/chromiumos/third_party/kernel

1.2 编译

$ CHROMEOS_KERNEL_FAMILY=termina ./chromeos/scripts/prepareconfig container-vm-x86_64
$ make olddefconfig
$ make -j$(nproc) bzImage
在根目录生成`vmlinux`文件


二,自定义rootfs

制作debian的rootfs,可以用北外源加快制作速度 https://mirrors.bfsu.edu.cn/debian/
$ export CHROOT_PATH=./debian_rootfs
$ truncate -s 20G debian.ext4
$ mkfs.ext4 debian.ext4
$ mkdir -p "${CHROOT_PATH}"
$ sudo mount debian.ext4 "${CHROOT_PATH}"
$ sudo debootstrap stable "${CHROOT_PATH}" https://mirrors.bfsu.edu.cn/debian/
$ sudo chroot "${CHROOT_PATH}"
passwd
echo "tmpfs /tmp tmpfs defaults 0 0" >> /etc/fstab
echo "tmpfs /var/log tmpfs defaults 0 0" >> /etc/fstab
echo "tmpfs /root tmpfs defaults 0 0" >> /etc/fstab
echo "sysfs /sys sysfs defaults 0 0" >> /etc/fstab
echo "proc /proc proc defaults 0 0" >> /etc/fstab
exit
$ sudo umount "${CHROOT_PATH}"
 

三,使用crosvm启动

转到上一章编译好的crosvm镜像
cd crosvm
加载刚才编译好的kernel和rootfs启动:
$ ./target/debug/crosvm run --rwroot ../rootfs/debian.ext4 ../kernel/vmlinux
[2023-04-25T17:27:37.781092048+08:00 INFO  crosvm] crosvm started.
[2023-04-25T17:27:37.781575877+08:00 INFO  crosvm] CLI arguments parsed.
[2023-04-25T17:27:37.783494620+08:00 INFO  crosvm::crosvm::sys::unix] crosvm entering multiprocess mode
[2023-04-25T17:27:37.783806995+08:00 INFO  crosvm::crosvm::sys::unix::device_helpers] Trying to attach block device: ../rootfs/debian.ext4
[2023-04-25T17:27:37.783904916+08:00 INFO  disk] disk size 10737418240,
[2023-04-25T17:27:37.783961853+08:00 INFO  disk] Disk image file is hosted on file system type ef53
[2023-04-25T17:27:37.863979960+08:00 INFO  devices::proxy] begin child proc pcivirtio-block
[2023-04-25T17:27:37.864148849+08:00 INFO  devices::proxy] begin child proc pcivirtio-rng
[2023-04-25T17:27:37.901629786+08:00 INFO  devices::sys::unix::acpi] Listening on acpi_mc_group of acpi_event family
[    0.000000] Linux version 5.10.178-gcaf2a57efe0a (huangqw@DESKTOP-IE5EV1S) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1 SMP PREEMPT Tue Apr 25 11:22:43 CST 2023
[    0.000000] Command line: panic=-1 acpi=noirq console=ttyS0 root=/dev/vda rw
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x020: 'AVX-512 opmask'


....


[  OK  ] Reached target Graphical Interface.
         Starting Update UTMP about System Runlevel Changes...
[  OK  ] Finished Update UTMP about System Runlevel Changes.


Debian GNU/Linux 11 DESKTOP-IE5EV1S ttyS0


DESKTOP-IE5EV1S login: root
Password:
Linux DESKTOP-IE5EV1S 5.10.178-gcaf2a57efe0a #1 SMP PREEMPT Tue Apr 25 11:22:43 CST 2023 x86_64


The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.


Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@DESKTOP-IE5EV1S:~#
root@DESKTOP-IE5EV1S:~# uname -a
Linux DESKTOP-IE5EV1S 5.10.178-gcaf2a57efe0a #1 SMP PREEMPT Tue Apr 25 11:22:43 CST 2023 x86_64 GNU/Linux
root@DESKTOP-IE5EV1S:~#
root@DESKTOP-IE5EV1S:~# cat /proc/version
Linux version 5.10.178-gcaf2a57efe0a (huangqw@DESKTOP-IE5EV1S) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1 SMP PREEMPT Tue Apr 25 11:22:43 CST 2023
文章来自个人专栏
crosvm
2 文章 | 1 订阅
0条评论
0 / 1000
请输入你的评论
0
0