LoginSignup
11
12

More than 5 years have passed since last update.

CentOS 7 で overlayfs を使う手順

Posted at

はじめに

CentOS 7 で overlayfs を使ってみたので、その際の手順をまとめておきます。
なお、環境は AWS EC2 上の CentOS 7 です。

overlayfs は Linux Kernel 3.18 からマージされています。現時点の CentOS 7 のカーネルは 3.10 なので、まずはカーネルのアップデートから行います。

CentOS 7 に最新カーネルをインストールする

最新カーネルは ELRepo というリポジトリからインストールします。ELRepo は主に最新のドライバが公開されているリポジトリです。

(1) リポジトリのインストール

$ sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
$ sudo rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

(2) カーネルのインストール

$ sudo yum --enablerepo=elrepo-kernel install kernel-ml

(3) grub の設定

grub.conf に書かれている起動エントリーを確認。

$ awk -F\' '$1=="menuentry " {print $2}' /boot/grub2/grub.cfg
CentOS Linux (4.2.1-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux, with Linux 3.10.0-123.8.1.el7.x86_64
CentOS Linux, with Linux 0-rescue-f9afeb75a5a382dce8269887a67fbf58

この場合は、先頭のエントリ(0番目のエントリ)から起動したいので、以下のように実行して再起動。

$ sudo grub2-set-default 0
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
$ sudo reboot

(4) カーネルバージョンの確認
再起動後、ログインしてカーネルバージョンを確認。

$ uname -r
4.2.1-1.el7.elrepo.x86_64

overlayfs を使う

overlayfs は Union Filesystem の1つで、複数のディレクトリツリーを重ねて1つのディレクトリツリーとして見せることができます。この辺りはいろんなサイトに情報が載っているので、以下では設定手順だけ記載します。

# overlayfs 用のディレクトリを作成
$ mkdir lower upper work merged

# lower と upper ディレクトリにファイルを作成
$ echo "111" > lower/file1
$ echo "222" > upper/file2

# マウント(lower と upper ディレクトリを重ね合わせたものを merged ディレクトリで見せる)
$ sudo mount -t overlay -o lowerdir=lower,upperdir=upper,workdir=work overlay merged

# 重ね合わされたディレクトリの中身を確認
$ ls merged/
file1  file2

参考サイト

http://linoxide.com/how-tos/install-linux-kernel-4-0-elrepo-source/
http://wiki.mikejung.biz/CentOS_7
http://gihyo.jp/admin/serial/01/linux_containers/0018

11
12
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
11
12