2012年3月6日火曜日

[Solaris] Minimal OpenIndiana oi151a

Creating minimal OpenIndiana VMware VM.

(1) Boot VM from OpenIndiana Build 151a Server CD.
(2) Select "Shell" in installation menu.
(3) Search HDD.
root@openindiana:/root# format < /dev/null
Searching for disks...done


AVAILABLE DISK SELECTIONS:
       0. c3t0d0 
          /pci@0,0/pci15ad,1976@10/sd@0,0
Specify disk (enter its number):
=> c3t0d0

(4) Partitioning.

Allocate all cylinders except cylinder 0 to slice 0 for rpool.

root@openindiana:/root# fdisk -n -B /dev/rdsk/c3t0d0p0

root@openindiana:/root# format /dev/rdsk/c3t0d0p0
selecting /dev/rdsk/c3t0d0p0
[disk formatted]


FORMAT MENU:
        disk       - select a disk
        type       - select (define) a disk type
        partition  - select (define) a partition table
        current    - describe the current disk
        format     - format and analyze the disk
        fdisk      - run the fdisk program
        repair     - repair a defective sector
        label      - write label to the disk
        analyze    - surface analysis
        defect     - defect list management
        backup     - search for backup labels
        verify     - read and display labels
        save       - save new disk/partition definitions
        inquiry    - show vendor, product and revision
        volname    - set 8-character volume name
        !     - execute , then return
        quit
format> partition


PARTITION MENU:
        0      - change `0' partition
        1      - change `1' partition
        2      - change `2' partition
        3      - change `3' partition
        4      - change `4' partition
        5      - change `5' partition
        6      - change `6' partition
        7      - change `7' partition
        select - select a predefined table
        modify - modify a predefined partition table
        name   - name the current table
        print  - display the current table
        label  - write partition map and label to the disk
        ! - execute , then return
        quit
partition> print
Current partition table (original):
Total disk cylinders available: 2085 + 2 (reserved cylinders)

Part      Tag    Flag     Cylinders        Size            Blocks
  0 unassigned    wm       0               0         (0/0/0)           0 <= Here!
  1 unassigned    wm       0               0         (0/0/0)           0
  2     backup    wu       0 - 2084       15.97GB    (2085/0/0) 33495525
  3 unassigned    wm       0               0         (0/0/0)           0
  4 unassigned    wm       0               0         (0/0/0)           0
  5 unassigned    wm       0               0         (0/0/0)           0
  6 unassigned    wm       0               0         (0/0/0)           0
  7 unassigned    wm       0               0         (0/0/0)           0
  8       boot    wu       0 -    0        7.84MB    (1/0/0)       16065
  9 unassigned    wm       0               0         (0/0/0)           0

partition> 0
Part      Tag    Flag     Cylinders        Size            Blocks
  0 unassigned    wm       0               0         (0/0/0)           0

Enter partition id tag[unassigned]: root
Enter partition permission flags[wm]: wm
Enter new starting cyl[1]: 1
Enter partition size[0b, 0c, 1e, 0.00mb, 0.00gb]: 2084c
partition> p
Current partition table (unnamed):
Total disk cylinders available: 2085 + 2 (reserved cylinders)

Part      Tag    Flag     Cylinders        Size            Blocks
  0       root    wm       1 - 2084       15.96GB    (2084/0/0) 33479460
  1 unassigned    wm       0               0         (0/0/0)           0
  2     backup    wu       0 - 2084       15.97GB    (2085/0/0) 33495525
  3 unassigned    wm       0               0         (0/0/0)           0
  4 unassigned    wm       0               0         (0/0/0)           0
  5 unassigned    wm       0               0         (0/0/0)           0
  6 unassigned    wm       0               0         (0/0/0)           0
  7 unassigned    wm       0               0         (0/0/0)           0
  8       boot    wu       0 -    0        7.84MB    (1/0/0)       16065
  9 unassigned    wm       0               0         (0/0/0)           0

partition> label
Ready to label disk, continue? y

partition> quit


