WSLのUbuntu 24.04 LTS環境でpolkitdパッケージのアップデート時に出たエラー

自分のWindows PCで動かしていたWSLをUbuntu 24.04 LTS に入れ替えました。 debパッケージ類を更新しようとしたら出たエラーを解決したときのメモです。

出たエラー

一旦パッケージを最新化しようとしたら

$ sudo apt upgrade

こんなエラーが

Failed to take /etc/passwd lock: Invalid argument
dpkg: error processing package polkitd (--configure):
 installed polkitd package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 polkitd
E: Sub-process /usr/bin/dpkg returned an error code (1)

対処

参考にしたサイトに記載あったコマンドを参考に作業してみます。

$ cd /bin && sudo mv -f systemd-sysusers{,.org} && sudo ln -s echo systemd-sysusers && cd -
$ pwd
/bin
$ ls -la systemd-sysusers*
lrwxrwxrwx 1 root root     4 Jan 25 13:59 systemd-sysusers -> echo
-rwxr-xr-x 1 root root 68224 Aug  8 23:51 systemd-sysusers.org

再度更新してみます。とりあえずパッケージは入ったようです。 違う問題が起きたらsystemd-sysusersのバイナリを基に戻す感じですかね。

$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up polkitd (124-2ubuntu1.24.04.2) ...
polkit.conf
start-stop-daemon: unable to stat /usr/libexec/polkitd (No such file or directory)

$ dpkg --list polkitd
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version              Architecture Description
+++-==============-====================-============-=============================================================
ii  polkitd        124-2ubuntu1.24.04.2 amd64        framework for managing administrative policies and privileges

今日はこんなところで。

参考

asdfを軽く使ってみる

大分久々ですが記事を書いてみます。

asdfについて

asdfは各種ツールに対応したバージョン管理ツールです。

インストール

インストールした環境はAWS上にローンチした Ubuntu 24.04.1 LTS(64bit) です。 また、デフォルトで用意されている ubuntu ユーザの環境にセットアップします。

前提条件

作業前提として git と curl が必要です。 大抵導入済みと思いますが、パッケージがインストールされているかどうか確認をします。

$ dpkg --list curl git
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version             Architecture Description
+++-==============-===================-============-=======================================================
ii  curl           8.5.0-2ubuntu10.6   amd64        command line tool for transferring data with URL syntax
ii  git            1:2.43.0-1ubuntu7.2 amd64        fast, scalable, distributed revision control system

今回使用した環境では unzip が入っていなかったので、先にインストールしておきます。

$ sudo apt-get install unzip

asdfのセットアップ

まずはasdfを持ってきます。

$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.15.0

次にパスを設定します。

$ echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc
$ echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc
$ source ~/.bashrc

パスが通っていることを確認します。

$ which asdf
/home/ubuntu/.asdf/bin/asdf

初期セットアップはこれで完了です。

簡単な使い方

簡単に使ってみます。

プラグイン一覧の表示

asdf でツールを管理するために、各ツール用のプラグイン一覧を取得してみます。

$ asdf plugin-list-all

プラグインのインストール

asdfプラグインをインストールします。今回は作業時点で最新の terraform を入れてみます。

$ asdf plugin add terraform
$ asdf plugin list
terraform
$ asdf install terraform latest
Downloading terraform version 1.10.4 from https://releases.hashicorp.com/terraform/1.10.4/terraform_1.10.4_linux_amd64.zip
Verifying signatures and checksums
gpg: keybox '/tmp/asdf_terraform_BcQcWI/pubring.kbx' created
gpg: /tmp/asdf_terraform_BcQcWI/trustdb.gpg: trustdb created
gpg: key 34365D9472D7468F: public key "HashiCorp Security (hashicorp.com/security) <security@hashicorp.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1
gpg: Signature made Wed Jan  8 10:50:46 2025 UTC
gpg:                using RSA key 374EC75B485913604A831CC7C820C6D5CD27AB87
gpg: Good signature from "HashiCorp Security (hashicorp.com/security) <security@hashicorp.com>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: C874 011F 0AB4 0511 0D02  1055 3436 5D94 72D7 468F
     Subkey fingerprint: 374E C75B 4859 1360 4A83  1CC7 C820 C6D5 CD27 AB87
