2020年10月24日土曜日

The Go Programming Language


 公式サイト

公式tutorial getting started

自習場所

自習場所(日本語)


[memo]

外部からパッケージをインポートする場合は、

$ go mod init myprog.go

を実行すると (myprog.goは、外部パッケージをimportしているプログラム)

~/go/pkg/mod/

にダウンロードされる。

パッケージは、ここから検索できる。


外部から参照されるモジュールを作成する場合

モジュール用のデレクトリを作成しそこに移動する。

$ go mod init インポート名

インポート名は、importで参照する名前、ドメイン名/パッケージ名にする。

を実行しgo.modを作成する。

参照側は、自身のgo.modにreplace ドメイン名/パッケージ名 => 対象パス を追加する








2020年4月16日木曜日

FreeBSD kernel build

まずは、FreeBSD Handbookの8.5. Building and Installing a Custom Kernelを読む

#cd /usr/src
#make buildkernel KERNCONF=MYKERNE

詳しく知るには、
/usr/src/Makefileを読む。

その前に、Developers' HandbookのChapter 9. Building and Installing a FreeBSD Kernelを読む

#/usr/sbin/config MYKERNEL

続いて、config(8)を読む
man config

SYNOPSIS
     config [-CVgp] [-I path] [-d destdir] [-s srcdir] SYSTEM_NAME
     config [-x kernel]

     SYSTEM_NAME      Specify the name of the system configuration file
                      containing device specifications, configuration options
                      and other system parameters for one system
                      configuration.

MYKERNELは、SYSTEM_NAMEのことでシステムの構成を記述したファイル、
通常は、/sys/ARCH/confに存在する。(ARCHは、amd64)
configは、Makefileなどビルドに必要なファイルを作成する。
テンプレートが/sys/ARCH/confにある。テンプレートを修正してはいけない。
コピーして使う。
書き方は、config(5)に書かれている。

FILES
     /sys/conf/files                                         list of common files system is built from
     /sys/conf/Makefile.ARCH                                 generic makefile for the ARCH
     /sys/conf/files.ARCH                                    list of ARCH specific files
     /sys/ARCH/compile/SYSTEM_NAME   
                       default kernel  build directory for system  SYSTEM_NAME on ARCH

時間があれば、Building 4.4BSD Kernels with Configを読む。

config(5)によると
     device name [, name [...]]
     devices name [, name [...]]
             Configures the specified devices for inclusion into the kernel
             image.  Devices that are common to all architectures are defined
             in the file sys/conf/files.  Devices that are specific to
             architecture arch are defined in the file sys/conf/files.<arch>.


2020年4月5日日曜日

GNU Make 4.1 (1)

$ make --version
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

makeは、versionが異なると細かい部分で異なるので注意が必要

make [OPTION]... [TARGET]...

makeは、makefileと呼ばれるファイルを読み込み、makefileに従い処理を行う。
makefileには、ビルドに必要な情報が書かれている。

makeを引数なしで実行すると
GNUmakefile, makefile, Makefileの順でファイルを探していく。
最初に見つかったファイルをmakefileとして処理する。

.dependがあれば読み込む。

$ make
make: *** No targets specified and no makefile found.  Stop.

$ touch GNUmakefile
$ make
make: *** No targets.  Stop.

$ echo hello: > makefile
$ make
make: *** No targets.  Stop.       # makefile でなくGNUmakefileが読み込まれる
$ cp makefile GNUmakefile 
$ make
make: Nothing to be done for 'hello'.

通常は、Makefileを使うことが推奨されている。
GNUmakefileは、GNU makeに限定される場合だけに使用する。

makeが上手く動作しない場合は、-dを付けて実行すると、原因がわかるかもしれない

概要   https://www.gnu.org/software/make/
マニュアルhttps://www.gnu.org/software/make/manual/
開発   http://savannah.gnu.org/projects/make/







2020年1月2日木曜日

ubuntu server インストール

ubuntu を使ってライブUSB を作ってインストールする方法

ここがインストールのチュートリアル。
https://tutorials.ubuntu.com/tutorial/tutorial-install-ubuntu-server?_ga=2.54415336.1168427040.1568425745-2077189292.1557957691#0