FORMAT MENU:
        disk       - select a disk
        type       - select (define) a disk type
        partition  - select (define) a partition table
        current    - describe the current disk
        format     - format and analyze the disk
        fdisk      - run the fdisk program
        repair     - repair a defective sector
        label      - write label to the disk
        analyze    - surface analysis
        defect     - defect list management
        backup     - search for backup labels
        verify     - read and display labels
        save       - save new disk/partition definitions
        inquiry    - show vendor, product and revision
        volname    - set 8-character volume name
        !     - execute , then return
        quit

format> quit

(5) Create rpool.

root@openindiana:/root# zpool create -f rpool c3t0d0s0

(6) Create filesystems.

root@openindiana:/root# zfs create -o mountpoint=legacy rpool/ROOT
root@openindiana:/root# zfs create -o mountpoint=/ -o canmount=noauto rpool/ROOT/mini
root@openindiana:/root# zfs create -b 4096 -V 512m rpool/swap
root@openindiana:/root# zfs create -b $(( 128 * 1024 )) -V 512m rpool/dump

(7) BE mount

root@openindiana:/root# beadm mount mini /work
Mounted successfully on: '/work'

(8) Create IPS image.

root@openindiana:/root# pkg image-create --force --full --publisher openindiana.org=http://pkg.openindiana.org/dev-il /work
root@openindiana:/root# pkg -R /work set-property flush-content-cache-on-success True

(9) Install packages.

First of all, install SUNWcsd.

root@openindiana:/root# pkg -R /work install pkg:/SUNWcsd
               Packages to install:    72
           Create boot environment:    No
               Services to restart:     3
DOWNLOAD                                  PKGS       FILES    XFER (MB)
Completed                                72/72 26140/26140  151.9/151.9

PHASE                                        ACTIONS
Install Phase                            37719/37719

PHASE                                          ITEMS
Package State Update Phase                     72/72
Image State Update Phase                         2/2

PHASE                                          ITEMS
Reading Existing Index                           8/8
Indexing Packages                              72/72
Indexing Packages                              72/72
Optimizing Index...

PHASE                                          ITEMS
Indexing Packages                              72/72
Deleting content cache

