![]() |
| December 1999 | Get BSD | New to BSD? | Search BSD | Submit News | FAQ | Contact Us | Join Us |
|
For this last column of the calendar year we're going back to the original format...well, more or less. We present some new general questions and answers and go back to the first "Help, I've Fallen" column that presented cookbook-type answers. It was this format that brought the three of us together. This time, those initial responses will be broadened and answered in depth.
The second part of the issue will list an archive of all the previous questions and answers from October, 1998 to October, 1999. Not all the sections were individualized in HTML; here, we give the questions and a link to the issue. When we did begin tagging each question, we list the question and a link that will take you directly to that question and our responses.
Using the power and flexibility of Unix, yes! Using the -exec flag of
find is one way.
% find . -type d -exec chmod a+x {}\;
And next time, try using chmod in this way:
% chmod -R u+w ...
Q: I've forgotten my root password and can't/don't how to get back in.
If you are running FreeBSD pre-version 3.X, you can power-cycle the system with the Big Red Switch, and when it prompts:
boot:
you type -s, like this:
boot: -s
to come up in single-user mode. After messages from the booting OS you will see:
Enter full pathname of shell or RETURN for /bin/sh:
Press the return key, wait for a prompt, then type
# fsck -p /
(Various messages appear here - can take a while)
# mount -u /
# passwd root
(Set the root password here)
# exit
The final exit will bring the computer back into multiuser mode.
If you are running FreeBSD 3.0 to 3.3, the boot sequence is a bit different; you have a several second countdown before autobooting to type the -s.
For NetBSD and OpenBSD, the same pretty much applies; i.e. give the -s flag at the boot loader prompt.
On some exotic hardware, it is different again. For example on the pmax and alpha, you need to remove the -a (for autoboot) flag, and for the old Macintoshes, you need to activate the 'single user' radio button in the MacOS booter options!
Q: How do I create a BSD filesystem on a 1.44MB floppy?
Start by formatting the diskette, even if it came pre-formatted: (If your floppy drive is 0, use fd0 or rfd0; if it is drive 1, use fd1 or rfd1.)
# fdformat /dev/rfd0
Next, you must <.>disklabel the floppy; and then run <.>newfs. The following arguments are acceptable.
# disklabel -w -B fd0 fd1440
# newfs -t 2 -u 15 -i 65536 -l1 /dev/rfd0
You will see something like this from newfs:
Warning: calculated sectors per cylinder (30) disagrees with disk label (36)
/dev/rfd0: 2880 sectors in 96 cylinders of 2 tracks, 15 sectors
1.4MB in 6 cyl groups (16 c/g, 0.23MB/g, 32 i/g)
super-block backups (for fsck -b #) at:
32, 528, 992, 1488, 1952, 2448,
For NetBSD and OpenBSD it is a little simpler; we have the following recipe:
# fdformat fd0
# disklabel fd0 floppy3
# newfs /dev/rfd0a
The cryptic 'floppy3' label type comes from /etc/disklabel, and is short for "floppy 3.5". There are other label types for 2.88M floppies, and even 5.25" disks.
OpenBSD and NetBSD have the following disklabel names for the 3.5" 1.44M disks: floppy, floppy3, or 3in and FreeBSD has fd1440, floppy3, 3in, or 3.5in. So, floppy3 is a safe bet.
Finally, mount the floppy drive on /mnt and it is all set for use.
# mount /dev/fd0a /mnt
You can check the filesystem that you build with the df command if you wish. A
% man df
will tell you more about this command, but the meaning of its output is quite self-evident.
# df /mnt Filesystem 1K-blocks Used Avail Capacity Mounted on /dev/fd0a 1327 1 1326 0% /mnt
Note that after mounting a filesystem, it must be unmounted (with umount) to keep the mount table up to date.
# umount /mnt (it is now safe to eject your floppy)
This is a restriction arising from the manual eject mechanism of PC floppy drives, and from Unix's tendency to cache a lot of disk information.
Yes. For FreeBSD there is:
http://www.freebsd.org/tutorials
Much of the help files that apply to the FreeBSD flavor of Berkeley Unix will help with the NetBSD and OpenBSD flavors. There are also the following general BSD resources:
Also, www.OpenBSD.org has an FAQ section now, but it is trying to avoiding splintering off a HOWTO section, and instead trying to fill out the manual pages with good examples.
If you're running FreeBSD, be sure to read Greg Lehey's The Complete FreeBSD, much of which applies to Net and OpenBSD as well.
Since *BSD users have to, almost by default, admin their own sites, the following system administration books are recommended:
Q. Where has all my disk space gone?
Does df tell you that you're at 95% full, 95% of the time? What's using all that space? Could it be that installation of Netscape that you can almost get running under Linux emulation?
The two easiest way that I have found to keep track of which directories are the disk-hogging culprits is to use du and sort, like this:
# du -k / > /tmp/du
$ sort -rn < /tmp/du | less
The initial du will grind away for quite a while. Then the sort will order the entries in reverse numerical order. You'll then be able to page through the output to get a reasonably good idea as to where the big hogs are. For me, it's the gargantuan GNU source tree(s).
Alternatively, there is a very handy X tool called xdu, which gives you a graphical view of /tmp/du. It takes a minute or so to get used to its navigation, but it too can be very handy for those clean-up days. (Look in the ports area for xdu.)
How to I disable a network interface?
Sometimes, when I take this laptop home and dial in with a modem, I find that the modem link is being starved of traffic. The problem is revealed by looking at the outputs of:
# netstat -rn
# ifconfig -a
These commands summarise what the network is doing. The culprit turns out to be that I have accidentally left an unconnected Etherlink PC-Card in the laptop's PCMCIA slot, and useless routes have been put into the routing table for the machines I want to connect to. The unplugged ethernet card is getting the traffic because it was set up earlier than the PPP modem link.
One solution is to simply eject the ethernet PC-card and watch the interface disappear, but I tend to either forget to bring the card back in the morning, or if I leave it sort of half-way into the socket, it silently falls out at the next conveniently busy train station.
Software to the rescue: I can disable ep0 (the ethernet card) with:
# ifconfig ep0 down
# ifconfig ep0 delete
After that, maybe a "route flush" is needed to purge any stale entries, and then a manual "route add default x.x.x.x" will get traffic flowing down the ppp link (where x.x.x.x is the remote IP address as shown by "ifconfig ppp0".)
Thus, your friendly stationmaster need never confuse sporting hero trade cards with type-II PCMCIA cards again.
Q. How do I get the current directory into the title bar or my xterm?
I have had someone recently ask me how they can
First, I'll explain how you can modify the xterm window's title, then I'll describe how to automatically have your shell update it. It's not very complex information, and once you have set it up you can pretty much forget about it.
Xterm control sequences
You may already know that the newline character (control-J) will move the cursor down vertically one row. XTerm uses these control codes, plus what are called vt100 control sequences, to permit fine control over boldness, underline, color, cursor positioning, character set and so on.
Before changing the window title, understand that there are two titles: one that is displayed across the top of the window, and another that is displayed when the window is iconified. Normally you want an abbreviated form in the second.
So, to change the window title, you only need to send the following to
the xterm:
ESC `]' Ps `;' Pt BEL
where ESC is the escape character (control-[), BEL is control-G,
parameter Ps is either 1 or 2 (to select icon or window title), and Pt
is the text you want to put there.
For example, if I want my xterm window to be titled 'leonard@syncope
in /homes/leonard on ttyp3' but with the icon title 'leonard@syncope
ttyp3', I would send
^[]1;leonard@syncope ttyp3^G
^[]2;leonard@syncope in /homes/leonard on ttyp3^G
You can try it using the echo command. Control characters are able to
entered by typing control-V before them (i.e., type control-V then
control-[ to get the ^[ character).
More tricky xterm control sequences are documented in a file called ctlseqs.ms which can be viewed with the command groff -Tascii -ms ctlseqs.ms.
Getting your shell to change the title
Now, this really depends on your shell more than your operating system. I'll look first at the Bourne shell family, then at the C shell family.
In sh, the PS1 variable contains the shell prompt text. You can put
variable expansions (of the form $VAR) into PS1 and they will be
expanded as the prompt is printed. So, a rudimentary first go for just
the window title would be:
PS1='^[]2;$LOGNAME@$HOSTNAME in $PWD^Gprompt> '
(You may need to set up HOSTNAME and TTY in advance by placing in your .profile the following: TTY=`tty` HOSTNAME=`hostname`)
Unfortunately, if your shell does command line editing, the length of the prompt can confuse it. This is to say that sh is not intelligent enough to know that everything between the ^[ and the ^G will not appear in the prompt, but it will think that it does, so horizontal cursor positioning will be incorrectly calculated. The result is not pretty.
Some of the BSDs are using ksh as their sh replacement, and ksh has a
protocol to tell it which characters in the prompt should not be
considered when computing the visible prompt length. It goes like
this:
PS1='^O^M^O invisible text ^O rest of prompt'
Actually, the ^O can be any control character as long as it has no effect when printed to the xterm and doesn't appear anywhere inside the invisible string.
For bash the invisible sequence is bounded in the form
PS1='\[ invisible text \] rest of prompt'
Bash will also expand other useful patterns in PS1 besides variables, like \u becomes the user name.
Alternatively, bash has a variable called $PROMPT_COMMAND, the contents of which gets executed every time just before the prompt is printed.
Commands to set up PS1 can be places in your .kshrc or .bashrc files.
For the original csh, the $prompt variable describes the prompt, but alas, it will not expand variables.
For tcsh the $prompt variable will also expand other patterns useful
for putting in a title (e.g. %m becomes the hostname). And, like bash
and ksh, invisible prompts are bounded in the form
set prompt = '%{ invisible text %} rest of prompt'
Alternatively the precmd command can be aliased to a command that is run before every prompt is printed, and this can be used to print the title-setting text.
Commands to set up your csh prompt can be kept in your .cshrc file.
More
Now that you know how to change the window title and icon title in xterms, and how to modify your sh or csh prompt, you can add functionality to your windows and customise things to display the information that you want to see.
I encourage you to look in your shell's manual page to find out what else you can put into your prompt. A friend of mine has the real-time All Ordinaries Index in his; another the countdown in seconds to the Olympic games. For me, the current working directory is enough. :)
This column takes on some of the more frequently pondered topics bi-monthly along with one or more advanced questions; these for each of the three flavors of BSD. We do our best with each question, but bear in mind that your results and opinions may vary. The authors of this column also tend to subscribe to the idea that it's not possible to protect you from the sharp instruments you'll find included with your *BSD system. While we try not to recommend anything inherently dangerous, it's up to you to use common sense in applying our recommendations.
October, 1998
- Is there a way to remove that annoying ^M from a DOS text file under *BSD?
- How can I use my *BSD floppy drive to copy files to it (in this case, at work), and retrieve the files on my *BSD system at home. So far I've only seen examples that used floppies with a filesystem on them. Is there a simpler, more direct way?
- What's the best way to get a listing of all the manual pages or a subset of them on *BSD?
- Where is tset being called from when a person logs into a freebsd box? This is causing some real annoyances when I telnet from a xterm and after I login the tab stops are messed up on anything except a 80 column screen.
- I've heard of using pkg_add over the net, somehow, but don't understand the exact details. Can you explain how this works?
- I know that a certain file is on my system somewhere, but I'm not sure where. How can I find it?
- Ok, how do I update the locate database every night rather than once a week?
December, 1998
- I can telnet to my FreeBSD system and login as myself just fine, but when I try to login as root, it fails. The system accepts `root' and my password, then just gives me a new "login:" prompt. What's wrong?
- I want to be able to su to root from my own login and understand that I have to put myself in the groups file as wheel. Can you explain exactly what need to do?
- What's the easiest way to change my full name in the password data base? Do I have to su to root?
- Should I run NetBSD-1.3.2 or NetBSD-current?
- Can you explain the difference between the FreeBSD-STABLE and FreeBSD-CURRENT versions? Which one should I use?
- Can you explain the difference between OpenBSD releases and current? Which one should I use?
- How do I install a pre-built package somewhere other than the default directory?
- What's the difference between ~/.Xdefaults and ~/.Xresources? I was trying to alter some default settings (height and width) for my xcoral editor, but couldn't figure it out.
- Can you discuss backups in general. Which way(s) are best?
- How do I get the "at" command to execute a run that I want to begin in the wee hours of the night? The "at" utility seems like a good way to do what I want to, but the man page isn't entirely clear.
February, 1999
- How do I rebuild a new kernel?
- How do I set up my (fake-net) networked home computers?
- What are my backup options?
- How can I increase my number of ptys?
- I just upgraded my system and now ps has quit working
- Tip of the month: rm
April, 1999
- How do I remove un-removable files?
- How does the BSD password system work?
- How can I change my login banner?
- How can I reboot without su'ing to root?
- How can I kill a long print job--and save all that paper?
- Is there a way of using my excess space is /usr for /var files?
- Why no free space after a huge rm -rf!?
- Tip of the month
June, 1999
- Why shouldn't I run as root all the time?
- How can I remove a strangely-named file?
- How can I change my login banner?
- How can I go from multi- to single-user mode?
- Here are a few general shell aliases
- [55]Tip of the month: Back doors.
August, 1999
October, 1999
- Configuring a parallel printer
- Basic printing commands in BSD Unix
- PostScript Filters
- Configuring lpd to print on another computer
- Tip of the month: Sometimes it is the hardware
December, 1999
- Chmod'ing several directories at one fell swoop"
- Help! I've forgotten my root password!"
- How do I create a small filesystem on my floppy disk"
- What good tutorial links are there for *BSD?
- How can I see where all my disk space has gone!?
- How to I disable a network interface? My ethernet card conflicts with ppp!
- How do I get the current directory into the title bar or my xterm?
Gary Kline has been porting code since the late 1970's when he helped port several V6 utilities to V7 at Cal Berkeley. When he isn't hacking code, he's hacking prose, or listening to jazz radio and drinking espresso.
Dirk Myers works at a company that designs and builds bar code scanners, usually in that order. Essentially a Mac user, he installed NetBSD/mac68k 1.2 on an old IIcx because it struck him as being a strange thing to do with a Mac. He now spends more time working on Un*x systems than he does MacOS systems, and shows no signs of returning to a Mac-only environment.
[mail]
David Leonard is a PhD student in the Department of Computer Science and Electrical Engineering at the University of Queensland, Brisbane, Australia.
His area of research is QoS-adaptive component software architectures, and in his spare time is a developer for the OpenBSD project. That said, David enjoys living the quiet life with his wife, Kylie and cat, Mu. He especially enjoys frequenting Moreton Bay's many fabulous places to eat. Mmmmm!