Skip to content

Instantly share code, notes, and snippets.

@afeish
Last active March 4, 2022 09:31
Show Gist options
  • Save afeish/568f886a42cd5360204c9adaed41f17c to your computer and use it in GitHub Desktop.
Save afeish/568f886a42cd5360204c9adaed41f17c to your computer and use it in GitHub Desktop.
test linux bind mount propogation

test with linux bind propogation

dd if=/dev/zero of=01.img bs=512 count=2880 conv=notrunc
dd if=/dev/zero of=02.img bs=512 count=2880 conv=notrunc

sudo losetup /dev/loop100 01.img
sudo losetup /dev/loop101 02.img

losetup -a

sudo mkfs -t ext2 /dev/loop100 
sudo mkfs -t ext2 /dev/loop101

mkdir origin shared slave private

sudo mount /dev/loop100 origin 

sudo mount --bind origin shared
sudo mount --bind origin slave
sudo mount --bind origin private
sudo mount --make-shared shared
sudo mount --make-slave slave
sudo mount --make-private private

sudo mkdir origin/{shared,slave,private}

echo "testing shared propogation ..."
sudo mount /dev/loop101 origin/shared
echo "hello shared mount (origin mount)" | sudo tee -a  origin/shared/hello.txt
diff shared/shared/hello.txt origin/shared/hello.txt 
echo "hello shared mount from replica (origin mount)" | sudo tee -a  shared/shared/hello.txt
diff shared/shared/hello.txt origin/shared/hello.txt 
sudo umount origin/shared

echo "testing slave propogation ..."
sudo mount /dev/loop101 origin/slave
echo "hello slave mount (origin mount)" | sudo tee -a  origin/slave/hello.txt
diff slave/slave/hello.txt origin/slave/hello.txt 
echo "hello slave mount from replica (origin mount)" | sudo tee -a  slave/slave/hello.txt
diff slave/slave/hello.txt origin/slave/hello.txt 
sudo umount origin/slave

sudo mount /dev/loop101 slave/slave
echo "hello slave mount from replica (slave mount)" | sudo tee -a  slave/slave/hello.txt
diff slave/slave/hello.txt origin/slave/hello.txt 
sudo umount slave/slave

echo "testing private propogation ..."
sudo mount /dev/loop101 origin/private
echo "hello private mount (from origin dir)" | sudo tee -a  origin/private/hello.txt
! test -f private/private/hello.txt && echo "private mount not propogated to replica (origin mount)"
echo "hello private mount from replica (from origin dir)" | sudo tee -a  private/private/hello.txt
! test -f origin/private/hello.txt && echo "private mount not propogated to origin (origin mount)"
sudo umount origin/private

sudo mount /dev/loop101 private/private
echo "hello private mount from replica (replica mount)" | sudo tee -a  private/private/hello.txt
diff private/private/hello.txt origin/private/hello.txt 
sudo umount private/private


sudo umount origin/shared || true
sudo umount origin/slave || true
sudo umount origin/private || true
sudo umount slave/slave || true
sudo umount private/private || true

sudo umount origin || true
sudo umount shared || true
sudo umount slave || true
sudo umount private || true
sudo rm -rf origin shared slave private
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment