循环设备 /dev/loopx
/dev/loop(或称vnd (vnode disk)、lofi(循环文件接口))是一种伪设备,这种设备使得文件可以如同块设备一般被访问。
fallocate -l 10G ~/test.img
mkfs.btrfs ~/test.img
mount -o loop ~/test.img /mnt/test
df结果
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 37G 24G 12G 66% /
devtmpfs 900M 0 900M 0% /dev
tmpfs 911M 0 911M 0% /dev/shm
tmpfs 911M 17M 894M 2% /run
tmpfs 911M 0 911M 0% /sys/fs/cgroup
/dev/sda2 477M 119M 329M 27% /boot
tmpfs 183M 0 183M 0% /run/user/0
/dev/loop0 10G 17M 8.0G 1% /test
/dev/loop1 10G 1.1G 7.1G 14% /var/bocker
[root@localhost /]#
btrfs
[root@localhost dev]# sh -x /usr/bin/bocker run img_42133 l
+ set -o errexit -o nounset -o pipefail
+ shopt -s nullglob
+ btrfs_path=/var/bocker
+ cgroups=cpu,cpuacct,memory
+ [[ 3 -gt 0 ]]
+ '[' ru == -- ']'
+ [[ -z run ]]
+ case $1 in
+ bocker_run img_42133 l
++ shuf -i 42002-42254 -n 1
+ uuid=ps_42156
++ bocker_check img_42133
++ grep -qw img_42133
++ btrfs subvolume list /var/bocker
++ echo 0
+ [[ 0 == 1 ]]
++ bocker_check ps_42156
++ grep -qw ps_42156
++ btrfs subvolume list /var/bocker
++ echo 1
+ [[ 1 == 0 ]]
+ cmd=l
++ echo 156
++ sed s/0//g
+ ip=156
+ mac=1:56
+ ip link add dev veth0_ps_42156 type veth peer name veth1_ps_42156
+ ip link set dev veth0_ps_42156 up
+ ip link set veth0_ps_42156 master bridge0
+ ip netns add netns_ps_42156
+ ip link set veth1_ps_42156 netns netns_ps_42156
+ ip netns exec netns_ps_42156 ip link set dev lo up
+ ip netns exec netns_ps_42156 ip link set veth1_ps_42156 address 02:42:ac:11:001:56
+ ip netns exec netns_ps_42156 ip addr add 10.0.0.156/24 dev veth1_ps_42156
+ ip netns exec netns_ps_42156 ip link set dev veth1_ps_42156 up
+ ip netns exec netns_ps_42156 ip route add default via 10.0.0.1
+ btrfs subvolume snapshot /var/bocker/img_42133 /var/bocker/ps_42156
+ echo 'nameserver 8.8.8.8'
+ echo l
+ cgcreate -g cpu,cpuacct,memory:/ps_42156
+ : 512
+ cgset -r cpu.shares=512 ps_42156
+ : 512
+ cgset -r memory.limit_in_bytes=512000000 ps_42156
+ tee /var/bocker/ps_42156/ps_42156.log
+ cgexec -g cpu,cpuacct,memory:ps_42156 ip netns exec netns_ps_42156 unshare -fmuip --mount-proc chroot /var/bocker/ps_42156 /bin/sh -c '/bin/mount -t proc proc /proc && l'
/bin/sh: l: command not found
+ true
+ ip link del dev veth0_ps_42156
+ ip netns del netns_ps_42156