lxc-unshare(1)

πŸ’… lxc-unshare(1) β€” like, the manual page, bestie

okay so first thing: this whole page is about lxc-unshare, and yes we're reading the lxc-unshare(1) man page together, welcome to the group chat 🫢

✨ NAME ✨

lxc-unshare β€” run a task in a new set of namespaces. that's it, that's the tweet πŸ’«

🌸 SYNOPSIS 🌸

lxc-unshare {-s, --namespaces namespaces} [-u, --user user] [-H,
            --hostname hostname] [-i, --ifname ifname] [-d, --daemon]
            [-M, --remount] {command}

πŸ¦‹ DESCRIPTION πŸ¦‹

so lxc-unshare runs a task inside a cloned set of namespaces. it's mainly a testing tool, ngl β€” like, it exists so you can poke at kernel stuff πŸ’…

and here's the plot twist: despite the name (iconic, misleading, we love her), it always uses clone rather than unshare to create the new task with fresh namespaces. the docs are like "apart from testing kernel regressions this should make no difference" β€” so basically no cap, same vibe, different syscall 😭

πŸŽ€ OPTIONS πŸŽ€

  • -s, --namespaces namespaces β€” tell it which namespaces to attach to, as a pipe-separated list, like NETWORK|IPC. allowed values are MOUNT, PID, UTSNAME, IPC, USER and NETWORK. this is the whole point, fr fr: you can switch the process's context to, say, the network namespace of the container while keeping every other namespace as the host's. ⚠️ heads up: the pipe symbol needs to be escaped, e.g. MOUNT\|PID, or quoted, e.g. "MOUNT|PID" β€” don't let the shell eat your pipes πŸ’€
  • -u, --user user β€” pick a userid that the new task should become. slay, identity crisis but make it intentional πŸ‘‘
  • -H, --hostname hostname β€” set the hostname in the new container. only allowed if the UTSNAME namespace is set β€” no UTSNAME, no hostname, that's the rule πŸŽ€
  • -i, --ifname interfacename β€” move the named interface into the container. only allowed if the NETWORK namespace is set. and yes bestie you may specify this argument multiple times to move multiple interfaces into the container. the more the merrier 🌈
  • -d, --daemon β€” daemonize (do not wait for the container to exit before exiting). main character energy: it leaves the party early and doesn't look back πŸ’…
  • -M, --remount β€” mount default filesystems (/proc, /dev/shm and /dev/mqueue) in the container. only allowed if the MOUNT namespace is set. 🧚

πŸ”₯ EXAMPLES πŸ”₯

spawn a shell with its own UTS (hostname) namespace

lxc-unshare -s UTSNAME /bin/bash

if the hostname is changed in that shell, the change will not be reflected on the host. your hostname stays unbothered, living its life ✨

spawn a shell in a new network, pid, and mount namespace

lxc-unshare -s "NETWORK|PID|MOUNT" /bin/bash

the resulting shell will have pid 1 and will see no network interfaces (ghosted by every NIC, honestly). after re-mounting /proc in that shell:

mount -t proc proc /proc

ps output will show there are no other processes in the namespace. just you, alone, thriving πŸ¦‹

spawn a shell in a new network, pid, mount, and hostname namespace

lxc-unshare -s "NETWORK|PID|MOUNT|UTSNAME" -M -H myhostname -i veth1 /bin/bash

the resulting shell will have pid 1 and will see two network interfaces (lo and veth1). the hostname will be "myhostname" and /proc will have been remounted. ps output will show there are no other processes in the namespace. two interfaces, one hostname, zero other processes β€” it's giving minimalism πŸ’–


πŸ’œ SEE ALSO πŸ’œ

lxc(7), lxc-create(1), lxc-copy(1), lxc-destroy(1), lxc-start(1), lxc-stop(1), lxc-execute(1), lxc-console(1), lxc-monitor(1), lxc-wait(1), lxc-cgroup(1), lxc-ls(1), lxc-info(1), lxc-freeze(1), lxc-unfreeze(1), lxc-attach(1), lxc.conf(5) β€” go read the whole family, they're all icons πŸ‘‘


and that's the page!! this one's from the lxc-unshare(1) manual, dated 2026-05-01 β€” mwah, go unshare responsibly, ily πŸ«ΆπŸ’…βœ¨

πŸ“¦ where this page comes from