apt XXX installを強制停止したあとに再インストールする方法
再度インストールするまでの手順
自作OSを作る上でqumeというエミュレーターをインストールしていたのだが、インターネットの接続が不安定だったため強制停止した。 再度インストールをしようとしたところ以下のエラーが。
$ sudo apt install qemu E: ロック /var/lib/dpkg/lock-frontend が取得できませんでした - open (11: リソースが一時的に利用できません) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
他のプロセスがaptを使用していることが原因みたい。
まずは$ sudo apt clean
したが、同様のエラーが出てうまくいかず。
http://www.ifelse.jp/blog/ubuntu-02
今度は使用しているプロセスを特定し、killを試みる。
// プロセスの特定 $ ps aux | grep apt XXX 17428 0.0 0.0 22560 1052 pts/0 R+ 17:52 0:00 grep --color=auto apt root 18595 0.0 0.0 74076 4444 pts/0 T 3月09 0:00 sudo apt install qemu root 18599 0.0 1.0 142620 86348 pts/0 T 3月09 0:00 apt install qemu _apt 18621 0.0 0.1 90272 8792 pts/0 T 3月09 0:00 /usr/lib/apt/methods/http // プロセスをkill $ sudo kill 18595
killできてなかったのでオプション付きでやってみると無事にkillできた。
$ sudo kill -9 18595 $ ps aux | grep apt $ ps aux | grep apt XXX 17428 0.0 0.0 22560 1052 pts/0 R+ 17:52 0:00 grep --color=auto apt
再び$ sudo apt install qemu
を実行し、無事インストールが完了した。
やったことを振り返る
プロセスの特定
// プロセスの特定 $ ps aux | grep apt
$ ps auxについて
は実行中のプロセスの表示。
auxはオプションで
オプション | 詳細 |
---|---|
ps a | 自分以外のユーザーのプロセスも表示する |
ps u | ユーザー名と開始時刻を表示する |
ps x | 制御端末のないプロセスの情報も表示する |
psコマンドのその他のオプションは以下。
https://eng-entrance.com/linux-command-ps
--sort START
STARTの順に表示等は使うかも。
$ ps auxf
にするとツリー状で表示される。
それをパイプでgrepに渡した。
psで表示されたプロセスの見方。
$ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 225940 8700 ? Ss 3月04 2:24 /sbin/init splash root 2 0.0 0.0 0 0 ? S 3月04 0:00 [kthreadd] root 4 0.0 0.0 0 0 ? I< 3月04 0:00 [kworker/0:0H]
USER:プロセスの所有ユーザー PID:プロセス番号 %CPU:CPUの占有率 %MEM:実メモリでの占有率 VSZ:仮想分も含めた使用サイズ(Kバイト) RSS:実メモリ上の使用サイズ(Kバイト) TTY:端末名 STAT:プロセスの状態 STARTED:プロセスの開始時刻 TIME:プロセスの総実行時間 COMMAND:実行コマンド名とパス(シェル表記の場合もあり)
だいたい見たまんまの意味。 %CPUとか%MEMはパーセントが頭についてるから率のことを表してるはず。(調べてないです)
STATの状態は以下。
STAT | 状態 |
---|---|
R | 稼動中 |
S | 一時停止中 |
D | 停止不可能で一時停止 |
T | 終了処理中 |
Z | ゾンビプロセス(すでに実体は無い) |
W | 実メモリ上に無くて,スワップアウトしている |
N | nice値(プロセスの優先順位) |
特定のプロセスをkill
普通にkillしてもできなかったのは処理中だったからなので強制的にプロセスを終了した。 killのオプションはたくさんあった。
$ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX
上記のようにたくさんオプションがあった。 今回はSIGKILLで強制的に終了させたが、あまり正しくない方法だったのかもしれない。 これについて詳しく掘り下げるのはまた別の機会にしたい。
参考:https://www.xmisao.com/2013/11/10/linux-kill-signals.html http://d.hatena.ne.jp/aqua-nora/20101210/1291969145 https://qiita.com/shuntaro_tamura/items/4016868bda604baeac3c
終わりに
いろいろ調べていく中でわかりやすい記事があったのでいかにメモしておく。 Ctrl+Cとkill -SIGINTの違いをわかりやすく説明していた。 http://equj65.net/tech/linuxprocessgroup/
# PythonでModuleNotFoundError: No module named 'XXX'が出た場合の対処法
PandasをインストールしたはずなのにModuleNotFoundErrorがでた
Traceback (most recent call last): File "main.py", line 2, in <module> import pandas ModuleNotFoundError: No module named 'pandas'
pip show <インストールモジュール名> でインストールが正しくされているかの確認。
$ pip show pandas Name: pandas Version: 0.24.1 Summary: Powerful data structures for data analysis, time series, and statistics Home-page: http://pandas.pydata.org Author: None Author-email: None License: BSD Location: /home/XX/.local/lib/python2.7/site-packages Requires: numpy, pytz, python-dateutil
Locationがpython2.7のところに入っていた。 python3で動かしていたのでModuleNotFoundErrorが出てしまった。 https://web.plus-idea.net/2017/05/python-import-error-no-module-name/
ずっとpip install <インストールモジュール名>
でインストールしていたのが問題だったみたい。
なので以下でpip3をインストール。
$ sudo apt install python3-pip $ pip3 --version pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6) $ pip3 install pandas $ pip3 show pandas Name: pandas Version: 0.24.1 Summary: Powerful data structures for data analysis, time series, and statistics Home-page: http://pandas.pydata.org Author: None Author-email: None License: BSD Location: /home/XX/.local/lib/python3.6/site-packages Requires: pytz, python-dateutil, numpy
無事にpandasがインストールできた。 https://www.python.jp/install/ubuntu/pip.html
SSH鍵の生成からGitHubに登録するまでの備忘録
鍵を生成しGitHubに登録する手順
まずは次に自分が見返してもできるように手順だけ書いておきます。
// ユーザー情報を設定する git config --global user.name "First-name Family-name" git config --global user.email "username@example.com" // 確認 $ git config --global --list
// EmailアドレスはGitHubに登録しているもの $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com" Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter] // パスワード入れる Enter passphrase (empty for no passphrase): [Type a passphrase] Enter same passphrase again: [Type passphrase again]
上記で公開鍵と秘密鍵が生成されます。
// 表示されるすべてをコピーする $ cat id_rsa.pub
https://github.com Setting> SSH and GPG keys> New SSH keys でコピーした公開鍵を登録する。
$ ssh -T git@github.com The authenticity of host 'github.com (192.30.255.113)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no)?
RSAのfingerprintが以下のいずれかと一致するのを確認します。
https://help.github.com/articles/github-s-ssh-key-fingerprints
Hi GitHubアカウント名! You've successfully authenticated, but GitHub does not provide shell access.
$ eval "$(ssh-agent -s)" Agent pid 59566 $ ssh-add ~/.ssh/id_rsa
以上でGitHubに登録が完了です。
SSH鍵の生成にて
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
GiHubのヘルプにのっとり上記コマンドで鍵を生成しました。
$ ssh-keygen
だけで鍵を生成すると2048bitになる。
RSA鍵では2048bit以下だとあまりよろしくないようです。
https://hnw.hatenablog.com/entries/2014/07/05
上記のブログの著者は以下のように述べていますが、今回自分はGitHubに書かれている方を使いました。
2048bit RSA鍵で2030年まで戦えるらしいので当分それでいいと思っています。闇雲にSSHの鍵長を長くするとDH鍵交換やその他の暗号化プロセスも計算量が増えて、結果として処理が重くなってしまうんじゃないでしょうか。何事もトレードオフがあるよねってことで。
違う名前で鍵を生成する
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com" // 鍵を違う名前で生成する Enter a file in which to save the key (/home/you/.ssh/id_rsa): example_rsa
ssh-keygenして名前を入力すると鍵を違う名前で生成することができます。(上記だとexample_rsaとexample_rsa.pub) デフォルト(なにも入力せずにエンター)ではid_rsaとid_rsa.pubが生成されます。
※名前を指定しない時は勝手に~/.ssh内に鍵を生成してくれますが、名前を指定するときは~/.ssh内にいないとこの中に生成してくれないです。
違う名前で鍵を生成した場合は接続がうまく行かない可能性があります。 ssh接続の際「~/.ssh/id_rsa」、「~/.ssh/id_dsa」、「~/.ssh/identity」しかデフォルトでは見に行かないからのようです。 ~/.ssh/configに以下を作成する必要があります。
Host github github.com HostName github.com IdentityFile ~/.ssh/id_git_rsa #ここに自分の鍵のファイル名 User git
参考: GitHubでssh接続する手順~公開鍵・秘密鍵の生成から~ - Qiita
SSH鍵の公開鍵をクリップボードにコピーする
上記手順では$ cat id_rsa.pub
で表示されたものをコピーするというダサい感じでしたが、コマンドでももちろんできます。
// Mac $ pbcopy < ~/.ssh/id_rsa.pub // Windows $ clip < ~/.ssh/id_rsa.pub // Linux $ xclip -sel clip < ~/.ssh/id_rsa.pub // xclipがなければ $ sudo apt-get install xclip
https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/#platform-linux
SSH鍵のパスワードの変更
ssh-keygen -p # Start the SSH key creation process Enter file in which the key is (/Users/you/.ssh/id_rsa): [Hit enter] Key has comment '/Users/you/.ssh/id_rsa' Enter new passphrase (empty for no passphrase): [Type new passphrase] Enter same passphrase again: [One more time for luck] Your identification has been saved with the new passphrase.
https://help.github.com/articles/working-with-ssh-key-passphrases
のちのち参考にするかも
Ubuntu18.04にDockerのCEをインストールする
以下の公式ドキュメント。 https://docs.docker.com/v17.09/engine/installation/linux/docker-ce/ubuntu/#install-using-the-repository
curlがなかったのでインストール。
sudo apt install curl
https://qiita.com/bunty/items/758425773b2239feb9a7 https://qiita.com/yasuhiroki/items/a569d3371a66e365316f
sudo apt update sudo apt install apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OKと返ってきた。
~$ sudo apt-key fingerprint 0EBFCD88 pub rsa4096 2017-02-22 [SCEA] 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid [ 不明 ] Docker Release (CE deb) <docker@docker.com> sub rsa4096 2017-02-22 [S]
ubuntuを日本語設定にしているため不明となっている。
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
/etc/apt/sources.listの下にDockerが追加されているのを確認。
$ cat /etc/apt/sources.list deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable # deb-src [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
以下でようやくインストール。
$ sudo apt update $ sudo apt install docker-ce
以下で正しくインストールされたかの確認。
$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
終わりに
以前、いろんなものをインストールしては消していてubuntuの動作がおかしくなったことがある。 その場限りであったりはdockerで構築して使用していく。
ファンクションキーを使ったショートカット
ショートカットキーを知っているのと知っていないのでは業務を行う上でのスピードが大違いなので調べてみた。 https://support.google.com/chrome/answer/157179?hl=ja
ファンクションキーの使い方
ファンクションキー(GoogleChrome)
ショートカットキー | 動作 |
---|---|
F1 | ヘルプやサポートを開く |
F2 | 特に... |
F3 | 検索画面を表示(=Ctrl+F) |
F4 | 特に...(AltやCtrlと合わせるとウィンドウを閉じるがCtrl+Wでいい) |
F5 | ページの更新 |
F6 | フォーカスの切り替え アドレスバーに移動する(=Ctrl+L、Alt+D) |
F7 | 特に... |
F8 | 特に... |
F9 | 特に... |
F10 | Chrome ツールバーの最後の項目にフォーカスを移動する |
F11 | 全画面表示 |
F12 | デベロッパーツールを開く |
詳しくはGoogleの公式を。 https://support.google.com/chrome/answer/157179?hl=ja
ファンクションキー(共通系)
ショートカットキー | 動作 |
---|---|
F1 | ヘルプやサポートを開く |
F2 | ファイルやフォルダの名前を変更 |
F3 | 検索画面を表示 |
F4 | ダイアログボックスの一覧を表示 |
F5 | ページの更新 |
F6 | 文字を「ひらがな」に変換 |
F7 | 文字を「全角カタカナ」に変換 |
F8 | 文字を「半角カタカナ」に変換 |
F9 | 文字を「全角アルファベット」に変換 |
F10 | 文字を「半角アルファベット」に変換 |
F11 | 全画面表示 |
F12 |
https://azby.fmworld.net/usage/closeup/20140528/page2.html https://support.microsoft.com/ja-jp/help/12445/windows-keyboard-shortcuts
F6〜F10の文字の変換を知っておくと、日本語を使うときには便利だと感じた。
F7: こんにちは->コンニチハ
F8: こんにちは->コンニチハ
F9: こんにちは->konnnitiha
F10: こんにちは->konnnitiha
終わり
ショートカットキーを覚えるだけでだいぶ効率化を図れるので積極的に覚えていきたい。
.bashrcと.bash_profileを設定する
Ubuntu18.04のデスクトップ版をインストールしたあとにやったこと
ホームディレクトリの中身を英語にする
Ubuntuで日本語版をインストールするとホームディレクトリが日本語になってしまい使いにくいので変更した。
// 英語にする $ LANG=C xdg-user-dirs-gtk-update // 日本語へ戻す $ xdg-user-dirs-gtk-update
上記のコマンドでUpdateをすると変更できる。
Gitのインストール
$ sudo apt-get install git-all
上記のインストール方法だと古いバージョンのものになる。 最新版は以下の記事を参考にしてソースから取ってくる。 Git - Gitのインストール
ショートカットキーの設定
設定>デバイス>キーボードからキーボードショートカットの設定ができる。