Skip to content

Instantly share code, notes, and snippets.

@Jacobboogiebear
Created March 13, 2022 07:10
Show Gist options
  • Save Jacobboogiebear/2af9a49f8e9fdc2641ae019be58c4acd to your computer and use it in GitHub Desktop.
Save Jacobboogiebear/2af9a49f8e9fdc2641ae019be58c4acd to your computer and use it in GitHub Desktop.
A quick script to build swtpm and libtpm on Ubuntu 20.04 (created for WSL2 and WSLg)
sudo apt-get install git g++ gcc automake autoconf libtool make gcc libc-dev libssl-dev pkg-config libtasn1-6-dev libjson-glib-dev expect gawk socat libseccomp-dev -y
cd ~
git clone https://github.com/stefanberger/swtpm.git
git clone https://github.com/stefanberger/libtpms.git
cd libtpms
./autogen.sh --prefix=/usr --with-tpm2 --with-openssl
make
sudo make install
cd ../swtpm
./autogen.sh --prefix=/usr
make
sudo make install
cd ..
rm -rf swtpm/ libtpms/
@josteink
Copy link

josteink commented Mar 27, 2022

To make this work with virt-manager, one also needs to install certtool before building. On Ubuntu you can do this via this command:

sudo apt install gnutls-bin 

If not swtpm_cert will not be build, and virt-manager will fail to create a swtpm device.

@ppelleti
Copy link

I found that just installing gnutls-bin was not enough. I also needed to install libgnutls28-dev before building swtpm. Only after that did it successfully work with virt-manager.

@dylan2intel
Copy link

dylan2intel commented Apr 28, 2023

It works fine for me with above aggregation comments, btw, ensure current user in sudoers.

cat <<EOF > build-swtpm.sh
> sudo apt-get install -y git g++ gcc automake autoconf libtool make gcc libc-dev libssl-dev pkg-config libtasn1-6-dev libjson-glib-dev expect gawk socat libseccomp-dev \
> gnutls-bin libgnutls28-dev
> cd ~
> git clone https://github.com/stefanberger/swtpm.git
> git clone https://github.com/stefanberger/libtpms.git
> cd libtpms
> ./autogen.sh --prefix=/usr --with-tpm2 --with-openssl
> make -j || make
> sudo make install
> cd ../swtpm
> ./autogen.sh --prefix=/usr
> make -j || make
> sudo make install
> cd ..
> rm -rf swtpm/ libtpms/
> EOF
chmod +x build-swtpm.sh
./build-swtpm.sh

swtpm -v
TPM emulator version 0.9.0, Copyright (c) 2014-2022 IBM Corp. and others

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment