Launch AMD SEV-SNP VM with console

用console安装SEV-SNP虚拟机

Posted by luobobo on August 31, 2024

怎么支持markdown code block还有问题…太忙了懒得修了,先这样

lbb第一次装es的时候没记notes,过程及其痛苦。

最近又装了一次snp,加倍痛苦。

好像现在也没啥好教程,简单记一下只用terminal (ssh access),没有GUI的情况下如何最快装好sev-snp VM.

1.先听它的 Github

git clone https://github.com/AMDESE/AMDSEV.git
cd AMDSEV
git checkout snp-latest

如果你想ssh连这个VM, 在common.sh 里给qemu 加上--enable-slirp

./build.sh --package
sudo cp kvm.conf /etc/modprobe.d/

Here are some of the issues I encountered when setting up a normal sev-snp VM following the official AMD instructions.

- Python not fount
sudo apt install python-is-python3

- iasl nasm are missing
sudo apt install iasl nasm

/bin/sh: 1: flex: not found
/bin/sh: 1: bison: not found

sudo apt-get install libssl-dev libelf-dev
sudo apt-get install debhelper-compat=12

2.再听它的

cd snp-release-<date>
./install.sh
sudo reboot now

Reboot the machine and choose SNP Host kernel from the grub menu.

uname -r

版本后面应该会有一串rcX-sev-

dmesg | grep -i -e rmp -e sev

注意看那个firmware 版本大于1.51,不然你麻烦了

cat /sys/module/kvm_amd/parameters/sev_snp 
Y

3.Prepare Guest (好,现在开始含糊起来了)

先create disk image

qemu-img create -f qcow2 guest_vm.qcow2 40G

a. 下载ISO镜像,这里假设你没有gui,只用console,不装vncviewer b. 血泪教训1: 装ubuntu22.04, 用20.04卡在boot环节好久 c. 装server, 不然你进去以后麻烦一堆

wget https://releases.ubuntu.com/jammy/ubuntu-22.04.5-live-server-amd64.iso #确切的镜像最好进目录找

4.Install Guest

sudo ./launch-qemu.sh -hda guest_vm.qcow2 -cdrom ubuntu-22.04.5-live-server-amd64.iso

进去以后有text图形化界面,看的懂字就问题不大,这一步会装进上一步创建好的disk image里。 如果boot的时候卡住了要add “console=ttyS0,115200n8” to the kernel command line,不知道怎么加的话参考这里

a. 提前给root创建好密码 passwd b. 提前创个普通用户方便待会儿ssh/scp

adduser yourusername
sudo reboot now

5.boot from qcow2

第一步先改launch-vm.sh

USE_DEFAULT_NETWORK=”1”

network 那里我用的

add_opts "-netdev user,id=vmnic,hostfwd=tcp::8000-:22 -device e1000,netdev=vmnic,romfile="

Launch VM

sudo ./launch-qemu.sh -hda guest_vm.qcow2 

冷静,现在还不能用-sev-snp, guest kernel不对

snp-release-(date)下面

(Host): scp -P 8000 ./linux/guest/*.deb yourname@localhost:/home/yourname
(VM): dpkg -i *.deb
(VM): sudo reboot now

6.Finally

sudo ./launch-qemu.sh -hda guest_vm.qcow2 -sev-snp