Browse Source

week11

master
RinRi 1 year ago
parent
commit
93e1c6e2f6
7 changed files with 75 additions and 0 deletions
  1. +1
    -0
      week11/.gitignore
  2. +12
    -0
      week11/ex1.sh
  3. BIN
      week11/ex2
  4. +21
    -0
      week11/ex2.c
  5. BIN
      week11/ex2.out
  6. +36
    -0
      week11/ex2.sh
  7. +5
    -0
      week11/ex2.txt

+ 1
- 0
week11/.gitignore View File

@@ -0,0 +1 @@
lofs*

+ 12
- 0
week11/ex1.sh View File

@@ -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

BIN
week11/ex2 View File


+ 21
- 0
week11/ex2.c View File

@@ -0,0 +1,21 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>

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);
}
}

BIN
week11/ex2.out View File


+ 36
- 0
week11/ex2.sh View File

@@ -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

+ 5
- 0
week11/ex2.txt View File

@@ -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

Loading…
Cancel
Save