1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WSLでsystemdがPID1じゃなくてエラー吐かれても実は動くことがある?

Last updated at Posted at 2021-10-05

WSLでRr-base)をインストールしてさらにtidyverseというパッケージをインストールしようとして

install.packages("tidyverse")

てやったら,なんか

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down

って怒られた.

色々調べるとlinuxだとカーネルがまず呼び出すプロセスとしてsystemdが一般的で,これに依存してる?ものがあるらしい.
基本的に大体のディストロで/sbin/initsystemdにリンクしている.
WSLにインストールしたディストロもsystemdが存在し,/sbin/initsystemdにリンクしているが,実際にWSLから起動する際は/initが呼び出され,これはMicroSoftが独自に開発してるものらしい?

これに対し多くのissueが建てられており,WSL2ではsystemdを呼び出すようなテクニックが共有されている.
https://shikiyura.com/2021/07/run_systemd_as_pid_1_on_wsl2_202107/
https://github.com/arkane-systems/genie
https://stackoverflow.com/questions/55579342/why-systemd-is-disabled-in-wsl

しかし,大抵WSL2の解決策ばかりでWSL1向けの記事は見つからない.自分としてはシリアルポートがWSL2だと使えないのでWSL1をいまだに使っている.
なのでsystemdが要求されている場合だけWSL2を使おうかとあきらめかけたが以下のような記事を見つけた
https://dev.to/bowmanjd/you-probably-don-t-need-systemd-on-wsl-windows-subsystem-for-linux-49gn

これによるとなんかsystemdがなくても動くと書いてある.
半信半疑,Rを起動してlibrary(tidyverse)としてみてもやはり動かない.

一応Rからではなくapt install r-cran-tidyverseとかしてインストール自体はできる模様なので,こちらでインストールを試みた.(他にもr-cran-xml2とかもこれでインストールした)
もう一度Rを起動してlibrary(tidyverse)とすると,

> library(tidyverse)
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down
── Attaching packages ──────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
✔ ggplot2 3.3.5     ✔ purrr   0.3.4
✔ tibble  3.1.4     ✔ dplyr   1.0.7
✔ tidyr   1.1.3     ✔ stringr 1.4.0
✔ readr   2.0.1     ✔ forcats 0.5.1
── Conflicts ─────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
Warning message:
In system("timedatectl", intern = TRUE) :
  running command 'timedatectl' had status 1

となってやはりsystemdPID1ではない云々という怒られは生じるが,一応ライブラリの読み込み自体はできた.単に読み込めたっぽいだけだと困るのでtidyverseの機能を利用してみる以下のようなコマンドを入力してみた

> df <- read_csv("https://www.nstac.go.jp/SSDSE/data/2021/SSDSE-B-2021.csv", locale = locale(encoding="CP932"), skip=1)
> subdf <- df %>% select(年度, 都道府県, 総人口) %>%
+ filter(都道府県 %in% c("東京都")) %>%
+ filter(年度==2018 | 年度==2017 | 年度==2016 | 年度==2015)
> ggplot(subdf, aes(x=年度, y=総人口))+geom_bar(stat="identity") + theme_light()

動いた

image.png

よく分かんないけどたぶんR内でinstall.packagesでインストールした際のエラーのメインはsystemdとかではなく,mv: cannot move ... Permission deniedのだったのかもしれない.

というわけでsystemdPID1じゃないと怒られても動くことはあるという話でした.

追記

そもそもR内でtidyverseをインストールするときに怒られる理由がxml2とかの依存パッケージがインストールできないからであるが,かといって
現状apt installでインストールできるr-cran-xml2のバージョンがちょっと古くてこれは使えんって怒られが生じる,
R内でinstall.packages("xml2")をすればよいのだが,これは何か途中のmvの作業でパーミッション関係で怒られる.
chmodでもすればよいのかもしれないが,以下の記事によると,オプションを付けるだけでパーミッションエラーを回避してくれるみたい
https://stackoverflow.com/questions/14382209/r-install-packages-returns-failed-to-create-lock-directory/14389028#14389028

というわけで

> install.packages("xml2", dependencies=TRUE, INSTALL_opts='--no-lock')

てやったらすんなりできた.これでさらに

> install.packages("tidyverse")

てやったら,途中めちゃめちゃsystemdが~って怒られるけど最終的にはちゃんとインストールできたっぽい

Installing package into ‘~/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/tidyverse_1.3.1.tar.gz'
Content type 'application/x-gzip' length 702779 bytes (686 KB)
==================================================
downloaded 686 KB

* installing *source* package ‘tidyverse’ ...
** package ‘tidyverse’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down
Warning in system("timedatectl", intern = TRUE) :
  running command 'timedatectl' had status 1
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down
Warning in system("timedatectl", intern = TRUE) :
  running command 'timedatectl' had status 1
** testing if installed package can be loaded from final location
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down
Warning in system("timedatectl", intern = TRUE) :
  running command 'timedatectl' had status 1
** testing if installed package keeps a record of temporary installation path
* DONE (tidyverse)

The downloaded source packages are in
        ‘/tmp/RtmpHuYGe4/downloaded_packages’

というわけでやっぱ

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down

は無視してよいかもしれない

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?