Month: December 2016

Pass a Device to a Linux Container

Recently I was trying to make FPGA tools running inside a LinuX Container (LXC). Getting the software tools running is basically about coping with Xilinx’s horrible bash scripts. Making the container see the FPGA hardware seems more challenging and there are very few references on the Internet. The major trick is to pass the correct devices to the LXC. FPGAs (at least those…


If you are working with some software which requires you to source some code and messes up with your PATH and other environment variables like Vivado and Merlin compiler, here is a simple and straightforward method to get rid of the mess (to some extent).

. /space/Xilinx/SDAccel/${VERSION}/
# do something if necessary
if ! test "$0" -ef "$(which $(basename $0))"
    exec $(basename $0) "$@"
    if test -t 2
        echo "Recursive call detected!" 1&>2

Some notes:

  • Start with #!/bin/bash if you or your script use bash-specific syntax!
  • Give this file execution permission with chmod +x!
  • Make sure this file itself has the same name as the target program, or is soft-linked to it!
  • Use . instead of source, which improves compatibility!

On Linux, if you see

mtr: unable to get raw sockets.

The following might help:

sudo chmod 4755 $(which mtr)


The reason this happens is that only privileged processes (or processes with proper capabilities(7) on Linux) can create raw sockets, which is needed to send/receive ICMP packets. By chmod(2), the executable will get the S_ISUID mode, which means it can set process effective user ID when execve(2).

A safer solution is

sudo setcap cap_net_raw+ep $(which mtr)

which only gives mtr the cap_net_raw capability.

Reinstalling the mtr package via the package manager should also solve the problem since it will do whatever appropriate to make it work.