rabbit-slide-znz-lilo-20220205 2022.2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f19b28d77dc39bfd5b0f36879cd7e2ad36b0b5054a0a970fe4cf2241313a87b2
4
+ data.tar.gz: f1ff26f71d1d226fcd2aa6449c206014cec3b0b3067248ce988bebab7e7f5d5e
5
+ SHA512:
6
+ metadata.gz: 57fad071af0d1b12b106a05b17ce1f9113161ed417fb409685906f282cb57a1fc7e8515ec921e05dc6684f4a748958cb161d1b24ba052f88539427ef1ddb4a08
7
+ data.tar.gz: 4fb0718261a80248a38f6a97dfb3f7c0a5f3c6c3c5c9fa1b9ff10151d950282b019e3a87a1fc4f43c80dc01b6783724137de77c703f7f536714b7732b6c16b99
data/.rabbit ADDED
@@ -0,0 +1,2 @@
1
+ --size 800,600
2
+ qemu-riscv64.md
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # qemuのriscv64にDebianを入れてみた
2
+
3
+ [LILO&東海道らぐオンラインミーティング 2022-02-05](https://lilo.connpass.com/event/237592/)の発表資料です。
4
+
5
+ ## 作者向け
6
+
7
+ ### 表示
8
+
9
+ rake
10
+
11
+ ### 公開
12
+
13
+ rake publish
14
+
15
+ ## 閲覧者向け
16
+
17
+ ### インストール
18
+
19
+ gem install rabbit-slide-znz-lilo-20220205
20
+
21
+ ### 表示
22
+
23
+ rabbit rabbit-slide-znz-lilo-20220205.gem
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require "rabbit/task/slide"
2
+
3
+ # Edit ./config.yaml to customize meta data
4
+
5
+ spec = nil
6
+ Rabbit::Task::Slide.new do |task|
7
+ spec = task.spec
8
+ # spec.files += Dir.glob("doc/**/*.*")
9
+ # spec.files -= Dir.glob("private/**/*.*")
10
+ # spec.add_runtime_dependency("rabbit-theme-YOUR-THEME")
11
+ end
12
+
13
+ desc "Tag #{spec.version}"
14
+ task :tag do
15
+ sh("git", "tag", "-a", spec.version.to_s, "-m", "Publish #{spec.version}")
16
+ sh("git", "push", "--tags")
17
+ end
data/config.yaml ADDED
@@ -0,0 +1,24 @@
1
+ ---
2
+ id: lilo-20220205
3
+ base_name: qemu-riscv64
4
+ tags:
5
+ - linux
6
+ - riscv64
7
+ presentation_date: '2022-02-05'
8
+ presentation_start_time:
9
+ presentation_end_time:
10
+ version: 2022.2.5.0
11
+ licenses: []
12
+ slideshare_id: qemuriscv64debian
13
+ speaker_deck_id: qemufalseriscv64nidebianworu-retemita
14
+ vimeo_id:
15
+ youtube_id:
16
+ width: 800
17
+ height: 600
18
+ author:
19
+ markup_language: :markdown
20
+ name: Kazuhiro NISHIYAMA
21
+ email: zn@mbf.nifty.com
22
+ rubygems_user: znz
23
+ slideshare_user: znzjp
24
+ speaker_deck_user: znz
Binary file
data/qemu-riscv64.md ADDED
@@ -0,0 +1,300 @@
1
+ # qemuのriscv64にDebianを入れてみた
2
+
3
+ author
4
+ : Kazuhiro NISHIYAMA
5
+
6
+ content-source
7
+ : LILO&東海道らぐオンラインミーティング
8
+
9
+ date
10
+ : 2022-02-05
11
+
12
+ allotted-time
13
+ : 20m
14
+
15
+ theme
16
+ : lightning-simple
17
+
18
+ # 自己紹介
19
+
20
+ - 西山 和広
21
+ - Ruby のコミッター
22
+ - twitter, github など: @znz
23
+ - 株式会社Ruby開発 www.ruby-dev.jp
24
+
25
+ # 環境
26
+
27
+ - ホスト側 Ubuntu 21.10 (impish), (Ubuntu 20.04.3 LTS (focal) でも動作確認)
28
+ - QEMU emulator version 6.0.0 (Debian 1:6.0+dfsg-2expubuntu1.1)
29
+ - ゲスト側: Debian GNU/Linux bookworm/sid
30
+
31
+ # 参考
32
+
33
+ - <https://wiki.debian.org/RISC-V> の情報を元に実行
34
+ - <https://blog.n-z.jp/blog/2022-01-29-debian-qemu-riscv64.html> に公開した情報を再構成
35
+
36
+ # chroot で debootstrap
37
+
38
+ ```
39
+ sudo apt-get install debootstrap qemu-user-static \
40
+ binfmt-support debian-ports-archive-keyring
41
+ sudo debootstrap --arch=riscv64 --keyring \
42
+ /usr/share/keyrings/debian-ports-archive-keyring.gpg \
43
+ --include=debian-ports-archive-keyring unstable \
44
+ /tmp/riscv64-chroot http://deb.debian.org/debian-ports
45
+ ```
46
+
47
+ ここは Debian Wiki のコマンドそのまま
48
+
49
+ # chroot 環境で事前設定
50
+
51
+ ```
52
+ CHROOT=/tmp/riscv64-chroot
53
+ sudo chroot "$CHROOT" apt-get update
54
+ sudo chroot "$CHROOT" apt-get -y install etckeeper
55
+ sudo chroot "$CHROOT" apt-get -y full-upgrade
56
+ ```
57
+
58
+ - `CHROOT` はこの後も利用
59
+ - `etckeeper` はいつも入れているのでここでも入れた
60
+
61
+ # 他の設定
62
+
63
+ ```
64
+ sudo chroot "$CHROOT" ln -sf /dev/null \
65
+ /etc/systemd/system/serial-getty@hvc0.service
66
+ sudo chroot "$CHROOT" apt-get install -y \
67
+ linux-image-riscv64 u-boot-menu
68
+ sudo chroot "$CHROOT" apt-get install -y \
69
+ openntpd ntpdate
70
+ sudo chroot "$CHROOT" sed -i \
71
+ 's/^DAEMON_OPTS="/DAEMON_OPTS="-s /' \
72
+ /etc/default/openntpd
73
+ printf '\nU_BOOT_PARAMETERS="rw noquiet'\
74
+ ' root=/dev/vda1"\nU_BOOT_FDT_DIR="noexist"\n' \
75
+ | sudo chroot "$CHROOT" tee -a /etc/default/u-boot
76
+ sudo chroot "$CHROOT" u-boot-update
77
+ ```
78
+
79
+ (ネットワーク設定とパスワード設定は後で)
80
+
81
+ # ネットワーク設定
82
+
83
+ ```
84
+ printf 'auto lo\niface lo inet loopback\n' | \
85
+ sudo chroot "$CHROOT" tee /etc/network/interfaces.d/lo
86
+ printf 'auto eth0\niface eth0 inet dhcp\n' | \
87
+ sudo chroot "$CHROOT" tee /etc/network/interfaces.d/eth0
88
+ echo "debian-riscv64" | sudo chroot "$CHROOT" tee /etc/hostname
89
+ echo "10.0.2.15 debian-riscv64" | sudo chroot "$CHROOT" tee -a /etc/hosts
90
+ ```
91
+
92
+ - 自動化しやすいように `/etc/network/interfaces` は書き換えず `interfaces.d` にファイル作成
93
+ - `/etc/hosts`にも追加して`sudo: unable to resolve host debian-riscv64: Temporary failure in name resolution`対策
94
+
95
+ # ユーザー設定
96
+
97
+ ```
98
+ NEW_USER_ID=10001
99
+ NEW_USER_NAME=user1
100
+ #NEW_USER_PASSWORD=password
101
+ NEW_USER_CRYPTED_PASSWORD='$6$(略)'
102
+ sudo chroot "$CHROOT" groupadd -g "$NEW_USER_ID" "$NEW_USER_NAME"
103
+ sudo chroot "$CHROOT" useradd -d "/home/$NEW_USER_NAME" -m \
104
+ -g "$NEW_USER_NAME" -u "$NEW_USER_ID" -p "$NEW_USER_CRYPTED_PASSWORD" \
105
+ -s /bin/bash "$NEW_USER_NAME"
106
+ sudo chroot "$CHROOT" apt-get install -y sudo
107
+ echo "$NEW_USER_NAME ALL=(ALL) NOPASSWD:ALL" | \
108
+ sudo chroot "$CHROOT" tee "/etc/sudoers.d/$NEW_USER_NAME"
109
+ ```
110
+
111
+ - gid や uid を固定するため `groupadd` と `useradd` で個別に追加
112
+ - `useradd` の `-p` は 生パスワードではない
113
+ - `sudo` の設定も追加
114
+
115
+ # ユーザー設定 (失敗)
116
+
117
+ ```
118
+ $ echo "$NEW_USER_NAME:$NEW_USER_PASSWORD" | \
119
+ sudo chroot "$CHROOT" chpasswd
120
+ chpasswd: (user user1) pam_chauthtok() failed, error:
121
+ Authentication token manipulation error
122
+ ```
123
+
124
+ - 仮想環境で弱いパスワードなのでそのまま書いておきたかったが、`chroot` 環境では使えなかった
125
+
126
+ # cloud-init
127
+
128
+ ```
129
+ sudo chroot "$CHROOT" apt-get -y install cloud-init openssh-server
130
+ ```
131
+
132
+ - 最終的には `cloud-init` を入れて、ネットワーク設定やユーザー設定はそちらに任せることに
133
+ - `openssh-server` の設定もしてくれる
134
+ - 一緒にインストールしておかないと、 `PasswordAuthentication yes` だけの `/etc/ssh/sshd_config` が作成されてしまっておかしなことに
135
+
136
+ # cloud-initとは
137
+
138
+ - 主に EC2 などのクラウド環境での初期設定ツール
139
+ - LXC/LXD や multipass などでも対応
140
+ - openssh のホスト鍵の再生成などディスクイメージの再利用をするときに必要な機能も入っている
141
+
142
+ # 使い分け
143
+
144
+ 「いまさらで物凄く恐縮ですが、cloud-initについて勉強してみた」 <https://qiita.com/MUCHIUCHI_OJISAN/items/9c013e87bd2dbeb4ca4a> の「使い分け」を参照
145
+
146
+ # ディスクイメージ作成前の最後の処理
147
+
148
+ ```
149
+ sudo chroot "$CHROOT" sed -i -e 's/^# \(ja_JP\.UTF-8\)/\1/' /etc/locale.gen
150
+ sudo chroot "$CHROOT" etckeeper commit "Enable ja_JP.UTF-8"
151
+ sudo chroot "$CHROOT" etckeeper vcs gc
152
+ sudo chroot "$CHROOT" apt-get clean
153
+ ```
154
+
155
+ - `cloud-init`で`/etc/locale.gen`の変更はしてくれないようなので変更しておく
156
+ - 他にもディスクイメージを小さくできる処理があればしておく
157
+
158
+ # ディスクイメージファイル作成
159
+
160
+ ```
161
+ sudo apt-get install -y libguestfs-tools
162
+ sudo virt-make-fs --partition=gpt --type=ext4 \
163
+ --size=10G "$CHROOT"/ "$HOME/riscv64/rootfs.img"
164
+ sudo chown "$USER" "$HOME/riscv64/rootfs.img"
165
+ ```
166
+
167
+ - イメージ作成には時間がかかるのでゆっくり待つ
168
+ - qemu の実行ユーザーで読み書きできるようにしておく
169
+
170
+ # 実行に必要なものをインストール
171
+
172
+ ```
173
+ sudo apt-get install -y qemu-system-misc
174
+ sudo apt-get install -y opensbi u-boot-qemu
175
+ sudo apt-get install -y genisoimage
176
+ ```
177
+
178
+ - 実行に必要なものをインストール
179
+ - genisoimage は cloud-init の NoCloud データソース用
180
+
181
+ # cloud-init用データ作成
182
+
183
+ ```
184
+ #cloud-config
185
+
186
+ ssh_pwauth: true # sshにパスワード認証で入れるようにする
187
+ chpasswd:
188
+ list:
189
+ #- root:debian # rootユーザーも直接使うならパスワードを設定する
190
+ - debian:debian # debianユーザーはdefaultsで作成されるのでパスワード設定をしておく
191
+ expire: false
192
+
193
+ manage_etc_hosts: true # sudoに必要
194
+
195
+ timezone: Asia/Tokyo
196
+ locale: ja_JP.UTF-8
197
+ package_upgrade: true
198
+ #packages:
199
+ #- qemu-guest-agent # riscv64 には未対応
200
+
201
+ mounts: # qemuの共有設定
202
+ - [ 'hostshare', '/mnt/hostshare', '9p', 'defaults,nofail,_netdev', '0', '2' ]
203
+
204
+ runcmd:
205
+ - [ mkdir, '-p', /mnt/hostshare ]
206
+ - [ mount, '-a' ]
207
+ - [ 'etckeeper', 'commit', 'cloud-init' ]
208
+ ```
209
+
210
+ # cloud-init用ISOファイル作成
211
+
212
+ ```
213
+ cd "$HOME/riscv64"
214
+ cat >meta-data <<EOF
215
+ instance-id: iid-local01
216
+ local-hostname: debian-riscv64
217
+ EOF
218
+ genisoimage -output seed.iso -volid cidata -joliet -rock meta-data user-data
219
+ ```
220
+
221
+ - instance-id が変わるとopensshのホスト鍵の再作成などの処理が実行されるので適当な固定値に
222
+
223
+ # 起動
224
+
225
+ ```
226
+ exec qemu-system-riscv64 -nographic -machine virt -m 1.9G \
227
+ -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf \
228
+ -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
229
+ -object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-device,rng=rng0 \
230
+ -append "console=ttyS0 rw root=/dev/vda1" \
231
+ -device virtio-blk-device,drive=hd0 -drive file=rootfs.img,format=raw,id=hd0 \
232
+ -drive file=seed.iso,if=virtio \
233
+ -device virtio-net-device,netdev=usernet -netdev user,id=usernet,hostfwd=tcp::22222-:22 \
234
+ -smp cpus=4,sockets=1,cores=4,threads=1 \
235
+ -virtfs local,path=$HOME/share,mount_tag=hostshare,security_model=mapped-xattr \
236
+ -name debian-riscv64
237
+ ```
238
+
239
+ - cloud-init用のseed.isoや共有のvirtfsなどは不要なら省略可能
240
+
241
+ # 接続
242
+
243
+ ```
244
+ ssh -p 22222 debian@localhost
245
+ ```
246
+
247
+ - 起動して `cloud-init` での設定が終わるまでしばらく待ってから接続
248
+
249
+
250
+ # 共有ディレクトリ設定
251
+
252
+ - ホストとゲストでファイルのやりとりのために `$HOME/share` を共有ディレクトリに設定
253
+ - ホスト側でパーミッションを 1777 に
254
+ - `security_model` は <https://wiki.qemu.org/Documentation/9psetup> の推奨設定
255
+ - ゲストで `sudo mount -t 9p hostshare /mnt/hostshare` のようにマウント
256
+ - 早すぎるとマウント失敗するので fstab に `_netdev` で遅めにマウント
257
+
258
+ # poweroff
259
+
260
+ ```
261
+ [ 169.345939] systemd-shutdown[1]: Powering off.
262
+ [ 169.348326] reboot: Power down
263
+ ```
264
+
265
+ - なぜか `poweroff` をしても上の行までで `qemu-system-riscv64` が終了せずに止まってしまう
266
+ - `C-a x` で終了
267
+ - ホスト側が amd64 の Ubuntu 20.04 だと問題なし
268
+
269
+ # 困りごと
270
+
271
+ ```
272
+ debian@debian-riscv64:~$ echo 'int main(){return 0;}' | gcc -xc -
273
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crti.o: mis-matched ISA version 2.0 for 'i' extension, the output version is 2.1
274
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crti.o: mis-matched ISA version 2.0 for 'a' extension, the output version is 2.1
275
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crti.o: mis-matched ISA version 2.0 for 'f' extension, the output version is 2.2
276
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crti.o: mis-matched ISA version 2.0 for 'd' extension, the output version is 2.2
277
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crtbeginS.o: mis-matched ISA version 2.0 for 'i' extension, the output version is 2.1
278
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crtbeginS.o: mis-matched ISA version 2.0 for 'a' extension, the output version is 2.1
279
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crtbeginS.o: mis-matched ISA version 2.0 for 'f' extension, the output version is 2.2
280
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crtbeginS.o: mis-matched ISA version 2.0 for 'd' extension, the output version is 2.2
281
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crtendS.o: mis-matched ISA version 2.0 for 'i' extension, the output version is 2.1
282
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crtendS.o: mis-matched ISA version 2.0 for 'a' extension, the output version is 2.1
283
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crtendS.o: mis-matched ISA version 2.0 for 'f' extension, the output version is 2.2
284
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crtendS.o: mis-matched ISA version 2.0 for 'd' extension, the output version is 2.2
285
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crtn.o: mis-matched ISA version 2.0 for 'i' extension, the output version is 2.1
286
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crtn.o: mis-matched ISA version 2.0 for 'a' extension, the output version is 2.1
287
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crtn.o: mis-matched ISA version 2.0 for 'f' extension, the output version is 2.2
288
+ /usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crtn.o: mis-matched ISA version 2.0 for 'd' extension, the output version is 2.2
289
+ debian@debian-riscv64:~$
290
+ ```
291
+
292
+ - なぜかリンクで警告がでる
293
+ - (`/usr/bin/ld: warning: /usr/lib/gcc/riscv64-linux-gnu/11/crti.o: mis-matched ISA version 2.0 for 'i' extension, the output version is 2.1` など)
294
+
295
+ # まとめ
296
+
297
+ - qemu で riscv64 の Debian 環境が作成できた
298
+ - cloud-init での初期設定もできた
299
+ - qemuのvirtfsの共有も使えた
300
+ - gccで警告がでる (普通に実行するだけで出るのでそのうち直るはず?)
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rabbit-slide-znz-lilo-20220205
3
+ version: !ruby/object:Gem::Version
4
+ version: 2022.2.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Kazuhiro NISHIYAMA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rabbit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.2
27
+ description: "[LILO&東海道らぐオンラインミーティング 2022-02-05](https://lilo.connpass.com/event/237592/)の発表資料です。"
28
+ email:
29
+ - zn@mbf.nifty.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rabbit"
35
+ - README.md
36
+ - Rakefile
37
+ - config.yaml
38
+ - pdf/lilo-20220205-qemu-riscv64.pdf
39
+ - qemu-riscv64.md
40
+ homepage: https://slide.rabbit-shocker.org/authors/znz/lilo-20220205/
41
+ licenses: []
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.2.32
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: qemuのriscv64にDebianを入れてみた
62
+ test_files: []