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.
Introduction
- Create a virtual machine
- Create a Ubuntu container
- Create a user account
- Setup SSH
Create a virtual machine
- In a browser press
CTRL+ALT+T
to open the Chrome OS developer shell (i.e. chrome-untrusted://crosh) - Create a new VM
1vmc start sandbox
- Create a new profile A profile enable the default settings to be altered.
1lxc profile copy default custom-profile
- Update the profile setting
1lxc profile set minikube-profile security.nesting true
2lxc 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:
1lxc image list images:
- Create a new container based on Ubuntu 18.04
1lxc launch image:ubuntu/bionic sandboxvm --profile custom-profile
- Create a new container based on Ubuntu 18.04
1lxc launch image:ubuntu/bionic sandboxvm --profile custom-profile
- Check the status of the container
1lxc list
Note: This screen shows the state of the container. The IP used to access the machine can be seen here.
- Run the new Ubuntu container
1lxc exec sandboxvm /bin/bash
Create a user account
- Add an account (ie. substitute USERNAME with the account name to be used)
1useradd -m [USERNAME]
- Set a password for the account
1passwd [USERNAME]
- Add user to sudo group
1usermod -aG sudo [USERNAME]
- Note the USERID and GROUPID assigned to the USERNAME
1cat /etc/passwd
Setup SSH
If a remote SSH connection is required then this needs to be setup on the local and remote hosts.
- On the local host VM, generate an SSH key
1ssh-keygen
- Display the ssh key generated
1cat ~/.ssh/id_rsa.pub
- On the remote host set up the SSH user
1mkdir -p /home/[USERNAME]/.ssh
2chmod 700 /home/[USERNAME]/.ssh
3touch /home/[USERNAME]/.ssh/authorized_keys
4chmod /home/[USERNAME]/.ssh/authorized_keys
- Paste the generated key into the authorized_keys file e.g.
1echo "[SSHKEY]" >> /home/[USERNAME]/.ssh/authorized_keys
Connect via SSH
- Get the IP of the container via the LXC screen
- Connect via SSH
1ssh [USERNAME]@[IP]
Connect via LXC
- Login as root
1lxc exec sandboxvm /bin/bash && cd
- Login as a specific user and use their home directory
To connect as a specific user:
- USERID
- GROUPID
- USERNAME
1lxc exec sandboxvm --user [USERID] --group [GROUPID] --cwd [USERID] --env HOME=/home/[USERNAME] /bin/bash && cd