buninu-linux 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,105 @@
1
+ # chroot — run a command inside another root directory
2
+
3
+ `/bin/chroot` is a Bun script that calls `chroot(2)` and `mount(2)` through
4
+ `/lib/dlopen.js`.
5
+
6
+ Unlike the traditional `chroot`, it prepares the new root first, so a
7
+ freshly unpacked root filesystem is usable straight away, and it undoes
8
+ every mount it made when the command exits.
9
+
10
+ ## Synopsis
11
+
12
+ ```sh
13
+ chroot NEWROOT [COMMAND [ARGUMENT...]]
14
+ chroot [-n] [-k] [-v] NEWROOT [COMMAND [ARGUMENT...]]
15
+ chroot -h | --help
16
+ ```
17
+
18
+ With no COMMAND it runs `$SHELL` if that exists inside NEWROOT, otherwise
19
+ `/bin/sh`, interactively when the terminal is one.
20
+
21
+ ## What it mounts
22
+
23
+ | Inside NEWROOT | What | Why |
24
+ |---|---|---|
25
+ | `/proc` | a fresh `proc` | path resolution, `ps`, anything reading `/proc/self` |
26
+ | `/sys` | a fresh `sysfs` | device and network information |
27
+ | `/dev` | recursive bind of the host's `/dev`, made a slave mount | every device node, including `/dev/ptmx`, without a second devtmpfs |
28
+ | `/dev/pts` | `devpts`, only if the bind brought none | pseudo-terminals for shells and editors |
29
+ | `/run` | `tmpfs` | runtime state |
30
+ | `/tmp` | `tmpfs` | scratch space that does not touch the root filesystem |
31
+ | `/etc/resolv.conf` | bind of the host's file | name resolution, without editing anything inside |
32
+
33
+ A mount point that already exists as a mount is left alone. A directory that
34
+ is missing is created; if the root filesystem is read-only and that fails,
35
+ that one mount is skipped and the rest still happen — use `-v` to see which.
36
+
37
+ Making `/dev` a slave mount means mounts appearing inside the root do not
38
+ propagate back to the host, and unmounting it afterwards cannot take the
39
+ host's `/dev` with it.
40
+
41
+ ## Options
42
+
43
+ | Option | Meaning |
44
+ |---|---|
45
+ | `-n`, `--no-mount` | Do not mount anything: the behaviour of the traditional `chroot`. Note that Bun itself cannot start without `/proc` and `/dev/urandom`, so `-n` suits statically linked programs. |
46
+ | `-k`, `--keep-mounts` | Leave the mounts in place after the command exits, to enter the same root again cheaply. Clean up later with `umount -R`. |
47
+ | `-v`, `--verbose` | Report every mount and unmount. |
48
+ | `--` | End of options; everything after it is NEWROOT and COMMAND. |
49
+
50
+ ## Examples
51
+
52
+ ```sh
53
+ # Mount a disk and enter the system on it
54
+ mount /dev/vda2 /mnt --mkdir
55
+ chroot /mnt
56
+
57
+ # Run one command and leave
58
+ chroot /mnt /bin/bun --version
59
+
60
+ # Watch what is set up and taken down
61
+ chroot -v /mnt /bin/sh -c 'ls /proc | head -3'
62
+
63
+ # Traditional behaviour: nothing is mounted for you
64
+ chroot -n /mnt /bin/sh
65
+
66
+ # Keep the mounts for repeated visits
67
+ chroot -k /mnt /bin/sh -c 'true'
68
+ chroot -k /mnt
69
+ umount -R /mnt
70
+ ```
71
+
72
+ ## Cleanup
73
+
74
+ When the command exits, every mount this invocation made is unmounted,
75
+ deepest first, including anything that appeared under the recursive `/dev`
76
+ bind. A mount that is still busy — a process left running inside, a shell
77
+ with its working directory there — is detached instead (`MNT_DETACH`), so
78
+ the kernel releases it once its last user goes away. The same cleanup runs
79
+ if `chroot(2)` itself fails or the command cannot be started, and on
80
+ `SIGTERM` or `SIGHUP`.
81
+
82
+ `Ctrl-C` goes to the command, not to `chroot`, so the mounts are still
83
+ removed after an interrupted program.
84
+
85
+ ## Limits
86
+
87
+ - Needs to be superuser: `chroot(2)` requires `CAP_SYS_CHROOT`, and the
88
+ mounts require `CAP_SYS_ADMIN`. Buninu normally runs as root.
89
+ - The new root must contain the program you ask for and whatever it links
90
+ against; `chroot /mnt /bin/sh` fails with "not found" if `/mnt/bin/sh`
91
+ is not there.
92
+ - Only the filesystem view changes. Processes, network, users and the
93
+ hostname are shared with the host; this is not a container.
94
+ - `-k` leaves mounts behind on purpose. `umount -R NEWROOT` removes them.
95
+
96
+ ## Exit status
97
+
98
+ The command's own status, or `125` if `chroot` itself failed, `126` if the
99
+ command was found but could not be run, and `127` if it was not found.
100
+
101
+ ## See also
102
+
103
+ - Source: `/bin/chroot`
104
+ - `mount --help`, `umount --help`
105
+ - Shared native binding: `/lib/dlopen.js`
@@ -27,7 +27,7 @@ Use `-` as ARCHIVE to read from standard input or write to standard output.
27
27
  | `-C DIR`, `--directory=DIR` | Read input files from DIR, or extract into DIR. |
28
28
  | `-z`, `--gzip` | Create gzip-compressed tar, or explicitly identify gzip input. |
