LoginSignup
2
2

More than 5 years have passed since last update.

Allow loopback mounting file inside LXC containers

Last updated at Posted at 2014-10-03

TeXを使いたいときにinstall-tl-ubuntuを使っている。
ただし、vagrant-lxcのようなコンテナ環境でprovisioningするときにそのままこのコマンドを使うと、そのたびに大量のダウンロードが発生するので好ましくない。
そこで

$ sudo bash install-tl-ubuntu -i /vagrant/texlive2014-20140525.iso

としたいわけだが、

mount: block device /dev/loop0 is write-protected, mounting read-only
mount: cannot mount block device /dev/loop0 read-only

などと怒られてマウントできない。
このようなときは、host側で以下の操作でiso9660でもloopbackデバイスを使えるようにする。

sudo tee /etc/apparmor.d/lxc/lxc-default-with-mounting-custom <<EOF
profile lxc-container-default-with-mounting-custom flags=(attach_disconnected,mediate_deleted) {
  #include <abstractions/lxc/container-base>
  mount fstype=ext*,
  mount fstype=xfs,
  mount fstype=btrfs,
  mount fstype=iso9660,
}
EOF
sudo apparmor_parser --replace /etc/apparmor.d/lxc-containers

自分のコンテナ起動用のVagrantfileはこんな感じ

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do config
config.vm.box = 'fgrehm/trusty64-lxc'
config.vm.define "test"
config.vm.provider :lxc do lxc
# allow_loop-back_device
lxc.customize 'aa_profile', 'lxc-container-default-with-mounting-custom'
lxc.customize 'cgroup.devices.allow', 'b 7:* rwm'
lxc.customize 'cgroup.devices.allow', 'c 10:237 rwm'
end
config.vm.provision :shell, :path =>  "https://gist.githubusercontent.com/ごにょごにょ/raw/site.sh", :privileged => false
end

で、立ち上げると

vagrant@vagrant-base-trusty-amd64:~$ sudo mount -t iso9660 -o loop,ro /vagrant/texlive2014-20140525.iso /mnt
vagrant@vagrant-base-trusty-amd64:~$ ls /mnt
archive index.html install-tl-advanced.bat LICENSE.CTAN README
readme-txt.dir release-texlive.txt texlive-doc tl-tray-menu.exe
autorun.inf install-tl install-tl-windows.bat LICENSE.TL readme-html.dir
README.usergroups source tlpkg
vagrant@vagrant-base-trusty-amd64:~$

これで install-tl-ubuntu -i /vagrant/texlive2014-20140525.iso ができるようになった

2
2
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
2
2