NanoBSD Â²¤¶
Prev |  |

# 2 ¦p¦ó¨Ï¥Î NanoBSD

## 2.1 NanoBSD ªº³]p

¤@¥¹±N¬M¹³ÀÉ¦s¤J´O¤J¦¡µwÅé¡A´N¥i¥H¥Î¥¦¨Ó¤Þ¾É NanoBSD ¤F¡C ¹w³]±¡ªp¤U¡AÀH¨ºÐ·|¹º¤À¬°¤T³¡¤À¡G

- ¨âÓ¬M¹³ÀÉ¤À³Î°Ï¡G `code#1` ©M `code#2`¡C

- ¤@Ó³]©wÀÉ¤À³Î°Ï¡A¦b¹B¦æÀô¹Ò¤¤¡A ¥i¥H±N¨ä±¾¸ü(mount)¨ì `/cfg` ¥Ø¿ý¤U¡C

³o¨Ç¤À³Î°Ï¡A¦b¹w³]±¡ªp¤U¬O¥H°ßÅª¤è¦¡±¾¸ü¡C

`/etc` ©M `/var` ¥Ø¿ý§¡¬° md(4)(malloc)ºÏºÐ¡C

³]©wÀÉªº¤À³Î°Ï«h¬O¦b `/cfg` ¥Ø¿ý¡C ¥¦¥]§t¤F¥Î©ó `/etc` ¥Ø¿ýªºÀÉ®×¡A¦b±Ò°Ê¤§«á¼È®É¥H°ßÅª¤è¦¡±¾¸ü¡C ¦]¦¹¡AY·Qn«¶}¾÷«O¯d·sªº³]©w¡A ¨º»òn°O±o±q `/etc` §â§ï¹LªºÀÉ®×½Æ»s¦^ `/cfg` ¥Ø¿ý¤~¦æ¡C

Example 1. §â×§ï¹L `/etc/resolv.conf` ³]©w«O¦s°_¨Ó

    # vi /etc/resolv.conf
    [...]
    # mount /cfg
    # cp /etc/resolv.conf /cfg
    # umount /cfg

> Note: ¥u¦³¦b¨t²Î±Ò°Ê¹Lµ{¤¤¡A¥H¤Î»Ýn×§ï³]©wÀÉªº®ÉÔ¡A¤~»Ýn±¾¸ü§t¦³ `/cfg` ªº¨ºÓ¤À³Î°Ï¡C

> ¤@ª½³£±¾¸ü `/cfg` ¤£¬O¤@Ó¦n¥D·N¡A¯S§O¬O·í±z§â NanoBSD ©ñ¦b¤£¾A¦X¶i¦æ¤j¶q¼g¤J°Ê§@ªº¤À³Î°Ï®É (¤ñ¦p¡G¥Ñ©óÀÉ®×¨t²Îªº¦P¨B¤Æ·|©w´Á¦b¨t²ÎºÐ¤º¼g¤J¸ê®Æ)¡C

## 2.2 ¥´³y NanoBSD ¬M¹³ÀÉ