terraform_1.10.4_linux_amd64.zip: OK
Cleaning terraform previous binaries
Creating terraform bin directory
Extracting terraform archive

先ほどインストールした terraform を有効にします。

$ asdf global terraform latest
$ terraform -v
Terraform v1.10.4
on linux_amd64

バージョンを指定する場合はこちら

$ asdf global terraform 1.10.4
$ terraform -v
Terraform v1.10.4
on linux_amd64

他にも入れてみる

他にも入れてみます。awscli, gcloud あたりを良く使うので入れてみます。

awscli

awscli を入れてみます。

$ asdf plugin add awscli
$ asdf plugin list | grep awscli
awscli
$ asdf install awscli latest
You can now run: /home/ubuntu/.asdf/installs/awscli/2.23.2/bin/aws --version
asdf-awscli: asdf-awscli 2.23.2 installation was successful!
$ asdf global awscli latest
$ which aws
/home/ubuntu/.asdf/shims/aws
$ aws --version
aws-cli/2.23.2 Python/3.12.6 Linux/6.8.0-1021-aws exe/x86_64.ubuntu.24
gcloud

gcloud を入れてみます。

$ asdf plugin add gcloud
✅  All dependencies found on system!
$ asdf plugin list | grep gcloud
gcloud
$ asdf install gcloud latest
⏬  downloading google-cloud-sdk-506.0.0-linux-x86_64.tar.gz
###################################################################################################################### 100.0%
✅  downloaded!
✅  All dependencies found on system!
📦  extracting...
✅  extracted!
🚧  installing...
Welcome to the Google Cloud CLI!

Your current Google Cloud CLI version is: 506.0.0
The latest available version is: 506.0.0

lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x                                                    Components                                                   x
tqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqu
x     Status    x                         Name                         x              ID              x    Size   x
tqqqqqqqqqqqqqqqnqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnqqqqqqqqqqqu
x Not Installed x App Engine Go Extensions                             x app-engine-go                x   4.7 MiB x
x Not Installed x Appctl                                               x appctl                       x  21.0 MiB x
x Not Installed x Artifact Registry Go Module Package Helper           x package-go-module            x   < 1 MiB x
x Not Installed x Cloud Bigtable Command Line Tool                     x cbt                          x  18.8 MiB x
x Not Installed x Cloud Bigtable Emulator                              x bigtable                     x   7.7 MiB x
x Not Installed x Cloud Datastore Emulator                             x cloud-datastore-emulator     x  36.2 MiB x
x Not Installed x Cloud Firestore Emulator                             x cloud-firestore-emulator     x  46.9 MiB x
x Not Installed x Cloud Pub/Sub Emulator                               x pubsub-emulator              x  62.2 MiB x
x Not Installed x Cloud Run Proxy                                      x cloud-run-proxy              x  13.3 MiB x
x Not Installed x Cloud SQL Proxy v2                                   x cloud-sql-proxy              x  13.8 MiB x
x Not Installed x Cloud Spanner Emulator                               x cloud-spanner-emulator       x  37.7 MiB x
x Not Installed x Cloud Spanner Migration Tool                         x harbourbridge                x  20.9 MiB x
x Not Installed x Google Container Registry's Docker credential helper x docker-credential-gcr        x   1.8 MiB x
x Not Installed x Kustomize                                            x kustomize                    x   4.3 MiB x
x Not Installed x Log Streaming                                        x log-streaming                x  13.9 MiB x
x Not Installed x Managed Flink Client                                 x managed-flink-client         x 383.4 MiB x
x Not Installed x Minikube                                             x minikube                     x  36.3 MiB x
x Not Installed x Nomos CLI                                            x nomos                        x  31.2 MiB x
x Not Installed x On-Demand Scanning API extraction helper             x local-extract                x  29.3 MiB x
x Not Installed x Skaffold                                             x skaffold                     x  24.2 MiB x
x Not Installed x Spanner migration tool                               x spanner-migration-tool       x  24.5 MiB x
x Not Installed x Terraform Tools                                      x terraform-tools              x  66.1 MiB x
x Not Installed x anthos-auth                                          x anthos-auth                  x  22.0 MiB x
x Not Installed x config-connector                                     x config-connector             x  91.1 MiB x
x Not Installed x enterprise-certificate-proxy                         x enterprise-certificate-proxy x   8.6 MiB x
x Not Installed x gcloud Alpha Commands                                x alpha                        x   < 1 MiB x
x Not Installed x gcloud Beta Commands                                 x beta                         x   < 1 MiB x
x Not Installed x gcloud app Java Extensions                           x app-engine-java              x 128.1 MiB x
x Not Installed x gcloud app Python Extensions                         x app-engine-python            x   3.8 MiB x
x Not Installed x gcloud app Python Extensions (Extra Libraries)       x app-engine-python-extras     x   < 1 MiB x
x Not Installed x gke-gcloud-auth-plugin                               x gke-gcloud-auth-plugin       x   4.0 MiB x
x Not Installed x istioctl                                             x istioctl                     x  24.0 MiB x
x Not Installed x kpt                                                  x kpt                          x  15.1 MiB x
x Not Installed x kubectl                                              x kubectl                      x   < 1 MiB x
x Not Installed x kubectl-oidc                                         x kubectl-oidc                 x  22.0 MiB x
x Not Installed x pkg                                                  x pkg                          x           x
x Installed     x BigQuery Command Line Tool                           x bq                           x   1.7 MiB x
x Installed     x Bundled Python 3.11                                  x bundled-python3-unix         x  74.4 MiB x
x Installed     x Cloud Storage Command Line Tool                      x gsutil                       x  11.8 MiB x
x Installed     x Google Cloud CLI Core Libraries                      x core                         x  20.7 MiB x
x Installed     x Google Cloud CRC32C Hash Tool                        x gcloud-crc32c                x   1.4 MiB x
mqqqqqqqqqqqqqqqvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvqqqqqqqqqqqj
To install or remove components at your current SDK version [506.0.0], run:
  $ gcloud components install COMPONENT_ID
  $ gcloud components remove COMPONENT_ID

