FreeBSDonUSB

FreeBSD を USBメモリにインストールするメモ

以下の2箇所よりコピペしただけ. まだ未確認.


http://typo.submonkey.net/articles/2006/4/13/installing-freebsd-on-usb-stick-episode-2
より抜粋

Installing FreeBSD on a USB stick, episode II

Posted by Ceri Davies on 4/14/2006

I previously wrote about putting a 6.1-BETA4 FreeBSD installation on a USB stick. Since the bugs that were in the 6.1-BETA4 installation have been fixed, plus to get 6.1-RC1 tested, here are updated instructions (which should work with 6.1-RELEASE as well).

These instructions result in a downloadable image suitable for dding direct to a USB stick of 512MB or larger.

arved pointed out that it's good to minimize the amount of writes done to USB sticks (and flash memory in general), and I've got some pointers in these instructions, but I haven't really looked at this point.

If you are looking to install FreeBSD from a USB stick, you should check out Dario Freni's script. Note

I assume that, like me, you don't have any SCSI disks and so your USB stick will show up on da0, at least while you're preparing it; we're using GEOM disk labels in the image so we don't care so much where the disk appears in the device tree. I'm also assuming that you don't care much for the data on your USB stick. The installation

You'll need to grab the disc1 ISO --- get the latest one.

  • Mount that ISO on /dist:
    # mkdir -p /dist
    # mdconfig -a -f /a/FreeBSD/6.1-RC1-i386-disc1.iso
    md1
    # mount -t cd9660 /dev/md1 /dist
    
  • Insert the stick. They come preformatted with a FAT32 partition on, so we'll need to throw a BSD slice label on there --- this command will destroy all existing slices. If you get a warning regarding "Geom not found", don't worry.:
    # fdisk -BI /dev/da0
    
  • We need a disk label:
    # bsdlabel -B -w da0s1
    
  • and a filesystem, which we'll mount on /mnt. In order to reduce the number of writes to the USB pen, and as common practice, we use the -U flag to enable soft updates. Additionally, so that we can find the filesystem easily no matter where the USB pen appears in the device tree, we will label the filesystem as FreeBSDonUSB:
    # newfs -U -L FreeBSDonUSB /dev/da0s1a
    /dev/da0s1a: 481.0MB (985040 sectors) block size 16384, fragment size 2048
       using 4 cylinder groups of 120.25MB, 7696 blks, 15424 inodes.
       with soft updates
    super-block backups (for fsck -b #) at:
     160, 246432, 492704, 738976
    # mount /dev/da0s1a /mnt
    
  • Now to do an install the blindingly easy way:
    # cd /dist/6.1-RC1/base
    # DESTDIR=/mnt ./install.sh 
    You are about to extract the base distribution into /mnt - are you SURE
    you want to do this over your installed system (y/n)? y
    
  • With 6.1, we are providing both uniprocessor and SMP kernels on the CD. sysinstall will install the correct one depending on your hardware configuration, but we need to decide. It's probably OK to just use the SMP one, but I have no multiprocessor machines, so will use the UP kernel. If you want the SMP kernel, just specify smp where I have generic below:
    # cd /dist/6.1-RC1/kernels
    # DESTDIR=/mnt ./install.sh generic
    # rmdir /mnt/boot/kernel
    # mv /mnt/boot/GENERIC /mnt/boot/kernel
    
  • Install the boot manager. We use the noupdate option to prevent boot0 writing itself back to disk every boot:
    # boot0cfg -v -B -o noupdate da0
    #   flag     start chs   type       end chs       offset         size
    1   0x80      0:  1: 1   0xa5    480: 63:32           32       985056
    version=1.0  drive=0x80  mask=0xf  ticks=182
    options=packet,noupdate,nosetdrv
    default_selection=F1 (Slice 1)
    
  • Create an fstab(5) file on the USB stick. Here's a simple one that puts the logs on to memory storage (to try to minimize writes). We also null mount /var/tmp on /tmp, which makes it non-persistent:
    # Device                Mountpoint      FStype  Options         Dump    Pass#
    /dev/ufs/FreeBSDonUSB   /               ufs     rw,noatime      1       1
    md                      /tmp            mfs     rw,-s16M,nosuid,noatime 0       0
    md                      /var/run        mfs     rw,-s4M,nosuid,noatime  0       0
    md                      /var/log        mfs     rw,-s16M,nosuid,noatime 0       0
    /dev/acd0               /cdrom          cd9660  ro,noauto,nosuid        0       0
    /proc                   /proc           procfs  rw,noauto       0       0
    /tmp                    /var/tmp        nullfs  rw              0       0
    
  • Since we're using the UFS label to define the root filesystem, we must force the GEOM label class to be loaded early:
    # cat >> /mnt/boot/loader.conf << EOF
    geom_label_load="YES"
    EOF
    
  • vi(1) likes to have a /var/tmp/vi.recover around, so we ensure that it exists on boot. Pull down this example script and install it:
    # mkdir -p /mnt/usr/local/etc/rc.d/
    # cd /mnt/usr/local/etc/rc.d/
    # fetch http://people.freebsd.org/~ceri/FreeBSDonUSB/scripts/mkvirecover
    # chmod 555 mkvirecover
    
  • In order for commands that use wtmp(5) to work correctly with /var/log on a memory disk, we need to tell newsyslog(8) that it is OK to create an empty /var/log/wtmp. Edit /mnt/etc/newsyslog.conf and add C to the /var/log/wtmp line:
    /var/log/wtmp                          644  3     *    @01T05 BC
    
  • Set the interfaces to configure themselves over DHCP. I exclude plip0 and fwe0 since they are practically never connected to a DHCP server, but are reasonably common:
    # cat >> /etc/rc.conf << EOF
    ifconfig_DEFAULT="DHCP"
    ifconfig_fwe0="NOAUTO"
    ifconfig_plip0="NOAUTO"
    EOF
    
  • Again, to reduce the number of writes to the USB key, we will pregenerate a locate database and then turn off the weekly update:
    # chroot /mnt /bin/sh
    # mount_devfs devfs /dev
    # /etc/periodic/weekly/310.locate
    
    Rebuilding locate database:
    # cat >> /etc/periodic.conf << EOF
    weekly_locate_enable="NO"
    weekly_whatis_enable="NO"
    EOF
    
  • Install any packages you might want, and set a root password:
    # chroot /mnt /bin/sh
    # passwd root
    # pkg_add -r lsof rsync unzip zsh kde...
    

That's it for now.


http://www.karashi.org/~poppen/d/20071214.html#p01
より抜粋

ただ、上記サイトのやり方だと、/homeがUSBメモリ上にあるので、/homeでばんばん作業をする必要がある時には、メディアの寿命が心配ということで、/homeもMFSにすることにした。

以下は作業内容。すべてUSBにインストールしたFreeBSDに対して行なう。

  1. /etc/fstabに下記の内容を追記する。
    • md /home mfs rw,-s16M,nosuid,noatime 0 0
  2. populate-home(この日記の最後に内容は書いた)をインストールする。
    • cp populate-home /usr/local/etc/rc.d
    • chmod 0555 /usr/local/etc/rc.d/populate-home
  3. /etc/rc.confに、下記の内容を追記する。
    • populate_home_enable="YES"
  4. 起動時にhomeディレクトリにコピーされるファイルを準備する。
    • mkdir -p /etc/home/ユーザ名
    • homeディレクトリに置くファイル群(dotファイルとか)をレポジトリからcheckoutするなり、コピーするなりして、手元に用意する。
    • cp 上記のファイル /etc/home/ユーザ名
    • chown -R ユーザ名 /etc/home/ユーザ名

populate-homeスクリプトの内容は下記の通り。

#!/bin/sh

# PROVIDE: populate_home
# REQUIRE: mountcritremote
# BEFORE:  DAEMON

. /etc/rc.subr

populate_home_enable=${populate_home_enable-"NO"}
populate_home_data=${populate_home_data-"/etc/home"}

name="populate_home"
rcvar=`set_rcvar`

stop_cmd=":"
start_cmd="populate_home_start"

populate_home_start()
{
        if [ -d ${populate_home_data} ]; then
                cd ${populate_home_data}
                /usr/bin/find . -print | /usr/bin/cpio -dump --quiet /home
        fi
        echo '.'
}

load_rc_config "$name"
run_rc_command "$1"

上記の作業で、MFSの/home(容量は16MB)が起動時にmountされ、/etc/homeの内容が/homeにコピーされる。

populate-homeのPROVIDEやREQUIRE、BEFOREあたりはちと自信がないんだけど、 とりあえず、手元の環境では動いている。