root@openindiana:/root# pkg -R /work list
NAME (PUBLISHER)                              VERSION         STATE      UFOXI
SUNWcs                                        0.5.11-0.151.1  installed  -----
SUNWcsd                                       0.5.11-0.151.1  installed  -----
compress/bzip2                                1.0.6-0.151.1   installed  -----
consolidation/X/X-incorporation               0.5.11-0.151.1  installed  -----
consolidation/admin/admin-incorporation       0.5.11-0.151.1  installed  -----
consolidation/gnome/gnome-incorporation       0.5.11-0.151.1  installed  -----
consolidation/l10n/l10n-incorporation         0.5.11-0.151.1  installed  -----
consolidation/osnet/osnet-incorporation       0.5.11-0.151.1  installed  -----
consolidation/sfw/sfw-incorporation           0.5.11-0.151.1  installed  -----
consolidation/sic_team/sic_team-incorporation 0.5.11-0.151.1  installed  -----
consolidation/solaris_re/solaris_re-incorporation 0.5.11-0.151.1  installed  -----
consolidation/sunpro/sunpro-incorporation     0.5.11-0.151.1  installed  -----
database/sqlite-3                             3.6.23-0.151.1  installed  -----
driver/audio                                  0.5.11-0.151.1  installed  -----
driver/serial/usbser                          0.5.11-0.151.1  installed  -----
driver/usb                                    0.5.11-0.151.1  installed  -----
install/beadm                                 0.5.11-0.151.1  installed  -----
library/libffi                                0.5.11-0.151.1  installed  -----
library/libtecla                              1.6.0-0.151.1   installed  -----
library/libxml2                               2.7.6-0.151.1   installed  -----
library/ncurses                               0.5.11-0.151.1  installed  -----
library/nspr                                  0.5.11-0.151.1  installed  -----
library/readline                              5.2-0.151.1     installed  -----
library/security/openssl                      0.9.8.15-0.151.1 installed  -----
library/security/trousers                     0.3.4-0.151.1   installed  -----
library/zlib                                  1.2.3-0.151.1   installed  -----
package/svr4                                  0.5.11-0.151.1  installed  -----
release/name                                  0.5.11-0.151.1  installed  -----
runtime/perl-510                              5.10.0-0.151.1  installed  -----
runtime/perl-510/extra                        5.10.0-0.151.1  installed  -----
runtime/perl-510/module/sun-solaris           0.5.11-0.151.1  installed  -----
runtime/python-26                             2.6.4-0.151.1   installed  -----
runtime/tcl-8                                 8.4.18-0.151.1  installed  -----
runtime/tk-8                                  8.4.18-0.151.1  installed  -----
service/fault-management                      0.5.11-0.151.1  installed  -----
service/file-system/smb                       0.5.11-0.151.1  installed  -----
service/management/sysidtool                  0.5.11-0.151.1  installed  -----
service/picl                                  0.5.11-0.151.1  installed  -----
service/resource-pools                        0.5.11-0.151.1  installed  -----
service/security/gss                          0.5.11-0.151.1  installed  -----
service/security/kerberos-5                   0.5.11-0.151.1  installed  -----
shell/bash                                    4.0.28-0.151.1  installed  -----
storage/svm                                   0.5.11-0.151.1  installed  -----
system/boot/grub                              0.97-0.151.1    installed  -----
system/boot/wanboot                           0.5.11-0.151.1  installed  -----
system/data/keyboard/keytables                0.5.11-0.151.1  installed  -----
system/data/terminfo                          0.5.11-0.151.1  installed  -----
system/data/zoneinfo                          2011.13-0.151.1 installed  -----
system/file-system/smb                        0.5.11-0.151.1  installed  -----
system/file-system/zfs                        0.5.11-0.151.1  installed  -----
system/kernel                                 0.5.11-0.151.1  installed  -----
system/kernel/platform                        0.5.11-0.151.1  installed  -----
system/kernel/ultra-wideband                  0.5.11-0.151.1  installed  -----
system/library                                0.5.11-0.151.1  installed  -----
system/library/iconv/utf-8                    0.5.11-0.151.1  installed  -----
system/library/install                        0.5.11-0.151.1  installed  -----
system/library/libdiskmgt                     0.5.11-0.151.1  installed  -----
system/library/math                           0.5.11-0.151.1  installed  -----
system/library/mozilla-nss                    0.5.11-0.151.1  installed  -----
system/library/security/gss                   0.5.11-0.151.1  installed  -----
system/library/security/gss/diffie-hellman    0.5.11-0.151.1  installed  -----
system/library/security/gss/spnego            0.5.11-0.151.1  installed  -----
system/library/security/libsasl               0.5.11-0.151.1  installed  -----
system/library/storage/scsi-plugins           0.5.11-0.151.1  installed  -----
system/management/snmp/net-snmp               5.4.1-0.151.1   installed  -----
system/management/snmp/sea/sea-config         0.5.11-0.151.1  installed  -----
system/zones                                  0.5.11-0.151.1  installed  -----
x11/header/x11-protocols                      7.5-0.151.1     installed  -----
x11/library/libx11                            1.3.5-0.151.1   installed  -----
x11/library/libxau                            1.0.6-0.151.1   installed  -----
x11/library/libxdmcp                          1.0.3-0.151.1   installed  -----
x11/library/libxext                           1.1.2-0.151.1   installed  -----

Install additional packages.
root@openindiana:/root# echo 'pkg:/archiver/gnu-tar
pkg:/compatibility/ucb
pkg:/consolidation/ips/ips-incorporation
pkg:/crypto/ca-certificates
pkg:/developer/linker
pkg:/driver/i86pc/platform
pkg:/driver/network/e1000g
pkg:/driver/network/elxl
pkg:/driver/network/iprb
pkg:/driver/network/pcn
pkg:/driver/network/platform
pkg:/driver/storage/ahci
pkg:/driver/storage/ata
pkg:/editor/vim
pkg:/file/gnu-coreutils
pkg:/library/gmp
pkg:/library/libidn
pkg:/library/pcre
pkg:/library/python-2/cherrypy
pkg:/library/python-2/m2crypto
pkg:/library/python-2/mako
pkg:/library/python-2/ply
pkg:/library/python-2/pybonjour
pkg:/library/python-2/pycurl
pkg:/library/python-2/pyopenssl-26
pkg:/library/python-2/simplejson-26
pkg:/locale/en
pkg:/network/bridging
pkg:/network/ftp
pkg:/network/ipfilter
pkg:/network/ssh
pkg:/network/ssh/ssh-key
pkg:/package/pkg
pkg:/service/network/dns/mdns
pkg:/service/network/ssh
pkg:/system/boot/real-mode
pkg:/system/extended-system-utilities
pkg:/system/library/c++/sunpro
pkg:/system/library/platform
pkg:/system/library/processor
pkg:/system/library/sysidtool
pkg:/system/management/sysidtool
pkg:/system/network
pkg:/system/xopen/xcu4
pkg:/system/xopen/xcu6
pkg:/text/gawk
pkg:/text/gnu-grep
pkg:/text/gnu-sed
pkg:/text/less
pkg:/text/locale
pkg:/web/curl
' | xargs pkg -R /work install
               Packages to install:    51
           Create boot environment:    No
               Services to restart:     1
DOWNLOAD                                  PKGS       FILES    XFER (MB)
Completed                                51/51   3905/3905    26.5/26.5

PHASE                                        ACTIONS
Install Phase                              5900/5900

PHASE                                          ITEMS
Package State Update Phase                     51/51
Image State Update Phase                         2/2

PHASE                                          ITEMS
Reading Existing Index                           8/8
Indexing Packages                              51/51
Indexing Packages                              51/51
Optimizing Index...

PHASE                                          ITEMS
Indexing Packages                            123/123
Deleting content cache

All installed packages.
root@openindiana:/root# pkg -R /work list
NAME (PUBLISHER)                              VERSION         STATE      UFOXI
SUNWcs                                        0.5.11-0.151.1  installed  -----
SUNWcsd                                       0.5.11-0.151.1  installed  -----
archiver/gnu-tar                              1.23-0.151.1    installed  -----
compatibility/ucb                             0.5.11-0.151.1  installed  -----
compress/bzip2                                1.0.6-0.151.1   installed  -----
consolidation/X/X-incorporation               0.5.11-0.151.1  installed  -----
consolidation/admin/admin-incorporation       0.5.11-0.151.1  installed  -----
consolidation/gnome/gnome-incorporation       0.5.11-0.151.1  installed  -----
consolidation/ips/ips-incorporation           0.5.11-0.151.1  installed  -----
consolidation/l10n/l10n-incorporation         0.5.11-0.151.1  installed  -----
consolidation/osnet/osnet-incorporation       0.5.11-0.151.1  installed  -----
consolidation/sfw/sfw-incorporation           0.5.11-0.151.1  installed  -----
consolidation/sic_team/sic_team-incorporation 0.5.11-0.151.1  installed  -----
consolidation/solaris_re/solaris_re-incorporation 0.5.11-0.151.1  installed  -----
consolidation/sunpro/sunpro-incorporation     0.5.11-0.151.1  installed  -----
crypto/ca-certificates                        0.5.11-0.151.1  installed  -----
database/sqlite-3                             3.6.23-0.151.1  installed  -----
developer/linker                              0.5.11-0.151.1  installed  -----
driver/audio                                  0.5.11-0.151.1  installed  -----
driver/i86pc/platform                         0.5.11-0.151.1  installed  -----
driver/network/e1000g                         0.5.11-0.151.1  installed  -----
driver/network/elxl                           0.5.11-0.151.1  installed  -----
driver/network/iprb                           0.5.11-0.151.1  installed  -----
driver/network/pcn                            0.5.11-0.151.1  installed  -----
driver/network/platform                       0.5.11-0.151.1  installed  -----
driver/serial/usbser                          0.5.11-0.151.1  installed  -----
driver/storage/ahci                           0.5.11-0.151.1  installed  -----
driver/storage/ata                            0.5.11-0.151.1  installed  -----
driver/usb                                    0.5.11-0.151.1  installed  -----
editor/vim                                    7.2.308-0.151.1 installed  -----
file/gnu-coreutils                            8.5-0.151.1     installed  -----
install/beadm                                 0.5.11-0.151.1  installed  -----
library/gmp                                   4.3.1-0.151.1   installed  -----
library/libffi                                0.5.11-0.151.1  installed  -----
library/libidn                                1.9-0.151.1     installed  -----
library/libtecla                              1.6.0-0.151.1   installed  -----
library/libxml2                               2.7.6-0.151.1   installed  -----
library/ncurses                               0.5.11-0.151.1  installed  -----
library/nspr                                  0.5.11-0.151.1  installed  -----
library/pcre                                  7.8-0.151.1     installed  -----
library/python-2/cherrypy                     3.1.2-0.151.1   installed  -----
library/python-2/m2crypto                     0.20.0-0.151.1  installed  -----
library/python-2/mako                         0.2.2-0.151.1   installed  -----
library/python-2/ply                          3.1-0.151.1     installed  -----
library/python-2/pybonjour                    1.1.1-0.151.1   installed  -----
library/python-2/pycurl                       7.19.0.1-0.151.1 installed  -----
library/python-2/pyopenssl-26                 0.8-0.151.1     installed  -----
library/python-2/simplejson-26                0.5.11-0.151.1  installed  -----
library/readline                              5.2-0.151.1     installed  -----
library/security/openssl                      0.9.8.15-0.151.1 installed  -----
library/security/trousers                     0.3.4-0.151.1   installed  -----
library/zlib                                  1.2.3-0.151.1   installed  -----
locale/en                                     0.5.11-0.151.1  installed  -----
network/bridging                              0.5.11-0.151.1  installed  -----
network/ftp                                   0.5.11-0.151.1  installed  -----
network/ipfilter                              0.5.11-0.151.1  installed  -----
network/ssh                                   0.5.11-0.151.1  installed  -----
network/ssh/ssh-key                           0.5.11-0.151.1  installed  -----
package/pkg                                   0.5.11-0.151.1  installed  -----
package/svr4                                  0.5.11-0.151.1  installed  -----
release/name                                  0.5.11-0.151.1  installed  -----
runtime/perl-510                              5.10.0-0.151.1  installed  -----
runtime/perl-510/extra                        5.10.0-0.151.1  installed  -----
runtime/perl-510/module/sun-solaris           0.5.11-0.151.1  installed  -----
runtime/python-26                             2.6.4-0.151.1   installed  -----
runtime/tcl-8                                 8.4.18-0.151.1  installed  -----
runtime/tk-8                                  8.4.18-0.151.1  installed  -----
service/fault-management                      0.5.11-0.151.1  installed  -----
service/file-system/smb                       0.5.11-0.151.1  installed  -----
service/management/sysidtool                  0.5.11-0.151.1  installed  -----
service/network/dns/mdns                      0.5.11-0.151.1  installed  -----
service/network/ssh                           0.5.11-0.151.1  installed  -----
service/picl                                  0.5.11-0.151.1  installed  -----
service/resource-pools                        0.5.11-0.151.1  installed  -----
service/security/gss                          0.5.11-0.151.1  installed  -----
service/security/kerberos-5                   0.5.11-0.151.1  installed  -----
shell/bash                                    4.0.28-0.151.1  installed  -----
storage/svm                                   0.5.11-0.151.1  installed  -----
system/boot/grub                              0.97-0.151.1    installed  -----
system/boot/real-mode                         0.5.11-0.151.1  installed  -----
system/boot/wanboot                           0.5.11-0.151.1  installed  -----
system/data/keyboard/keytables                0.5.11-0.151.1  installed  -----
system/data/terminfo                          0.5.11-0.151.1  installed  -----
system/data/zoneinfo                          2011.13-0.151.1 installed  -----
system/extended-system-utilities              0.5.11-0.151.1  installed  -----
system/file-system/smb                        0.5.11-0.151.1  installed  -----
system/file-system/zfs                        0.5.11-0.151.1  installed  -----
system/kernel                                 0.5.11-0.151.1  installed  -----
system/kernel/platform                        0.5.11-0.151.1  installed  -----
system/kernel/ultra-wideband                  0.5.11-0.151.1  installed  -----
system/library                                0.5.11-0.151.1  installed  -----
system/library/c++/sunpro                     0.5.11-0.151.1  installed  -----
system/library/iconv/utf-8                    0.5.11-0.151.1  installed  -----
system/library/install                        0.5.11-0.151.1  installed  -----
system/library/libdiskmgt                     0.5.11-0.151.1  installed  -----
system/library/math                           0.5.11-0.151.1  installed  -----
system/library/mozilla-nss                    0.5.11-0.151.1  installed  -----
system/library/platform                       0.5.11-0.151.1  installed  -----
system/library/processor                      0.5.11-0.151.1  installed  -----
system/library/security/gss                   0.5.11-0.151.1  installed  -----
system/library/security/gss/diffie-hellman    0.5.11-0.151.1  installed  -----
system/library/security/gss/spnego            0.5.11-0.151.1  installed  -----
system/library/security/libsasl               0.5.11-0.151.1  installed  -----
system/library/storage/scsi-plugins           0.5.11-0.151.1  installed  -----
system/library/sysidtool                      0.5.11-0.151.1  installed  -----
system/management/snmp/net-snmp               5.4.1-0.151.1   installed  -----
system/management/snmp/sea/sea-config         0.5.11-0.151.1  installed  -----
system/management/sysidtool                   0.5.11-0.151.1  installed  -----
system/network                                0.5.11-0.151.1  installed  -----
system/xopen/xcu4                             0.5.11-0.151.1  installed  -----
system/xopen/xcu6                             0.5.11-0.151.1  installed  -----
system/zones                                  0.5.11-0.151.1  installed  -----
text/gawk                                     3.1.5-0.151.1   installed  -----
text/gnu-grep                                 2.5.4-0.151.1   installed  -----
text/gnu-sed                                  4.2.1-0.151.1   installed  -----
text/less                                     436-0.151.1     installed  -----
text/locale                                   0.5.11-0.151.1  installed  -----
web/curl                                      7.21.1-0.151.1  installed  -----
x11/header/x11-protocols                      7.5-0.151.1     installed  -----
x11/library/libx11                            1.3.5-0.151.1   installed  -----
x11/library/libxau                            1.0.6-0.151.1   installed  -----
x11/library/libxdmcp                          1.0.3-0.151.1   installed  -----
x11/library/libxext                           1.1.2-0.151.1   installed  -----

(10) Setup SMF.

root@openindiana:/root# cp /work/lib/svc/seed/global.db /work/etc/svc/repository.db
root@openindiana:/root# chmod 0600 /work/etc/svc/repository.db

root@openindiana:/root# ln -s generic_limited_net.xml /work/etc/svc/profile/generic.xml
root@openindiana:/root# ln -s inetd_generic.xml /work/etc/svc/profile/inetd_services.xml
root@openindiana:/root# ln -s ns_dns.xml /work/etc/svc/profile/name_service.xml
root@openindiana:/root# ln -s platform_none.xml /work/etc/svc/profile/platform.xml

(11) Timezone/locale/hostname/root password/Keyboard

Keyboard
root@openindiana:/root# echo LAYOUT=Japanese > /work/etc/default/kbd

Timezone
root@openindiana:/root# /usr/gnu/bin/sed -i -e 's/TZ=.*/TZ=Japan/' /work/etc/default/init

Locale
root@openindiana:/root# echo 'LANG=en_US.UTF-8' >> /work/etc/default/init

Hostname
root@openindiana:/root# echo minioi > /work/etc/nodename

root password
root@openindiana:/root# /usr/gnu/bin/grep '^root:' /etc/shadow
root:$5$d.$K0QnLFEbK0DhPxb4wjqRsQNmjQdHqNZdV4MgWEnLRT8:6445::::::
root@openindiana:/root# sed -i -e 's/^root::/root:$5$d.$K0QnLFEbK0DhPxb4wjqRsQNmjQdHqNZdV4MgWEnLRT8:/' /work/etc/shadow

(12) Swap, dump

root@openindiana:/root# echo "/dev/zvol/dsk/rpool/swap\t-\t-\tswap\t-\tno\t-" >> /work/etc/vfstab

