aboutsummaryrefslogtreecommitdiff
path: root/util/mkrootfs
blob: 91eff68e2ab490bec57b0d0a3c16d36bc03a5d8d (plain)
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
#!/bin/sh
OLDPWD="$PWD"
cd "$(dirname "$0")"
BUSYBOX_FS="$(realpath ../busybox/rootfs)"
OVERLAY_FS="$(realpath ../rootfs)"
cd "$OLDPWD"

# change into the (mounted) target rootfs folder
cd "$1"

# scaffold folders
for dir in bin dev etc home lib mnt opt proc root run sbin srv sys tmp usr var ; do
	mkdir -p "$dir"
done

# create special devices
! [ -c dev/mem ] && mknod dev/mem c 1 1
! [ -c dev/null ] && mknod dev/null c 1 3
! [ -c dev/random ] && mknod dev/random c 1 8
! [ -c dev/urandom ] && mknod dev/urandom c 1 9
! [ -c dev/zero ] && mknod dev/zero c 1 5

# copy busybox files and overlay files
CPFLAGS='--no-dereference --recursive --preserve=mode,timestamps,links --no-preserve=owner'
cp $CPFLAGS "$BUSYBOX_FS/." .
cp $CPFLAGS "$OVERLAY_FS/." .

# setuid busybox
chmod a=xrs,u+w bin/busybox

# create a root user
! [ -e etc/passwd ] && echo "root:x:0:0::/root:/bin/sh" > etc/passwd
! [ -e etc/shadow ] && echo "root:!:0:0:99999:0:::" > etc/shadow
! [ -e etc/group ] && echo "root:x:0:root" > etc/shadow

# exit safely (continue makefile)
exit 0