diff --git a/week11/.gitignore b/week11/.gitignore new file mode 100644 index 0000000..515478d --- /dev/null +++ b/week11/.gitignore @@ -0,0 +1 @@ +lofs* diff --git a/week11/ex1.sh b/week11/ex1.sh new file mode 100755 index 0000000..4cf3a97 --- /dev/null +++ b/week11/ex1.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +sudo umount lofsdisk +sudo losetup -d $(sudo losetup -j lofs.img | awk -F ':' '{ print $1; }') +rm -rf lofsdisk lofs.img + +dd if=/dev/zero of=lofs.img bs=100M count=1 +mkfs.ext4 lofs.img +lodevice=$(sudo losetup -fP --show lofs.img) +mkdir lofsdisk +sudo mount "$lodevice" lofsdisk +sudo chmod -R 777 lofsdisk diff --git a/week11/ex2 b/week11/ex2 new file mode 100755 index 0000000..fc70d26 Binary files /dev/null and b/week11/ex2 differ diff --git a/week11/ex2.c b/week11/ex2.c new file mode 100644 index 0000000..3fdb198 --- /dev/null +++ b/week11/ex2.c @@ -0,0 +1,21 @@ +#include +#include +#include +#include +#include + +int main() { + DIR *d = opendir("/"); + if (d == NULL) { + perror("opendir"); + exit(1); + } + + struct dirent *entry; + while ((entry = readdir(d))!= NULL) { + if (entry->d_name[0] == '.') + continue; + + printf("%s ", entry->d_name); + } +} diff --git a/week11/ex2.out b/week11/ex2.out new file mode 100755 index 0000000..fc70d26 Binary files /dev/null and b/week11/ex2.out differ diff --git a/week11/ex2.sh b/week11/ex2.sh new file mode 100755 index 0000000..75410c3 --- /dev/null +++ b/week11/ex2.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +chmod +x ex1.sh +./ex1.sh + +echo "Amirlan" > lofsdisk/file1 +echo "Sharipov" > lofsdisk/file2 + +mkdir lofsdisk/usr +mkdir lofsdisk/usr/bin +mkdir lofsdisk/usr/lib +mkdir lofsdisk/usr/lib64 + +# I am using Arch Linux, that's why some libraries may differ from Ubuntu +# Sorry for the inconvinience + +cp /bin/bash /bin/ls /bin/echo /bin/cat lofsdisk/usr/bin +cp /lib/libreadline.so* lofsdisk/usr/lib/ +cp /lib/libdl.so.2* lofsdisk/usr/lib/ +cp /lib/libc.so* lofsdisk/usr/lib/ +cp /lib/libncursesw.so* lofsdisk/usr/lib/ +cp /lib/libcap.so.2* lofsdisk/usr/lib/ +cp /lib64/ld-linux-x86-64.so.2 lofsdisk/usr/lib64/ + +# symbolic links contain just the path, so after chroot they will pick the directories inside lofsdisk +ln -sf /usr/lib lofsdisk/lib +ln -sf /usr/lib64 lofsdisk/lib64 +ln -sf /usr/bin lofsdisk/bin + +gcc ex2.c -o ex2.out +cp ex2.out lofsdisk + +printf "\nW/ CHROOT\n" > ex2.txt +sudo chroot lofsdisk /ex2.out >> ex2.txt +printf "\nW/O CHROOT\n" >> ex2.txt +./ex2.out >> ex2.txt diff --git a/week11/ex2.txt b/week11/ex2.txt new file mode 100644 index 0000000..e603252 --- /dev/null +++ b/week11/ex2.txt @@ -0,0 +1,5 @@ + +W/ CHROOT +usr lib64 lost+found lib bin file1 file2 ex2.out +W/O CHROOT +tmp var opt home dev run etc bin lost+found lib sys sbin lib64 proc usr mnt root boot srv \ No newline at end of file