-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrebuild-rootfs.sh
More file actions
executable file
·62 lines (45 loc) · 1.73 KB
/
rebuild-rootfs.sh
File metadata and controls
executable file
·62 lines (45 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
#################################################################################
# Parameters
#################################################################################
# The rootfs image file
ROOTFS_IMAGE=$PWD/images/web-server-rootfs.ext4
# Temporary mount folder
MOUNT_FOLDER=/tmp/microvm-web-server
# Rust Executable
EXECUTABLE_NAME=web-server
EXECUTABLE_SOURCE=./web-server/target/x86_64-unknown-linux-musl/release/$EXECUTABLE_NAME
#################################################################################
# Rebuild the executable and copy it to the rootfs image
#################################################################################
# Switch to the Rust program folder
cd ./web-server
# Rebuild the Rust executable using the x86_64-unknown-linux-musl target in order to run inside the Micro VM
cargo build --target x86_64-unknown-linux-musl --release
# Switch back to script folder
cd ..
# Try to unmount folder
echo 'Umount image in case is still mounted'
sudo umount $MOUNT_FOLDER
# Remove mount folder
echo 'Removing old mount folder'
sudo rm -Rf $MOUNT_FOLDER
# Create mount folder
echo 'Creating the mount folder'
sudo mkdir $MOUNT_FOLDER
# Mount image on mount folder
echo 'Mounting the rootfs image'
sudo mount $ROOTFS_IMAGE $MOUNT_FOLDER
# Remove old executable
echo 'Removing old executable'
sudo rm -f $MOUNT_FOLDER/bin/$EXECUTABLE_NAME
# Copy executable into rootfs bin folder
echo 'Copying new executable to rootfs image'
sudo cp $EXECUTABLE_SOURCE $MOUNT_FOLDER/bin
# Make it executable
echo 'Making the new file executable'
sudo chmod +x $MOUNT_FOLDER/bin
# Unmount the rootfs image
echo 'Unmount the rootfs image'
sudo umount $MOUNT_FOLDER
echo 'Rootfs image updated with new executable'