-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4dbe0a0
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Prerequisites | ||
|
||
``` | ||
apt install -y e2fsprogs coreutils debootstrap qemu-system-x86 | ||
``` | ||
|
||
|
||
# Create vm | ||
``` | ||
sudo ./create-vm.sh | ||
``` | ||
|
||
# Run firefox | ||
Start vm | ||
``` | ||
qemu-system-x86_64 \ | ||
-drive file=root.img,format=raw \ | ||
-kernel /boot/vmlinuz-`uname -r` \ | ||
-initrd /boot/initrd.img-`uname -r` \ | ||
-append "root=/dev/sda rdinit=/sbin/init console=tty1,115200 console=ttyS0,115200" \ | ||
-m $MEMORY \ | ||
-smp ${CPU:-1} \ | ||
-machine ubuntu,accel=kvm \ | ||
-nographic \ | ||
-device virtio-net,netdev=vmnic -netdev user,id=vmnic,hostfwd=tcp::5555-:22 | ||
``` | ||
Run firefox | ||
``` | ||
ssh user@localhost -p5555 -Y firefox | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
DISK=3G | ||
MEMORY=2G | ||
CPU=4 | ||
|
||
truncate root.img --size ${DISK:-3G} | ||
mkfs.ext4 root.img -L ROOT | ||
|
||
export MOUNTPOINT=$(mktemp -d) | ||
mount root.img $MOUNTPOINT | ||
debootstrap --include=firefox,openssh-server,xauth --components=main,universe bionic $MOUNTPOINT | ||
cat <<"EOF" | bash | ||
chroot $MOUNTPOINT | ||
useradd -m user | ||
passwd -d user | ||
echo LABEL=ROOT / ext4 rw 0 1 > /etc/fstab | ||
echo "user ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers | ||
cat<<"EOF2" > /etc/systemd/system/dhclient.service | ||
[Unit] | ||
Description=dhclient | ||
#After=network.target | ||
[Service] | ||
Type=simple | ||
ExecStart=/bin/bash -c 'modprobe virtio-net; while [[ ! $( ip l | grep -e "^2:") ]]; do sleep 1; done; /sbin/dhclient -v -w' | ||
StandardOutput=journal | ||
[Install] | ||
WantedBy=multi-user.target | ||
EOF2 | ||
systemctl enable dhclient | ||
EOF | ||
|
||
# apt doesn't find it for some reason | ||
# sudo apt-get -o Dir=$MOUNTPOINT update | ||
# sudo apt-get -o Dir=$MOUNTPOINT install linux-modules-`uname -r` | ||
mkdir $MOUNTPOINT/lib/modules/ | ||
cp /lib/modules/`uname -r` $MOUNTPOINT/lib/modules/ -r | ||
umount $MOUNTPOINT |