BACK TO THE HOMEPAGE

Aug 06, 2021 3 min read

Setting up ChromeOS Virtual Machine

ChromeOS can create multiple virtual machines to run various software. Creating a new virtual machine allows for software to be tested without ruining your existing setup. It is also great for running programs in an isolated fashion. In this blog post learn how to Create a new virtual machine in ChromeOS.

Asus Chromebox 2 CN62 codename: Guado:inline

Introduction

  • Create a virtual machine
  • Create a Ubuntu container
  • Create a user account
  • Setup SSH

Create a virtual machine

  1. In a browser press CTRL+ALT+T to open the Chrome OS developer shell (i.e. chrome-untrusted://crosh)
  2. Create a new VM
NODE_TYPE // bash
vmc start sandbox
  1. Create a new profile A profile enable the default settings to be altered.
NODE_TYPE // bash
lxc profile copy default custom-profile
  1. Update the profile setting
NODE_TYPE // bash
lxc profile set minikube-profile security.nesting true
lxc profile set minikube-profile security.priviledged false

Create a Ubuntu container

LXC supports a number of images in the following section Ubuntu is used. To see a list of available images:

NODE_TYPE // text
lxc image list images:
  1. Create a new container based on Ubuntu 18.04
NODE_TYPE // bash
lxc launch image:ubuntu/bionic sandboxvm --profile custom-profile
  1. Create a new container based on Ubuntu 18.04
NODE_TYPE // bash
lxc launch image:ubuntu/bionic sandboxvm --profile custom-profile
  1. Check the status of the container
NODE_TYPE // bash
lxc list

Note: This screen shows the state of the container. The IP used to access the machine can be seen here.

  1. Run the new Ubuntu container
NODE_TYPE // bash
lxc exec sandboxvm /bin/bash

Create a user account

  1. Add an account (ie. substitute USERNAME with the account name to be used)
NODE_TYPE // bash
useradd -m [USERNAME]
  1. Set a password for the account
NODE_TYPE // bash
passwd [USERNAME]
  1. Add user to sudo group
NODE_TYPE // bash
usermod -aG sudo [USERNAME]
  1. Note the USERID and GROUPID assigned to the USERNAME
NODE_TYPE // bash
cat /etc/passwd

Setup SSH

If a remote SSH connection is required then this needs to be setup on the local and remote hosts.

  1. On the local host VM, generate an SSH key
NODE_TYPE // bash
ssh-keygen
  1. Display the ssh key generated
NODE_TYPE // bash
cat ~/.ssh/id_rsa.pub
  1. On the remote host set up the SSH user
NODE_TYPE // bash
mkdir -p /home/[USERNAME]/.ssh
chmod 700 /home/[USERNAME]/.ssh
touch /home/[USERNAME]/.ssh/authorized_keys
chmod /home/[USERNAME]/.ssh/authorized_keys
  1. Paste the generated key into the authorized_keys file e.g.
NODE_TYPE // bash
echo "[SSHKEY]" >> /home/[USERNAME]/.ssh/authorized_keys

Connect via SSH

  1. Get the IP of the container via the LXC screen
  2. Connect via SSH
NODE_TYPE // bash
ssh [USERNAME]@[IP]

Connect via LXC

  1. Login as root
NODE_TYPE // bash
lxc exec sandboxvm /bin/bash && cd
  1. Login as a specific user and use their home directory

To connect as a specific user:

  • USERID
  • GROUPID
  • USERNAME
NODE_TYPE // bash
lxc exec sandboxvm --user [USERID] --group [GROUPID] --cwd [USERID] --env HOME=/home/[USERNAME] /bin/bash && cd