Alpine Linux in VMware Fusion

Alpine Linux in VMware Fusion

Thu 22 October 2020

I needed a small Linux-VM running on my Mac. This is how I solved it with Alpine Linux.

Installation

Start with downloading the Alpine Linux Standard ISO from: https://www.alpinelinux.org/downloads/

Boot the image, login with username root and start the installation with:

# setup-alpine

When asked about diskmode, choose sys. Otherwise provide the setupassistant with sensible values for your situation.

When the setupassistant is done, you can add shared folder to your VM.

Reboot the VM.

Get the vmware shared folders working

Before we add packages we want to enable the community repository:

# vi /etc/apk/repositories

Uncomment the lines related to community repo:

#/media/cdrom/apks
http://dl-cdn.alpinelinux.org/alpine/v3.12/main
http://dl-cdn.alpinelinux.org/alpine/v3.12/community
#http://dl-cdn.alpinelinux.org/alpine/edge/main
#http://dl-cdn.alpinelinux.org/alpine/edge/community
#http://dl-cdn.alpinelinux.org/alpine/edge/testing

http://dl-cdn.alpinelinux.org/alpine/v3.12/main
http://dl-cdn.alpinelinux.org/alpine/v3.12/community
#http://dl-cdn.alpinelinux.org/alpine/edge/main
#http://dl-cdn.alpinelinux.org/alpine/edge/community
#http://dl-cdn.alpinelinux.org/alpine/edge/testing

With the community repository we can refresh the packagelist and install the open-vm-tools packages:

# apk update
# apk add open-vm-tools
# apk add open-vm-tools-guestinfo
# apk add open-vm-tools-deploypkg
# rc-update add open-vm-tools boot

Reboot the VM.

Test the mounting:

# modprobe fuse
# /usr/bin/vmhgfs-fuse .host:/ /mnt -o subtype=vmhgfs-fuse,allow_other
# cd /mnt/alpine_share

Some last minute configuration

So far we have been running as root, which is bad practice. Lets add a normal user:

# adduser alpineuser
# passwd alpineuser

To be able to have fun with our new Alpine Linux VM we want to install our favorite assembler:

# apk add yasm
# apk add yasm-doc
# apk add yasm-dev
# apk add build-base
# apk add musl-dev

Congratulations, we now have a working Alpine Linux VM.

For more information you can check the Alpine Wiki: https://wiki.alpinelinux.org/wiki/Main_Page

Lets write some assemblercode just to check if things work.

Create a file test.asm with the following content:

lobal _start

section .text

_start:
  mov rax, 1        ; write(
  mov rdi, 1        ;   STDOUT_FILENO,
  mov rsi, msg      ;   "Hello, world!\n",
  mov rdx, msglen   ;   sizeof("Hello, world!\n")
  syscall           ; );

  mov rax, 60       ; exit(
  mov rdi, 0        ;   EXIT_SUCCESS
  syscall           ; );

section .rodata
  msg: db "Hello, world!", 10
  msglen: equ $ - msg

This code I found on: https://jameshfisher.com/2018/03/10/linux-assembly-hello-world/

YASM it:

$ yasm -felf64 test.asm

Link it:

$ ld -o test test.o

Run it:

$ ./test
Hello, world!

Hurra... It works!