root@openindiana:/root# echo 'DUMPADM_DEVICE=/dev/zvol/dsk/rpool/dump
DUMPADM_SAVDIR=/var/crash
DUMPADM_CONTENT=kernel
DUMPADM_ENABLE=yes
DUMPADM_CSAVE=on
' > /work/etc/dumpadm.conf

(13) Devlinks

root@openindiana:/root# devfsadm -r /work

(14) Grub setting.

root@openindiana:/root# /work/boot/solaris/bin/update_grub -R /work
Creating GRUB menu in /work
bootadm: cannot find GRUB menu file: /rpool/boot/grub/menu.lst
Installing grub on /dev/rdsk/c3t0d0s0
stage2 written to partition 0, 275 sectors starting at 50 (abs 16115)
stage1 written to partition 0 sector 0 (abs 16065)

root@openindiana:/root# mkdir -p /rpool/boot/grub
root@openindiana:/root# echo 'default 0
timeout 10

title Mini OpenIndiana
findroot (pool_rpool,0,a)
bootfs rpool/ROOT/mini
kernel$ /platform/i86pc/kernel/$ISADIR/unix -B $ZFS-BOOTFS
module$ /platform/i86pc/$ISADIR/boot_archive
' > /rpool/boot/grub/menu.lst

root@openindiana:/root# mkdir /rpool/boot/grub/bootsign
root@openindiana:/root# touch /rpool/boot/grub/bootsign/pool_rpool

root@openindiana:/root# zpool set bootfs=rpool/ROOT/mini rpool

(15) Create boot archive

root@openindiana:/root# bootadm update-archive -R /work
updating /work//platform/i86pc/boot_archive
updating /work//platform/i86pc/amd64/boot_archive

(16) Finish

root@openindiana:/root# beadm umount mini
Unmounted successfully
root@openindiana:/root# zpool export rpool

root@openindiana:/root# cp /usr/sbin/reboot /tmp
root@openindiana:/root# eject; /tmp/reboot
cdrom /dev/dsk/c2t0d0s2 ejected

2011年5月3日火曜日

[Python] while True と while 1

while True と while 1 では結構性能が違う。

Python 2.7.1 on win32
>>> import timeit
>>>
>>> stmt1 = """
... i = 0
... while True:
...     i += 1
...     if i > 100:
...             break
... """
>>> stmt2 = """
... i = 0
... while 1:
...     i += 1
...     if i > 100:
...             break
... """
>>> t1 = timeit.Timer(stmt = stmt1)
>>> t2 = timeit.Timer(stmt = stmt2)
>>> t1.timeit()
8.104886514906184
>>> t2.timeit()
5.19364556109781
>>>

while 1 のほうが速い。

2011年1月12日水曜日

[CherryPy] Hello world

Solaris11 ExpressのCherryPy 3.1.2でhello world。

#!/usr/bin/env python
# coding: utf-8
import cherrypy

class Root:
        @cherrypy.expose
        def index(self):
                return "Hello, world"

# IN6ADDR_ANY(::) で LISTEN
cherrypy.server.socket_host = "::"
cherrypy.quickstart(Root())

ほぉほぉ。

2010年11月3日水曜日

[Python, Solaris] pynvpairにnvlistのイテレータ追加

pynvpairにnvlist_next_nvpair()を使ったイテレータを追加したのでforでまわせるようになった。

nvlist_print()の代替実装例。

def nvlist_print(nvlist, indent = 0):
    for type, name, value in nvlist:
        if not isinstance(value, list):
            if type == DATA_TYPE_NVLIST:
                print "%s%s:" % (" " * indent, name)
                nvlist_print(value, indent + 4)
            else:
                print "%s%s: %s" % (" " * indent, name, value)
        else:
            print "%s%s:" % (" " * indent, name)
            indent2 = indent + 4
            for i, v in enumerate(value):
                if type == DATA_TYPE_NVLIST_ARRAY:
                    print "%s[%d]:" % (" " * indent2, i)
                    nvlist_print(v, indent2 + 4)
                else:
                    print "%s[%d]: %s" % (" " * indent2, i, v)

2010年11月1日月曜日