インストール用のUSBを作る。
ここがubuntuでの作成方法のチュートリアル。
https://tutorials.ubuntu.com/tutorial/tutorial-create-a-usb-stick-on-ubuntu#0

ここからISOイメージをダウンロードする。
https://ubuntu.com/download/server

‘Startup Disk Creator' を使ってusbメモリに書き込む。
 ddコマンドでも書き込める
lsblkでsdxをしらべ
dd bs=4M if=./image.usb of=/dev/sdX && sync

BIOSを設定して、USBから起動するようにする。

usbメモリを刺したまま起動する。

あとは、ガイドに従い操作する。

めも
BIOSをupdateしないとインストールできないことがある。

 


2019年8月16日金曜日

git

gitは、web上のプロトコルでなくても、ローカルのファイルシステムでも動作する。
動作確認は、ローカルのファイルシステムで行うのが簡単

$mkdir base.git
$cd base.git
$git init --bare --shared
$cd ..
$git clone --bare --shared base.git second.git

$ git clone base.git test0
Cloning into 'test0'...
warning: You appear to have cloned an empty repository.
done.

$cd test0
$ git remote set-url --push origin ../second.git
$ git remote -v
origin /home/ok/git_test/base.git (fetch)
origin ../second.git (push)

$ echo 'first commit' >  a
$ git add .
$ git commit -m 'first commit'
[master (root-commit) 8c08e8e] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 a
$ git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 212 bytes | 212.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To ../second.git
 * [new branch]      master -> master

2019年4月5日金曜日

ubuntu kernel build

apt でソースがダウンロードできるように
sudo sed -i 's/^# deb-src/deb-src/g' /etc/apt/source.list
source.listのdev-srcのコメントをはずす。
修正したら
sudo apt update

linuxビルドに必要なものをインストールする。
sudo apt install ccache fakeroot libncurses5-dev
sudo apt build-dep linux

sourceの取得
apt source linux
で取得できるが
NOTICE: 'linux' packaging is maintained in the 'Git' version control system at:
git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/bionic
Please use:
git clone git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/bionic
上記の方法で取得したubuntu kernelは、下記の方法ではビルドできない
若干の修正が必要

git で取得しろとのこと
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

cd linux
mkdir ../build
cp /boot/config-`uname -r` ../build/.config

make O=../build/ olddefconfig

カーネルビルド
make -j9 O=../build/ LOCALVERSION=-xxx

モジュールビルド
make modules -j9 O=../build/ LOCALVERSION=-xxx


パッケージ作成
make bindeb-pkg O=../build/ LOCALVERSION=-xxx
bindeb-pkg バイナリパッケージのみ
deb-pkg ソースパッケージも作成

インストール
sudo apt ../*.deb



build 時間
core2 duo

real    190m49.470s
user    310m50.655s

sys     36m25.217s

Intel(R) Core(TM) i3-6100U CPU @ 2.30GHz
real 115m21.085s
user 166m20.077s
sys 17m37.104s

Intel(R) Pentium(R) CPU G4620 @ 3.70GHz
real 51m28.830s
user 185m58.351s
sys 15m43.776s

Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
real 20m22.547s
user 113m49.728s
sys 11m31.246s

lxd環境
real 1087.78  18m7.78
user 7239.94    120m39.94
sys 874.63           14m34.63









2019年1月13日日曜日

php apache postgresql ubuntu18へのインストール

apache2 とphp のインストール
#apt install php
これだけ
/var/www/html/phpinfo.php
を作って 動作確認をしてみる
phpinfo.phpは
<?php phpinfo() ?>

postgresのインストール
#apt install postgresql
インストールしたらpostgresのパスワード設定をする
#su - postgres
$psql
postgres=# \password
Enter new password:
Enter it again:
postgres=# \q
$exit
#
phppgadminのインストール
#apt update
#apt install phppgadmin
そのままでは、外部からアクセスできないので
/etc/apache2/conf-available/phppgadmin.conf
を修正
Require local => Require all granted
/etc/phppgadmin/config.inc.php
を修正
$conf['extra_login_security'] = false;
apache2再起動
#systemctl restart apache2
http://xxx.xxx.xxx.xxx/phppgadmin
をアクセスして動作確認