Here is how to share /dec/sdb3 of LXC host with a container.
Reference
http://askubuntu.com/questions/528161/how-to-make-a-hdd-device-file-dev-sdxy-available-in-lxc-container
root@ubuntu:~# tail -1 /etc/lsb-release
DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS"
root@ubuntu:~# dpkg -l lxc | tail -1
ii lxc 1.0.7-0ubuntu0.9 amd64 Linux Containers userspace tools
[ edit fstab of a container ]
on the LXC host, edit fstab of a container "ubuntu-cn01"
root@ubuntu:~# cat /var/lib/lxc/ubuntu-cn01/fstab
/dev/sdb3 mnt/sdb3 ext4 noatime 0 0
root@ubuntu:~# grep lxc.mount /var/lib/lxc/ubuntu-cn01/config
lxc.mount.auto = cgroup
lxc.mount = /var/lib/lxc/ubuntu-cn01/fstab
start the container.
error
root@ubuntu:~# lxc-start -n ubuntu-cn01 -d
lxc-start: lxc_start.c: main: 342 The container failed to start.
lxc-start: lxc_start.c: main: 344 To get more details, run the container in foreground mode.
lxc-start: lxc_start.c: main: 346 Additional information can be obtained by setting the --logfile and --logpriority options.
start the container again with logfile option.
root@ubuntu:~# lxc-start -n ubuntu-cn01 -d --logfile log_ubuntu-cn01
lxc-start: lxc_start.c: main: 342 The container failed to start.
lxc-start: lxc_start.c: main: 344 To get more details, run the container in foreground mode.
lxc-start: lxc_start.c: main: 346 Additional information can be obtained by setting the --logfile and --logpriority options.
check the log file.
There is no mnt/sdb3 directory in the container.
root@ubuntu:~# cat log_ubuntu-cn01
lxc-start 1446740734.065 ERROR lxc_utils - utils.c:safe_mount:1434 - No such file or directory - Mount of '/dev/sdb3' onto '/usr/lib/x86_64-linux-gnu/lxc/mnt/sdb3' failed
lxc-start 1446740734.065 ERROR lxc_conf - conf.c:mount_entry:2051 - No such file or directory - failed to mount '/dev/sdb3' on '/usr/lib/x86_64-linux-gnu/lxc/mnt/sdb3'
lxc-start 1446740734.065 ERROR lxc_conf - conf.c:lxc_setup:4160 - failed to setup the mounts for 'ubuntu-cn01'
create a direcotry.
root@ubuntu:~# mkdir /var/lib/lxc/ubuntu-cn01/rootfs/mnt/sdb3
start the container
root@ubuntu:~# lxc-start -n ubuntu-cn01 -d
I was able to see a mount point in the container.
root@ubuntu-cn01:~# ls /mnt/sdb3/
hello.txt lost+found
[ device option ]
check the major/minor of /des/sdb3 on the LXC host
root@ubuntu:~# sudo ls -l /dev/sdb3
brw-rw---- 1 root disk 8, 19 11月 5 21:38 /dev/sdb3
create a block device for the container.
root@ubuntu:~# mknod /var/lib/lxc/ubuntu-cn01/rootfs/dev/sdb3 b 8 19
edit config file of the container.
root@ubuntu:~# tail -2 /var/lib/lxc/ubuntu-cn01/config
lxc.cgroup.devices.allow = b 8:19 rwm
lxc.mount.entry = /dev/sdb3 /var/lib/lxc/ubuntu-cn01/rootfs/dev/sdb3 none bind 0 0
start the container.
root@ubuntu:~# lxc-start -n ubuntu-cn01 -d
on the container
root@ubuntu-cn01:~# mount | grep sdb3
udev on /dev/sdb3 type devtmpfs (rw,relatime,size=8040160k,nr_inodes=2010040,mode=755)
mount /dev/sdb3.
root@ubuntu-cn01:~# mount -t ext4 /dev/sdb3 tmp_dir1
root@ubuntu-cn01:~#
root@ubuntu-cn01:~# mount | grep sdb3
udev on /dev/sdb3 type devtmpfs (rw,relatime,size=8040160k,nr_inodes=2010040,mode=755)
/dev/sdb3 on /root/tmp_dir1 type ext4 (rw)
root@ubuntu-cn01:~#
root@ubuntu-cn01:~# ls -l tmp_dir1/
合計 16
-rw-r--r-- 1 root root 0 11月 6 01:08 hello.txt
drwx------ 2 root root 16384 11月 5 01:25 lost+found
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.