On Wed, 15 Feb 2017 17:08:31 -0000 "William Harrington" <[email protected]> wrote:
> Does the network interface need to be restarted for the change to show in > the shell? Not on my system - the change shows up as soon as I: > > echo testhost > /proc/sys/kernel/hostname > > exec /bin/bash > > export PS1="[\u@\h]: " but this just is for bash, not networking. AFAIK, when it starts, bash asks for the hostname via the C-library gethostname() system call which in turn asks the kernel. The kernel will report whatever hostname was written to /proc/sys/kernel/hostname, or by a prior call to sethostname(), and bash will then set its \h and \H prompt variables to that value. Also, from a net search, it seems the proper way to restart bash (to update \h et al.) is indeed to replace it with a new running version of itself: exec /bin/bash I'd be interested to know if there is any quick "restart" bash builtin like there is for reset (terminal reset) and source (reread a given bash config file). As I currently understand things, there isn't. On Wed, 15 Feb 2017 03:58:33 +0000 Ken Moffat <[email protected]> wrote: > Apart from what has already been said, you didn't tell us what > you have managed to do (e.g. with init=/bin/bash you end up > with a read-only root filesystem - I get the impression you > have gone past that). So everybody is guessing. Assuming that there isn't any malfeasance here such as trolling, etc., my own best guess is that his case is for an embedded system (hence the desire for secrecy and low level control). So, he doesn't need all the startup scripts of a full desktop and wants to be able to control/specify everything that is done on startup. If nothing else, the topic is educational. If I had to guess what is going wrong with ssmtpmailtesting's attempt here it would be that either bash was not restarted (because it is serving as init) after the host name was changed and/or that he doesn't have a /proc filesystem and did not think to use the hostname utility in conjuction with my suggestion to restart bash via exec: hostname testhost exec /bin/bash From here: http://superuser.com/questions/200057/how-to-make-bash-update-its-idea-of-hostname another approach is to set the $HOSTNAME variable and the system/kernel hostname and then set the bash prompt to print the value of $HOSTNAME rather than relying on \h which it seems can only be altered during bash startup: export HOSTNAME="testhost" hostname "$HOSTNAME" export PS1="[\u@$HOSTNAME]: " which also does work immediately on my system. Note that in the above, PS1 will be set to the *current* value of $HOSTNAME so if $HOSTNAME is ever later changed, $PS1 should also be set again. FWIW, there is some other good info on setting the hostname here: http://jblevins.org/log/hostname In this case, it might be helpful to have a kernel parameter to set the hostname on boot (e.g., hostname=.. but as far as I know there isn't a hostname kernel parameter). I don't know if the kernel parameter ip= will do the trick here. He could also write a custom little C init program that will make all the needed config system calls and then fork to bash or some other application after everything was configured. Such an approach would be like having a little custom "flat file" mini-systemd. Cheers, Mike Shell -- http://lists.linuxfromscratch.org/listinfo/lfs-support FAQ: http://www.linuxfromscratch.org/blfs/faq.html Unsubscribe: See the above information page Do not top post on this list. A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail? http://en.wikipedia.org/wiki/Posting_style