To update your SDK installation to the latest version [506.0.0], run:
  $ gcloud components update

==> Source [/home/ubuntu/.asdf/installs/gcloud/506.0.0/completion.bash.inc] in your profile to enable shell command completion for gcloud.
==> Source [/home/ubuntu/.asdf/installs/gcloud/506.0.0/path.bash.inc] in your profile to add the Google Cloud SDK command line tools to your $PATH.

For more information on how to get started, please visit:
  https://cloud.google.com/sdk/docs/quickstarts


✅  gcloud 506.0.0 installed!
ℹ️  Check by Default SDK Components at /home/ubuntu/.default-cloud-sdk-components
$ asdf global gcloud latest
$ which gcloud
/home/ubuntu/.asdf/shims/gcloud
$ gcloud -v
Google Cloud SDK 506.0.0
bq 2.1.11
bundled-python3-unix 3.11.9
core 2025.01.10
gcloud-crc32c 1.0.0
gsutil 5.33

今日はこんなところで。

参考

EC2のTermination Protection設定を確認する

EC2インスタンスのTermination Protection設定をまとめて調べようと思い、とりあえずスクリプトを書いてみたので、メモ。

#!/bin/bash

INTERVAL=2
HEADER='instance-id,disable_api_termination'

INSTANCE_IDS=$(aws ec2 describe-instances | jq -r '.Reservations[].Instances[].InstanceId')

echo ${HEADER}
for INSTANCE_ID in ${INSTANCE_IDS}
do
  PROTECTION=$(aws ec2 describe-instance-attribute --instance-id ${INSTANCE_ID} --attribute disableApiTermination | jq -r '.DisableApiTermination.Value')
  echo "${INSTANCE_ID},${PROTECTION}"
  sleep ${INTERVAL}
done

実行するとこんな感じ。

instance-id,disable_api_termination
i-xxxxxxxx,true
i-xxxxxxxx,true
i-xxxxxxxx,true

とりあえず感がありますが、今日はこんなところで。

Virtualboxで作成したCentOS7が起動しない

