Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Allow loopback mounting file inside LXC containers

More than 5 years have passed since last update.

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 ができるようになった

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away