iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article

Installing and Playing Around with NetBSD on a USB Drive

に公開

In my room, PCs often appear where I'm not sure if they're dead or alive. This time, it's a TOSHIBA Satellite L21 released in 2010. Somewhere in those 11 years, I seem to have lost the motivation to deal with HDDs, so I tried my best to see if I could play around with it by booting from a USB.

Since I interact with Linux far too much in my daily life, I thought I'd try using a BSD-based OS. One of the great things about BSD systems is that the pre-installed commands are extensive. In Linux, you often need to install the C compiler or make yourself, but in BSD systems, they are likely included from the start.

Initially, I tried to install FreeBSD, but I was met with BTX halted and couldn't even get the installation CD to boot. Furthermore, OpenBSD froze at the boot screen. Holding onto a faint hope, I started the NetBSD installer, and it worked well. So, this time I decided to use NetBSD to build a toy environment.

Installing NetBSD

Preparing the installation media

Download the amd64 CD image from the NetBSD website. You can either burn it to a CD or to a USB drive acting as a CD.

Booting from the installation media


Boot Menu

Insert the installation media into the PC and turn it on, and the Boot Menu will appear. The default selection is fine, so you can either wait for the timer or press RETURN.

Selecting the language for installation


Language Selection

You can select the language to be used during installation. Choosing the language you are most comfortable with will make the installation process easier. I selected English.

Selecting the keyboard layout


Keyboard Layout Selection

You can select the keyboard layout. You should choose the one that best fits the keyboard you are using. Since I use a JIS keyboard as a US keyboard, I just pressed RETURN.

Installation Menu


Installation Menu

Select the action for the installer. Since I want to install NetBSD, select Install NetBSD to hard disk. Select this even if you are installing to a USB drive.


Confirmation to continue

It explains what is about to happen, such as changes to the hard disk data, and asks if you are sure. Select Yes to continue.

Selecting the Destination Disk


Disk Selection

Select the disk where you want to install. Choose carefully, as selecting the wrong disk could accidentally destroy your data.

Configuring the Destination Disk


Selecting the Partitioning Scheme

Select how to partition the disk. Since this is an old PC, I chose MBR.


Confirming Geometry

The disk geometry will be confirmed. Geometry refers to the configuration of the number of cylinders, heads, and sectors on the disk. It asks to correct it if the values detected by the BIOS are incorrect. The BIOS is probably smart, so it should be correct. I just pressed RETURN.


Partitioning Method

It asks if you want to partition manually. I don't want to do anything that tedious, so I'll let it use the entire disk and handle it automatically.


Following the NetBSD Partition

It seemed like it would handle things nicely for NetBSD, so I just pressed RETURN.


Setting Swap Space to 0

While the partitioning was supposed to be handled "nicely," it seems that by default, the swap area takes up most of it. Let's set the swap area to 0.


Last Chance to Edit

This is your last chance to change the partition configuration. If there are no issues, continue.


Final Writing Confirmation

You're asked for final confirmation to write to the disk. This is the very last check. If you answer Yes here, all data on the disk will be erased.

Terminal Selection (?)


Terminal Selection (?)

I'm not sure if this is the terminal setting for boot time. I'm not really sure. For now, I just pressed RETURN.

Installation


Installation Selection

Select the type of installation. You can choose not to install X11 or keep it to a minimal installation. Here, I selected Full installation.


Selecting the Installation Source

Next, select the source to be used for the installation. This time, everything can be installed from the installation media. Just press RETURN.


Waiting for Installation

Wait for the installation process to complete.


Installation Completed

Once the installation is complete, press RETURN.

Various Settings


Various Settings

Here, you perform various configurations. The tasks, in order from the top, are:

  1. Network configuration
  2. Time zone configuration
  3. Setting the root user's password
  4. Enabling binary package installation
  5. Enabling ntpdate
  6. Enabling xdm
  7. Disabling raidframe
  8. Adding a general user


Configuration Finished

Once the settings are complete, move on to the next step.

Completion of Installation


Completion of Installation

All installation work is now complete. Great job!

Restarting the Computer


Restarting the Computer

You'll return to the initial installation menu, so restart the computer.

Initial Configuration of NetBSD

Login


Login Screen

If the restart is successful, a login screen like the one in the image above will appear. Log in using the general user you created during the installation.


Graphical World

Once you log in successfully, a graphical world like the one in the image above will appear. The window titled uxterm in the top left is the terminal. Enter commands there to operate the computer.

Introducing Various Applications

First, let's install some applications. Since installing applications requires superuser privileges, become the superuser.

Become the superuser
$ su -

Applications can be obtained in the form of packages. To manage packages, use pkgin(1). This works similarly to apt(8) in Debian or Ubuntu.

First, let's install sudo (to temporarily gain administrative privileges), bash (shell), vim-xaw (editor), fetch (file retrieval), w3m (browser), and ja-man (Japanese manual).

Installing applications
# pkgin install sudo bash vim-xaw fetch w3m ja-man

Configuring sudoers

Control which users can use administrative privileges with sudo. Execute the following, and by uncommenting line 82, you allow users in the wheel group to use sudo.

Configuring sudoers
# visudo

Changing the Login Shell

Change the general user's login shell to bash. Executing the following command will open the editor. The login shell setting is on line 10.

Changing the Login Shell
$ which bash
/usr/pkg/bin/bash
# chsh user