NanoBSD ¬M¹³ÀÉ¬O³z¹L¨Ï¥Î«D±`Â²³æªº `nanobsd.sh` shell script ¨Ó¥´³yªº¡A³oÓ script ¥i¥H¦b ``/usr`/src/tools/tools/nanobsd` ¥Ø¿ý¤¤§ä¨ì¡C ³oÓ script «Ø¥ßªº¬M¹³ÀÉ¡A¥i¥H¥Î dd(1) ¤u¨ã¨Ó½Æ»s¨ìÀH¨ºÐ¤W¡C

¥´³y NanoBSD ¬M¹³ÀÉ©Ò»Ýªº«ü¥O¬O¡G

    # cd /usr/src/tools/tools/nanobsd
    # sh nanobsd.sh
    # cd /usr/obj/nanobsd.full
    # dd if=_.disk.full of=/dev/da0 bs=64k

  ¶i¤J NanoBSD ¥´³y script ªº¥D¥Ø¿ý¡C
  ¶}©l¥´³y¹Lµ{¡C
  ¶i¤J¥´³y¦nªº¬M¹³ÀÉ©Ò¦bªº¥Ø¿ý¡C
  ¦bÀH¨ºÐ¤W¦w¸Ë NanoBSD¡C

## 2.3 ¦Û¦æ¥´³y NanoBSD ¬M¹³ÀÉ

³o¥i¯à¬O NanoBSD ³Ì¬°«n¡A ¦P®É¤]¬O±z³Ì·P¿³½ìªº¥\¯à¡C ¦P®É¡A¦b¶}µo NanoBSD À³¥Îµ{¦¡®É¡A³o¤]¬O¬Û·í¯Ó®Éªº¹Lµ{¡C

°õ¦æ¤U±ªº«ü¥O±N·| `nanobsd.sh` Åª¨ú¥Ø«e©Ò¦b¥Ø¿ýªº `myconf.nano` ÀÉªº³]©w¡G

    # sh nanobsd.sh -c myconf.nano

¦Û¦æ¥´³yªº¬yµ{¡A¥u»Ý¨âÓ¨BÆJ¡G

- ¦Ûq¿ï¶µ

- ¦Ûq¥\¯à

### 2.3.1 ¦Ûq¿ï¶µ

³z¹L×§ï³]©w¡A¥i¥H³]©w¥Î©ó NanoBSD ¥´³y¹Lµ{¤¤ `buildworld` ©M `installworld` ¶¥¬qªº½sÄ¶¡B¦w¸Ë¿ï¶µ¡A¥H¤Î NanoBSD ¥Dn¥´³y¹Lµ{¤¤ªº¿ï¶µ¡C ³z¹L¨Ï¥Î³o¨Ç¿ï¶µ¥i¥H«d´î¨t²Îªº¤Ø¤o¡A¨Ï¤§¯à°÷©ñ¤J 64 MB ªºÀH¨ºÐ¡C ±zÁÙ¥i¥H¶i¤@¨B³z¹L³o¨Ç¿ï¶µ¨Ó«d´î FreeBSD¡A ª½¨ì¥¦¥u¥]§t kernel ¥H¤Î¨â¤TÓ userland ÀÉ®×¬°¤î¡C

³]©wÀÉ®×¤¤¥]§t¥Î¥H¥N´À¹w³]Èªº³]©w¿ï¶µ¡CÂ²¤¶³Ì«nªº´X¶µ³]©w¦p¤U¡G

- `NANO_NAME` ¡X¡X ¥»¦¸¥´³yªº¦WºÙ(©Ò«Ø¥ß¤u§@¥Ø¿ýªº¦WºÙ)¡C

- `NANO_SRC` ¡X¡X ¥Î¥H½sÄ¶¡B¥´³y¬M¹³ÀÉªº source tree ªº¦ì¸m¡C

- `NANO_KERNEL` ¡X¡X ³]©w¥Î¨Ó½sÄ¶ªº kernel ³]©wÀÉÀÉ¦W¡C

- `CONF_BUILD` ¡X¡X ¥Î©ó `buildworld` ¥´³y¶¥¬qªº¿ï¶µ¡C

- `CONF_INSTALL` ¡X¡X ¥Î©ó `installworld` ¥´³y¶¥¬qªº¿ï¶µ¡C

- `CONF_WORLD` ¡X¡X ¥Î©ó `buildworld` ©M `installworld` ³o¨âÓ¥´³y¶¥¬qªº¿ï¶µ¡C

- `FlashDevice` ¡X¡X ©w¸q©Ò¥Îªº´O¤J¦¡µwÅéÃþ«¬¡C ¸Ô±¡½Ð°Ñ¦Ò `FlashDevice.sub` ÀÉ¡C

### 2.3.2 ¦Ûq¥\¯à

³z¹L¦b³]©wÀÉ®×¤¤¨Ï¥Î shell ¨ç¼Æ¡A¥i¥H¶i¤@¨B·L½Õ NanoBSD¡C Á|¨Ò»¡©ú¤@¤U¦Û¦æ¥´³y¨ç¼Æªº°ò¥»¤è¦¡¡G

    cust_foo()(
            echo "bar=topless" > \
                    ${NANO_WORLDDIR}/etc/foo
    )
    customize_cmd cust_foo

¤U±Á|§ó¹ê»ÚÂIªº¨Ò¤l¡A¥¦·|§â¹w³]ªº `/etc` ¥Ø¿ý¤j¤p¡A±q 5MB ½Õ¾ã¬° 30MB¡G

    cust_etc_size()(
            cd ${NANO_WORLDDIR}/conf
            echo 30000 > default/etc/md_size
    )
    customize_cmd cust_etc_size

°£¦¹¤§¥~¡AÁÙ¦³´XÓ¹w³]ªº¥\¯à©w¸q¥i¥H¥Î¨Ó¦Ûq¡G

- `cust_comconsole` ¡X¡X ¦b¹w³] VGA Åã¥Ü¥d¤W°±¥Î getty(8) (`/dev/ttyv*`)¨Ã±Ò¥Î serial port ªº COM1 ¥H§@¬°¨t²Î console¡C

- `cust_allow_ssh_root` ¡X¡X ¤¹³\ sshd(8) ¥i¥H¥Î `root` ±b¸¹µn¤J¡C

- `cust_install_files` ¡X¡X ±q `nanobsd/Files` ¥Ø¿ý¤¤¦w¸ËÀÉ®×¡A³o¥]§t¤@¨Ç¹ê¥Îªº¨t²ÎºÞ²z script ¡C

### 2.3.3 ³]©wÀÉ®×Á|¨Ò

¤U±¬O¥Î©ó¦Û¦æ¥´³yªº NanoBSD ¬M¹³ÀÉªº§¹¾ã¨Ò¤l¡G

    NANO_NAME=custom
    NANO_SRC=/usr/src
    NANO_KERNEL=MYKERNEL
    NANO_IMAGES=2

    CONF_BUILD='
    NO_KLDLOAD=YES
    NO_NETGRAPH=YES
    NO_PAM=YES
    '

    CONF_INSTALL='
    NO_ACPI=YES
    NO_BLUETOOTH=YES
    NO_CVS=YES
    NO_FORTRAN=YES
    NO_HTML=YES
    NO_LPR=YES
    NO_MAN=YES
    NO_SENDMAIL=YES
    NO_SHAREDOCS=YES
    NO_EXAMPLES=YES
    NO_INSTALLLIB=YES
    NO_CALENDAR=YES
    NO_MISC=YES
    NO_SHARE=YES
    '

    CONF_WORLD='
    NO_BIND=YES
    NO_MODULES=YES
    NO_KERBEROS=YES
    NO_GAMES=YES
    NO_RESCUE=YES
    NO_LOCALES=YES
    NO_SYSCONS=YES
    NO_INFO=YES
    '

    FlashDevice SanDisk 1G

    cust_nobeastie()(
            touch ${NANO_WORLDDIR}/boot/loader.conf
            echo "beastie_disable=\"YES\"" >> ${NANO_WORLDDIR}/boot/loader.conf
    )

    customize_cmd cust_comconsole
    customize_cmd cust_install_files
    customize_cmd cust_allow_ssh_root
    customize_cmd cust_nobeastie

## 2.4 §ó·s NanoBSD

§ó·s NanoBSD ¬Û¹ï FreeBSD ¦Ó¨¥¸û¬°Â²³æ¡G

1. ©M¤§«e¤@¼Ë¥´³y·sªº NanoBSD ¬M¹³ÀÉ¡C

2. ±N·sªº¬M¹³ÀÉ©ñ¤J¥¿¹B¦æªº NanoBSD ¤¤¥¼¥Îªº¤À³Î°Ï¤§¤@¡C

   »P¤§«e³Ìªì¦w¸Ë NanoBSD ªº¨BÆJ¬Û¤ñ¡A ³o¤@¨BÆJ³Ì«nªº°Ï§O¦b©ó¡G³o¦¸¤£¥Î `_.disk.full` ÀÉ(¥¦¥]§t¾ãÓºÏºÐªº¬M¹³ÀÉ)¡A ¦ÓÀ³¦w¸Ë `_.disk.image` ¬M¹³ÀÉ(³oÓÀÉ®×¤¤¡A¥u¥]§t¤@Ó¨t²Î¤À³Î°Ï)¡C

3. «·s±Ò°Ê¡A¨Ã±q·s¦w¸Ëªº¤À³Î°Ï¤¤±Ò°Ê¨t²Î¡C

4. ¦pªG¤@¤Á¶¶§Qªº¸Ü¡A¤É¯Å¤u§@´N§¹¦¨¤F¡C

5. ¦pªGµo¥Í¤F¥ô¦ó°ÝÃD¡A«h¥i¥H±q¥ý«eªº¤À³Î°Ï±Ò°Ê (¨ä¤¤¥]§t¤FÂÂªº¡B ¥i¥Îªº¬M¹³ÀÉ)¡A¨ÓºÉ§Ö«ì´_¨t²Î¥\¯à¡C ±µ¤U¨Ó¥i¥H×¥¿·s½sÄ¶ªºª©¥»¤¤¦s¦bªº°ÝÃD¡A¨Ã«½Æ«ez¨BÆJ¡C

n¦b¥¿¦b¹B¦æªº NanoBSD ¨t²Î¤¤¦w¸Ë·sªº¬M¹³ÀÉ¡A¥i¥H¨Ï¥Î¦ì©ó `/root` ¥Ø¿ýªº `updatep1` ©Î `updatep2` script ¡A ¹ê»Ú¤Wn¥Îþ¤@Ó script¡A«h¨ú¨M©ó¥¿¦b¹B¦æªº¨t²Î¬O¦ì©óþÓ¤À³Î°Ï¦Ó©w¡C

ÀH®É´£¨Ñ·s NanoBSD ¬M¹³ÀÉ©Ò´£¨ÑªºªA°È¡A ¥H¤Î±Ä¥Îªº¶Ç¿é¤èªkªº¤£¦P¡A±z¥i¥H°Ñ¦Ò¨Ã¨Ï¥Î¤U¦C¤TºØ¤è¦¡¤§¤@¡G

### 2.4.1 ¨Ï¥Î ftp(1)

¦pªG¶Ç¿é³t«×¬O²Ä¤@n¨Dªº¸Ü¡A½Ð±Ä¥Î¤U±¨Ò¤l¡G

    # ftp myhost
    get _.disk.image "| sh updatep1"

### 2.4.2 ¨Ï¥Î ssh(1)

¦pªG·Q§ó¦w¥þªº¸Ü¡AÀ³°Ñ¦Ò¤U±¨Ò¤l¡G

    # ssh myhost cat _.disk.image.gz | zcat | sh updatep1

### 2.4.3 ¨Ï¥Î nc(1)

¦pªG»·µ{¥D¾÷¬J¤£´£¨Ñ ftp(1) ªA°È¡A¤]¤£´£¨Ñ sshd(8) ªA°Èªº¸Ü¡G

1. º¥ý¡A¦b´£¨Ñ¬M¹³ÀÉªº¥D¾÷¤W¶}±Ò TCP listen¡A¨ÃÅý¥¦§â¬M¹³ÀÉ¶Çµ¹ client¡G

       myhost# nc -l 2222 < _.disk.image

   > Note: ½Ð½T»{±z©Ò¨Ï¥Îªº port ¨S¦³³Q¨¾¤õÀðªý¤î¨Ó¦Û NanoBSD client ªº³s½u½Ð¨D¡C

2. ³s¨ì´£¨Ñ·s¬M¹³ÀÉªA°Èªº¥D¾÷¡A¨Ã°õ¦æ `updatep1` ³o¤ä script¡G

       # nc myhost 2222 | sh updatep1

Prev | Home |
NanoBSD Â²¤¶ |  |

¥»¤å¤Î¨ä¥L¤å¥ó¡A¥i¥Ñ¦¹¤U¸ü¡Gftp://ftp.FreeBSD.org/pub/FreeBSD/doc/¡C

Y¦³ FreeBSD ¤è±ºÃ°Ý¡A½Ð¥ý¾\Åª FreeBSD ¬ÛÃö¤å¥ó¡A¦p¤£¯à¸Ñ¨Mªº¸Ü¡A¦A¬¢¸ß <questions@FreeBSD.org>¡C
Ãö©ó¥»¤å¥óªº°ÝÃD¡A½Ð¬¢¸ß <doc@FreeBSD.org>¡C