Wednesday, July 10, 2019

[SOLVED] Mounting external USB drive to Proxmox LXC Container

I needed to mount an external USB drive directly to an LXC container.  On initial research, this process seems simple enough.

I am using Ubuntu / Debian for this guide.

Basically I do the following to get it mounted on the Proxmox Hardware Node first:

mkdir /mnt/mountpoint
chmod -R 777 /mnt/mountpoint (this is optional)
mount /dev/bus/usb/001/004 /mnt/mountpoint

BUT! when I tried to use it in the LXC container I got 'READ ONLY' permission issues. Some error message like this:

Read only filesystem!

So I did a lot more research and found many people have similar issues. I wasted 30 minutes trying different suggestions until I found one that worked.  The solution is the fact that linux was mounting the partition as fat32 / exfat. Therefore it could not perform Read and Write.  Here is the solution that worked for me...

STEP 1 - INSTALL ntfs-3g

sudo apt-get update
sudo apt-get install ntfs-3g

STEP 2 - MOUNT using NTFS file system type (my usb drive is at USB 001:004)

mkdir /mnt/mountpoint
chmod -R 777 /mnt/mountpoint (this is optional)
mount -t ntfs-3 /dev/bus/usb/001/004 /mnt/mountpoint

STEP 3 - CHECK IF YOU CAN READ & WRITE

cd /mnt/mountpoint
touch test

If step 3 did not produce any error and you can clearly see file 'test' being created, then you are good to go.

Next you just need to add one line to your LXC container configuration to set the mountpoint.

nano /etc/pve/lxc/123.conf   (assuming 123 is your CT ID)

Tuesday, May 21, 2019

How to mount NFS share to Proxmox LXC container

This is a quick how to guide to mount NFS share to your Proxmox VE LXC container.

If you are experiencing permission issue, you may want to read this article:

for example: May 21 12:42:31 e7 systemd[1]: Failed to start PVE LXC Container: 164.

Enabling NFS sharing mount bind in Proxmox

STEP 1 - EDIT YOUR LXC CONTAINER CONFIGURATION

nano /etc/pve/lxc/[CTID].conf


STEP 2 - ADD THE FOLLOWING LINE TO END OF CONFIGURATION FILE


mp0: [/host/nfs/shared_path],mp=[/lxc/container/mount_point_path]

for example:

mp0: /mnt/pve/nfs_share/,mp=/data_shared


(note: please make sure you pre-created the /data_shared (mount point) directory in your LXC container first)

STEP 3 - RESTART YOUR LXC


pct shutdown [CTID]
pct start [CTID]


Unlike openvz you do not have to edit / add anything to your fstab file. The next time you enter your container, you will have the NFS share automatically mounted.

Enabling NFS sharing (mount bind) for mounting NFS shares into LXC container

If you are running Proxmox 5.x and you are trying to mount an NFS share to your LXC container you may encounter permission denied issues.

such as:
May 21 12:42:31 e7 systemd[1]: Failed to start PVE LXC Container: 164.


This issue is caused by security permission in apparmor. We just need to reconfigure it so that it will support NFS shares.

This article will describe how to overcome this issue permission issue.

STEP 1 - COPY APPARMOR CONFIGURATION (on Proxmox Host)

cd /etc/apparmor.d/lxc
cp lxc-default-cgns lxc-container-default-with-nfs
nano lxc-container-default-with-nfs

Change lxc-container-default-cgns with lxc-container-default-with-nfs

Add the following lines right before the } (closing curly brace)

  mount fstype=nfs*,
  mount fstype=rpc_pipefs,


STEP 2 - RELOAD APPARMOR

systemctl reload apparmor



The above 2 steps will fix the AppArmor permission issues.

Next, you may want to know how to Bind Mount your NFS share to your LXC container, please click on the next article How to mount NFS share to Proxmox LXC container.



SAMPLE OF MY LXC CONFIGURATION FILE:


arch: amd64
cores: 4
hostname: blahblah
memory: 8192
nameserver: 10.0.0.1 8.8.8.8 4.4.4.4
net0: name=eth0,bridge=vmbr0,gw=10.0.0.1,hwaddr=_______________,ip=10.0.110.42/16,type=veth
ostype: ubuntu
rootfs: local_md0:164/vm-164-disk-1.raw,size=64G
searchdomain: localhost
swap: 8192
lxc.apparmor.profile: lxc-container-default-with-nfs
mp0: /mnt/pve/vepublicb1/tf/data_shared,mp=/data_shared

Debugging a proxmox LXC container that will not start

Sometime after making changes in your LXC configuration file in /etc/pve/lxc your LXC container may have problem starting. You will get a message like this:

Job for pve-container@165.service failed because the control process exited with error code.
See "systemctl status pve-container@165.service" and "journalctl -xe" for details.
command 'systemctl start pve-container@165' failed: exit code 1

Then it recommends to get status of the start by typing...

systemctl status pve-container@165.service