相当しばらくぶりの投稿です。今日はVirtualboxの話題。


VirtualBox上でCentOS7の仮想マシンを先日作ったのですが、
これを起動しようとしたところ、起動できず。
復旧する羽目になりました。その時の対応メモです。

環境

起動直後


起動直後はこんな感じでした。完全にダメですね。


f:id:think-t:20180904005430j:plain

レスキューモードで起動


ということでレスキューモードで立ち上げます。


f:id:think-t:20180904010633j:plain


f:id:think-t:20180904010648j:plain


f:id:think-t:20180904010926j:plain

復旧


参考リンクのページを参考に「grubx64.efi」をコピーしました。
参考リンクのコマンドをそのまま参考にしながら進めましたが、「/dev/centos_gateway/root」「/dev/sda2」「/dev/sda1」はレスキューモードにしたタイミングで既にマウントされていました。

vgchange -ay
mount /dev/centos_gateway/root /mnt/sysimage
mount /dev/sda2 /mnt/sysimage/boot
mount /dev/sda1 /mnt/sysimage/boot/efi
mount --bind /proc /mnt/sysimage/proc
mount --bind /sys /mnt/sysimage/sys
mount --bind /dev /mnt/sysimage/dev
chroot /mnt/sysimage
cp -p /boot/efi/EFI/centos/grubx64.efi /boot/efi/EFI/BOOT/
exit
umount -R /mnt/sysimage
shutdown -r now


これでローカルからブートしたらもとに戻せました。


f:id:think-t:20180904012050j:plain


今日はこんなところで。

パスワード変更時に「/usr/share/cracklib/pw_dict: error reading header」エラーが出たときの対処メモ

普段作業用に使っているVMのパスワードがなぜか変更できなくなったので、
そのとき調査したことと、復旧で行ったことをメモしておきます。


環境はCentOS6.6の64ビット版です。

起きたこと


passwd コマンドを使って、パスワードを変更しようとしたところ、以下のようなメッセージが出ました。

# passwd
ユーザー root のパスワードを変更。
新しいパスワード:
/usr/share/cracklib/pw_dict: error reading header
PWOpen: 成功です

調べた


参考リンクを元に環境を調べたところ、cracklibの辞書ファイルが0バイトになっていたため、辞書ファイルが壊れてしまったと推測。

# cd /usr/share/cracklib/
# ls -la
合計 264
drwxr-xr-x.  2 root root   4096  7月 21 12:13 2014 .
drwxr-xr-x. 78 root root   4096  5月 31 16:24 2016 ..
-rw-r--r--.  1 root root   1024  6月 25 15:39 2011 cracklib-small.hwm
-rw-r--r--.  1 root root 235109  6月 25 15:39 2011 cracklib-small.pwd
-rw-r--r--.  1 root root  12416  6月 25 15:39 2011 cracklib-small.pwi
-rw-r--r--.  1 root root    360  6月 25 15:39 2011 cracklib.magic
-rw-r--r--.  1 root root      0  1月 27 16:55 2015 pw_dict.hwm
-rw-r--r--.  1 root root      0  1月 27 16:55 2015 pw_dict.pwd
-rw-r--r--.  1 root root      0  1月 27 16:55 2015 pw_dict.pwi

直す


該当するファイルが含まれるRPMパッケージを確認すると「cracklib-dicts」であることが分かったので、これをインストールしなおすことにしました。

# rpm -qf /usr/share/cracklib/pw_dict.hwm 
cracklib-dicts-2.8.16-4.el6.x86_64


パッケージの依存関係に「pam」があったので、強制再インストールにすることにしました。

# rpm -q --whatrequires cracklib-dicts                                                                             
pam-1.1.1-20.el6.x86_64

# yumdownloader cracklib-dicts
# rpm -Uvh --force cracklib-dicts-2.8.16-4.el6.x86_64.rpm 


cracklib-dictsパッケージの再インストールを行った結果、パスワード変更ができるようになりました。

# passwd
ユーザー root のパスワードを変更。
新しいパスワード:
新しいパスワードを再入力してください:
passwd: 全ての認証トークンが正しく更新できました。


今日はこんなところで。