[Python, Solaris] libnvpairのpythonインタフェース

OpenSolaris動作するlibnvpairのpythonインタフェース。
b134で動作確認。

こんな感じ。
>>> from pynvpair import *
>>>
>>> a = nvlist()
>>> a.add(DATA_TYPE_UINT64_ARRAY, "test", (0, 100, 12345))
>>> a.dump()
test[0]: 0
test[1]: 100
test[2]: 12345
>>> a.lookup(DATA_TYPE_UINT64_ARRAY, "test")
[0L, 100L, 12345L]
>>> 
何かに使えそう。 

2010年10月24日日曜日

[Python] 例外処理とif...elseのコスト

例えば、あるループ中にあるシーケンスの要素を参照するとき。
for i in range(10):
    value = a[i]
これだと、インデックスiが有効かどうかわからないのでどうにかしたい。

(例1)
とりあえず長さをチェックして参照する。
for i in range(10):
    if i < len(a):
        value = a[i]
これはループで毎回len(a)するのでいかにも遅そう。

(例2)
シーケンスの長さが変わらないのであればループの前にあらかじめ長さをとっておこう。
alen = len(a)
for i in range(10):
    if i < alen:
        value = a[i]

(例3)
とりあえず参照して例外を拾おう。
for i in range(10):
    try:
        value = a[i]
    except IndexError:
        pass

どれを使うのがよさげなのか計ってみよう。

テスト用スクリプト
#!/usr/bin/env python
import timeit

# インデックスiが範囲内の場合のセットアップ
setup1 = """
a = [ 1, 2, 3 ]
alen = len(a)
i = 1
"""

# インデックスiが範囲外の場合のセットアップ
setup2 = """
a = [ 1, 2, 3 ]
alen = len(a)
i = 5
"""

# 例1用ステートメント
stmt1 = """
if i < len(a):
    a[i]
else:
    pass
"""

# 例2用ステートメント
stmt2 = """
if i < alen:
    a[i]
else:
    pass
"""

# 例3用ステートメント
stmt3 = """
try:
    a[i]
except IndexError:
    pass
"""

print timeit.Timer(setup = setup1, stmt = stmt1).timeit()
print timeit.Timer(setup = setup1, stmt = stmt2).timeit()
print timeit.Timer(setup = setup1, stmt = stmt3).timeit()
print timeit.Timer(setup = setup2, stmt = stmt1).timeit()
print timeit.Timer(setup = setup2, stmt = stmt2).timeit()
print timeit.Timer(setup = setup2, stmt = stmt3).timeit()
実行結果
# インデックスが範囲内
0.361014127731 # 例1
0.125293016434 # 例2
0.128052949905 # 例3
# インデックスが範囲外
0.284233808517 # 例1
0.101886034012 # 例2
1.82788801193  # 例3

例外処理で実装した場合(例3)のインデックスが範囲外になる時が飛びぬけて遅い。
つまり、例外発生のコストは結構大きい。
例外発生が頻繁に発生することが予測される場合、if...elseで簡単に
代替できるのであればif...elseを使ったほうが高速。

[expect] spawnしたプロセスの終了ステータスを得る

spawnしたプロセスの終了ステータスを得たいことがある。
この場合はwaitでプロセスの終了を待つと、結果が返ってくる。
結果はリストになっていて3番目(インデックス2)が-1の場合は
OSエラー、0の場合は4番目(インデックス3)にswawnしたプロセスの
終了ステータスが入っている。

スクリプトの例。読み取り権のないファイルをcatして終了ステータスを得る。
spawn cat /etc/shadow
expect eof
catch wait result
set OS_ERROR [ lindex $result 2 ]
if { $OS_ERROR == -1 } {
        puts "Fail to exec"
        exit 127
}
set STATUS [ lindex $result 3 ]
exit $STATUS
スクリプト自体をcatの終了ステータスで終了する。


実行結果
$ expect test.expect
spawn cat /etc/shadow
cat: /etc/shadow: Permission denied
$ echo $?
1
きちんと1が返っている。

expectはTcl言語の文法を知らないとちょっと戸惑う。
man expectでもよくわからないと思うことは実はTcl言語の文法だったり。