And its output is...

● pve-container@165.service - PVE LXC Container: 165
   Loaded: loaded (/lib/systemd/system/pve-container@.service; static; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2019-05-21 08:13:01 CDT; 10s ago
     Docs: man:lxc-start
           man:lxc
           man:pct
  Process: 3560220 ExecStart=/usr/bin/lxc-start -n 165 (code=exited, status=1/FAILURE)

May 21 08:12:59 e2 systemd[1]: Starting PVE LXC Container: 165...
May 21 08:13:01 e2 lxc-start[3560220]: lxc-start: 165: lxccontainer.c: wait_on_daemonized_start: 865 Received container state "ABORTING" instead of "RUNNING"
May 21 08:13:01 e2 lxc-start[3560220]: lxc-start: 165: tools/lxc_start.c: main: 330 The container failed to start
May 21 08:13:01 e2 lxc-start[3560220]: lxc-start: 165: tools/lxc_start.c: main: 333 To get more details, run the container in foreground mode
May 21 08:13:01 e2 lxc-start[3560220]: lxc-start: 165: tools/lxc_start.c: main: 336 Additional information can be obtained by setting the --logfile and --logpriority options
May 21 08:13:01 e2 systemd[1]: pve-container@165.service: Control process exited, code=exited status=1
May 21 08:13:01 e2 systemd[1]: pve-container@165.service: Killing process 3560226 (3) with signal SIGKILL.
May 21 08:13:01 e2 systemd[1]: Failed to start PVE LXC Container: 165.
May 21 08:13:01 e2 systemd[1]: pve-container@165.service: Unit entered failed state.

May 21 08:13:01 e2 systemd[1]: pve-container@165.service: Failed with result 'exit-code'.


As you can see the output still does not tell me enough information.

So I recommend using the following command to start LXC with debug and output log to temporary file:


lxc-start --logfile /tmp/lxc-start.log -n [CTID]



if the debug or log above is still not enough, the next command below will provide an EXTREMELY detailed log:

strace -f lxc-start -l trace -o /tmp/trace.log -n [CTID]

Wednesday, May 15, 2019

Debugging (verbose logging) LXC startup process in Proxmox VE

Sometime you run into problem and your LXC container do not start.  Proxmox VE graphical UI is very good, but it does not provide enough information about what is wrong.

To get the most detailed information, you should try to start the LXC container from command using verbose logging. Here is the command you should use:


(replace [ID] with your actual LXC container ID)

lxc-start -n [ID] -F -l DEBUG -o /tmp/lxc-[ID].log


Then, to view the log use this command:

cat /tmp/lxc-[ID].log

Upgrading Proxmox VE

To upgrade your Proxmox virtual environment to the next version do the following steps.

Step 1 - Get latest APT updates

apt-get update


Step 2 - Perform distribution upgrade

apt-get dist-upgrade


You may be asked if you would like to use existing or newer configuration file. I usually answer N (no) to keep using the current version which is usually safer.

Can not start LXC container with error: unsupported Ubuntu version '18.04'

I restored an LXC container I have backed up from a newer Proxmox VE to an older node. To my surprise... it would not start. This is the error message I got when I debugged the LXC start-up process.


lxc pre-start with output: unsupported Ubuntu version '18.04'


When I press start button, it quickly fails and displays:




I thought it may be caused by file system (the LXC image) corruption. So I tried to mount and unmount it first using

pct mount 165
pct unmount 165

both worked perfectly so that was not the issue.

Then I made sure the file system is clean by running fsck against it, using this fsck command

pct fsck 165

That also ran perfectly clean!

After being puzzled, I researched and found people with similar issue, it turned out that Proxmox LXC start up script checks for version of Ubuntu and did not have the latest version 18.04 LTS Bionic Beaver.  So I updated this file:

nano /usr/share/perl5/PVE/LXC/Setup/Ubuntu.pm

look for this section:
my $known_versions = {
  
    '17.10' => 1, # artful
    '17.04' => 1, # zesty
    '16.10' => 1, # yakkety
    '16.04' => 1, # xenial
    '15.10' => 1, # wily
    '15.04' => 1, # vivid
    '14.04' => 1, # trusty LTS
    '12.04' => 1, # precise LTS
};

and replace it with this:
my $known_versions = {
    '22.04' => 1,
    '20.04' => 1,
    '18.04' => 1, # Bionic Beaver LTS
    '17.10' => 1, # artful
    '17.04' => 1, # zesty
    '16.10' => 1, # yakkety
    '16.04' => 1, # xenial
    '15.10' => 1, # wily
    '15.04' => 1, # vivid
    '14.04' => 1, # trusty LTS
    '12.04' => 1, # precise LTS
};


This SOLVED my issue and I was able to start the LXC container.

If you don't feel comfortable editing /usr/share/perl5/PVE/LXC/Setup/ 
You can also simply upgrade your Proxmox VE node to get the latest update from Proxmox.