github.com/hugelgupf/u-root@v0.0.0-20191023214958-4807c632154c/cmds/exp/cpu/doc.go (about)

     1  // Copyright 2018-2019 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // cpu - connection to CPU server over SSH protocol
     6  //
     7  // Synopsis:
     8  //     cpu [OPTIONS]
     9  //
    10  // Description:
    11  //     On local machine useful flags are all save -remote
    12  //     On remote machines, all save dbg9p, key, hostkey.
    13  //
    14  //     CPU is an ssh client that starts up a shell on a remote machine,
    15  //     as usual; but, further, makes a namespace of the local machine
    16  //     available in a private mount rooted at /tmp/cpu.
    17  //     Wherever you go, there your files are.
    18  //     You can, in the ssh session, do something like this:
    19  //     chroot /tmp/cpu /bin/bash
    20  //     and at that point, you are running a bash, imported from your local
    21  //     machine, on the remote machine; it will use your .profile and
    22  //     all your files are available. You can also do something like
    23  //     cat /tmp/cpu/etc/hosts
    24  //     if your host file is lacking; or
    25  //     cp /etc/hosts /tmp/cpu/tmp
    26  //     to get the /etc/hosts on the remote machine to your local machine.
    27  //
    28  //     The cpu client makes this work by starting a cpu command on the
    29  //     remote machine with a -remote switch and several other arguments.
    30  //     The local cpu starts a 9p server and, using ssh port forwarding,
    31  //     makes that server available to the remote. On the remote side, the
    32  //     cpu command establishes a private, unshared mount of tmpfs on /tmp;
    33  //     creates /tmp/cpu; and mounts the 9p server on that directory.
    34  //
    35  //     CPU has many options, as shown above; most you need not worry about.
    36  //     The most common invocation is
    37  //     cpu -h hostname
    38  //     which will start a shell and mount the 9p server in /tmp/cpu.
    39  //     Note this mount proceeds over the ssh session, and further
    40  //     it mounts in a private /tmp; there is little to see when
    41  //     it is running from outside the ssh session
    42  //
    43  // Options:
    44  //     -bin string
    45  //           path of cpu binary
    46  //     -d    enable debug prints
    47  //     -dbg9p
    48  //           show 9p io
    49  //     -hostkey string
    50  //           host key file
    51  //     -key string
    52  //           key file (default "$HOME/.ssh/cpu_rsa")
    53  //     -network string
    54  //           network to use (default "tcp")
    55  //     -p string
    56  //           port to use (default "22")
    57  //     -port9p string
    58  //           port9p # on remote machine for 9p mount
    59  //     -remote
    60  //           Indicates we are the remote side of the cpu session
    61  //     -srv string
    62  //           what server to run (default "unpfs")
    63  // Examples
    64  // In these examples, cpu runs with warning messages enabled.
    65  // The first message is a warning that cpu could not use overlayfs to build a
    66  // a reasonable union mount. The next are showing you what it is mounting, the
    67  // union mount having failed.
    68  // These mounts are the best we could do for a reasonable compromise of
    69  // wanting local resources visible (e.g. /dev) and using resources from the
    70  // remote machine (e.g. /etc, /lib, /usr and so on).
    71  // u-root doesn't really need /lib and /usr, and u-root's /etc is minimal by design,
    72  // so this works.
    73  // Also note that the user's 9p server running on the local machine is mounted at /tmp/cpu.
    74  // We can turn these off at some point but for now, in early days, we may want them.
    75  // Note that these messages come from the remote side.
    76  // cpu to a machine with bash as your shell and run a command
    77  //   cpu -sp 23 date
    78  //     2019/05/17 16:53:22 Overlayfs mount failed: invalid argument. Proceeding with selective mounts from /tmp/cpu into /
    79  //     2019/05/17 16:53:22 Mounted /tmp/cpu/lib on /lib
    80  //     2019/05/17 16:53:22 Mounted /tmp/cpu/lib64 on /lib64
    81  //     2019/05/17 16:53:22 Warning: mounting /tmp/cpu/lib32 on /lib32 failed: no such file or directory
    82  //     2019/05/17 16:53:22 Mounted /tmp/cpu/usr on /usr
    83  //     2019/05/17 16:53:22 Mounted /tmp/cpu/bin on /bin
    84  //     2019/05/17 16:53:22 Mounted /tmp/cpu/etc on /etc
    85  //     Fri May 17 16:53:23 UTC 2019
    86  // cpu to a machine and run $SHELL (since no arguments were given)
    87  // NOTE: $SHELL is NOT installed on the remote machine! It (and all its .so's and . files)
    88  // come from the local machine.
    89  // cpu sp -23
    90  //    2019/05/17 16:58:04 Overlayfs mount failed: invalid argument. Proceeding with selective mounts from /tmp/cpu into /
    91  //    2019/05/17 16:58:04 Mounted /tmp/cpu/lib on /lib
    92  //    2019/05/17 16:58:04 Mounted /tmp/cpu/lib64 on /lib64
    93  //    2019/05/17 16:58:04 Warning: mounting /tmp/cpu/lib32 on /lib32 failed: no such file or directory
    94  //    2019/05/17 16:58:04 Mounted /tmp/cpu/usr on /usr
    95  //    2019/05/17 16:58:04 Mounted /tmp/cpu/bin on /bin
    96  //    2019/05/17 16:58:05 Mounted /tmp/cpu/etc on /etc
    97  //    root@(none):/# echo ~
    98  //    /tmp/cpu/home/rminnich
    99  //    root@(none):/# ls ~
   100  //    IDAPROPASSWORD  go      ida-7.2  projects            salishan2019random~
   101  //    bin             gopath  papers   salishan2019random  snap
   102  //    root@(none):/#
   103  //    # Now that we are on the node, modprobe something
   104  //    root@(none):/# depmod
   105  //    depmod: ERROR: could not open directory /lib/modules/5.0.0-rc3+: No such file or directory
   106  //    depmod: FATAL: could not search modules: No such file or directory
   107  //    root@(none):/#
   108  //    # Note that, if we had the right modules on our LOCAL machine for this remote machine, we could
   109  //    # insert them. This further means you can build a modular kernel in FLASH and insmod needed modules
   110  //    # later (as long as your core kernel has networking, that is!). Modules could include, e.g., an AHCI
   111  //    # driver.
   112  //    # run the lspci command but redirect output to ~
   113  //    # note it is not installed on the remote machine; it comes from our local machine.
   114  //    root@(none):/# lspci
   115  //    00:00.0 Host bridge: Intel Corporation 82G33/G31/P35/P31 Express DRAM Controller
   116  //    00:01.0 VGA compatible controller: Device 1234:1111 (rev 02)
   117  //    00:02.0 Unclassified device [00ff]: Red Hat, Inc. Virtio RNG
   118  //    00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)
   119  //    00:1f.0 ISA bridge: Intel Corporation 82801IB (ICH9) LPC Interface Controller (rev 02)
   120  //    00:1f.2 SATA controller: Intel Corporation 82801IR/IO/IH (ICH9R/DO/DH) 6 port SATA Controller [AHCI mode] (rev 02)
   121  //    00:1f.3 SMBus: Intel Corporation 82801I (ICH9 Family) SMBus Controller (rev 02)
   122  //    root@(none):/# lspci > ~/xyz
   123  //    root@(none):/# exit
   124  //    # exit and notice that file is on my local machine now:
   125  //    exit
   126  //    rminnich@xcpu:~/gopath/src/github.com/u-root/u-root/xcmds/cpu$ ls -l ~/xyz
   127  //    -rw-r--r-- 1 rminnich rminnich 577 May 17 17:06 /home/rminnich/xyz
   128  //    rminnich@xcpu:~/gopath/src/github.com/u-root/u-root/xcmds/cpu$
   129  package main