You need to log in again for the settings to take effect. Right-click with your mouse on an empty area of the screen and select Quit to log out.

If the terminal prompt looks like the following when you log in again, it's a success.

bash prompt
bash-5.1$ 

Configuring bash

Prepare ~/.bash_profile and ~/.bashrc for bash. This time, I'll use ones stolen from Ubuntu. To apply the settings, log in again.

File Contents
~/.bash_profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
  # include .bashrc if it exists
  if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
  fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
  PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
  PATH="$HOME/.local/bin:$PATH"
fi
~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
  *i*) ;;
  *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
  debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
  xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
  if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    # We have color support; assume it's compliant with Ecma-48
    # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
    # a case would tend to support setf rather than setaf.)
    color_prompt=yes
  else
    color_prompt=
  fi
fi

if [ "$color_prompt" = yes ]; then
  PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
  xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
  *)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
  test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
  alias ls='ls --color=auto'
  alias dir='dir --color=auto'
  alias vdir='vdir --color=auto'

  alias grep='grep --color=auto'
  alias fgrep='fgrep --color=auto'
  alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;\&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
  . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

Using SKK in Vim

Japanese input within the editor is sufficient for my needs. There is a plugin called skk.vim that allows using SKK in Vim, so I'll use that. Execute the following commands:

Installing skk-vim
$ fetch https://github.com/vim-skk/skk.vim/archive/refs/heads/master.zip
$ unzip master.zip
$ mkdir -p ~/.vim/
$ cp -r skk.vim-master/plugin .vim

Now, if you start Vim and press ^J after entering Insert mode, you should be able to input Hiragana. To use Kanji conversion, you need to obtain a dictionary.

Obtaining the dictionary
$ fetch http://openlab.jp/skk/dic/SKK-JISYO.L.gz
$ gzip -dc SKK-JISYO.L.gz >~/SKK-JISYO.L
$ echo 'let g:skk_large_jisyo = "$HOME/SKK-JISYO.L"' >>~/.vimrc
$ echo 'let g:skk_auto_save_jisyo = 1' >>~/.vimrc

This enables Japanese input, including Kanji conversion.

X Configuration

I'm new to X11, so this might be a bit questionable, but it works for me. First, copy ~/.xsession. Originally, the destination should have been ~/.xinitrc, but that didn't work for me.

Copying the file
$ cat /etc/X11/xinit/xinitrc >~/.xsession
$ chmod +x ~/.xsession

Log in again and confirm that the terminal background becomes white. If you find yourself unable to log in, you can either press [Ctrl]+[Return] after entering your password on the login screen, or log in via the console to fix the file.

As it is, the screen is blindingly bright, so I'll change the xterm settings. Create ~/.Xresources. Upon logging in again, you should see the terminal display looking much more vibrant.

~/.Xresources
*xterm*termName:	xterm-256color
*xterm*locale:		true
*xterm*saveLines:	4096

! Molokai Theme
! https://gist.github.com/vreon/845878
*xterm*background:	#101010
*xterm*foreground:	#d0d0d0
*xterm*cursorColor:	#d0d0d0
*xterm*color0:		#101010
*xterm*color1:		#960050
*xterm*color2:		#66aa11
*xterm*color3:		#c47f2c
*xterm*color4:		#30309b
*xterm*color5:		#7e40a5
*xterm*color6:		#3579a8
*xterm*color7:		#9999aa
*xterm*color8:		#303030
*xterm*color9:		#ff0090
*xterm*color10:		#80ff00
*xterm*color11:		#ffba68
*xterm*color12:		#5f5fee
*xterm*color13:		#bb88dd
*xterm*color14:		#4eb4fa
*xterm*color15:		#d0d0d0

Trying Out Shinonome Fonts

Shinonome fonts are public domain bitmap fonts. While you can use TTF fonts, it's more interesting to play around with these. I'll obtain Shinonome fonts compatible with internationalized xterm. Even though they have the grand extension .rpm, the contents are just cpio, so they can be extracted using tar(1).

Obtaining Shinonome fonts
$ fetch http://vega.pgw.jp/~kabe/vsd/shinonome-plus/shinonome-plus-fonts-0.9.12-5.el6.noarch.rpm
$ tar xf shinonome-plus-fonts-0.9.12-5.el6.noarch.rpm
$ sudo mkdir -p /usr/local/share/fonts/shinonome
$    # NOTE: ↓ NOT /usr
$ sudo cp -a usr/share/X11/fonts/shinonome/* /usr/local/share/fonts/shinonome
$ vim ~/.xsession
Insert around line 59:
xset fp+ /usr/local/share/fonts/shinonome


Shinonome Fonts

The image above shows, from back to front: the default font, Shinonome Font Marumoji (12 px), Shinonome Font Gothic (14 px), and Shinonome Font Mincho (16 px).

To set this as the default font for xterm, add the following to ~/.Xresources.

~/.Xresources
! Shinonome Marumoji
*xterm*font:		shnm12maruu

Conclusion

That's it.

This time, I built an environment on a 2 GB USB drive that's enough to play around with NetBSD. No matter how underpowered a machine might be now, it must have been a reasonably usable model when it was first released. Even if it has become a bit of a "potato" machine, it surely still wants to be of use to you. It might be a good idea to take it out of the closet once in a while and play around with it.


References

Discussion