29
29
  | `--zstd` | Create or read a zstd-compressed tar. A `.zst` or `.tzst` input is also detected by name. |
30
- | `-v` | Print names while creating/extracting; with `-t`, also show each regular file's size and modification time. |
30
+ | `-v` | Print names while creating/extracting; with `-t`, also show each member's size, modification time, kind and link target. |
31
31
 
32
32
  Short options can be combined, for example `-xzvf` or `-czf`.
33
33
  For the traditional first option word, the leading hyphen is optional, so
@@ -42,8 +42,34 @@ tar -xzf source.tar.gz -C /tmp/source
42
42
  tar -tf source.tar.gz
43
43
  tar --zstd -cf backup.tar.zst home
44
44
  tar --zstd -xf backup.tar.zst -C /mnt/restore
45
+
46
+ # An Alpine root filesystem, symbolic links and all; then enter it
47
+ tar -xzf alpine-minirootfs-3.24.1-x86_64.tar.gz -C /mnt/alpine
48
+ chroot /mnt/alpine
45
49
  ```
46
50
 
51
+ ## Links
52
+
53
+ Extraction restores symbolic links exactly as the archive records them,
54
+ including absolute targets such as `/bin/busybox` and targets that do not
55
+ exist yet, and it restores hard links. This is what GNU tar does, and it is
56
+ what an unpacked root filesystem needs: an Alpine minirootfs is 335 symbolic
57
+ links, 306 of them absolute, and without them the result has no `/bin/sh`.
58
+
59
+ `Bun.Archive` creates only the symbolic links whose target is relative and
60
+ stays inside the extraction directory, and skips hard links entirely, so
61
+ this command reads the archive's own headers (ustar, GNU `L`/`K` long names,
62
+ pax `x` records) and creates the rest itself once every file is in place.
63
+ Nothing is ever written through a link, because the links are made last.
64
+
65
+ A member's own name still follows GNU tar's rule: a leading `/` is dropped
66
+ and a name containing `..` is refused, so an archive cannot write outside
67
+ the extraction directory.
68
+
69
+ The same header scan backs listing, so `-t` reports every member —
70
+ directories, links, devices — and not just regular files. A symbolic link
71
+ shows its target, a hard link the file it points at.
72
+
47
73
  ## Current Bun.Archive limits
48
74
 
49
75
  Creation stores regular files only. Symbolic links are rejected rather than
@@ -51,11 +77,9 @@ silently archived as the wrong type; modes, ownership, hard links, and empty
51
77
  directories are not preserved. Bun 1.4.3 also requires file contents to be
52
78
  materialized in memory before archive creation.
53
79
 
54
- Extraction restores directories and symbolic links, but Bun 1.4.3 skips hard
55
- links. Listing and verbose extraction use `Archive.files()`, so they report
56
- regular files only. Verbose listing can show their size and modification time,
57
- but not the unavailable mode or owner. Bun provides gzip and zstd codecs but no xz or bzip2 codec,
58
- so this command does not accept `.tar.xz` or `.tar.bz2`.
80
+ Extraction does not restore modes, ownership or timestamps. Bun provides gzip
81
+ and zstd codecs but no xz or bzip2 codec, so this command does not accept
82
+ `.tar.xz` or `.tar.bz2`.
59
83
 
60
84
  Appending with `-r`/`rvf` is not supported. `Bun.Archive` has no append API;
61
85
  rebuilding an existing archive through `Archive.files()` would silently lose
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "buninu-linux",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "A Linux distribution running Bun as PID 1 with the Buninu userspace.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -37,6 +37,6 @@
37
37
  "fetch": "./index.js -f",
38
38
  "pack": "./index.js -b",
39
39
  "start": "./index.js -r",
40
- "check": "for f in ./index.js ./initramfs/init.js ./initramfs/lib/document.js ./initramfs/lib/dlopen.js ./initramfs/lib/fbdev.js ./initramfs/lib/canvas.js ./initramfs/lib/bunterm/glyphs.js ./initramfs/lib/bunterm/renderer.js ./initramfs/lib/bunterm/images.js ./initramfs/lib/bunterm/input.js ./initramfs/lib/bunterm/terminal.js ./initramfs/lib/modprobe.js ./initramfs/lib/power.js ./initramfs/bin/bunterm ./initramfs/bin/mount ./initramfs/bin/umount ./initramfs/bin/ip ./initramfs/bin/ps ./initramfs/bin/top ./initramfs/bin/poweroff ./initramfs/bin/reboot ./initramfs/bin/tar; do node --check \"$f\" || exit 1; done"
40
+ "check": "for f in ./index.js ./initramfs/init.js ./initramfs/lib/document.js ./initramfs/lib/dlopen.js ./initramfs/lib/fbdev.js ./initramfs/lib/canvas.js ./initramfs/lib/bunterm/glyphs.js ./initramfs/lib/bunterm/renderer.js ./initramfs/lib/bunterm/images.js ./initramfs/lib/bunterm/input.js ./initramfs/lib/bunterm/mouse.js ./initramfs/lib/bunterm/terminal.js ./initramfs/lib/modprobe.js ./initramfs/lib/power.js ./initramfs/bin/bunterm ./initramfs/bin/chroot ./initramfs/bin/mount ./initramfs/bin/umount ./initramfs/bin/ip ./initramfs/bin/ps ./initramfs/bin/top ./initramfs/bin/poweroff ./initramfs/bin/reboot ./initramfs/bin/tar ./initramfs/bin/stripansi; do node --check \"$f\" || exit 1; done"
41
41
  }
42
42
  }