Skip to content

Instantly share code, notes, and snippets.

@algermissen
Created March 18, 2023 10:24
Show Gist options
  • Save algermissen/413689b57e806716462b4dd01e3c2be9 to your computer and use it in GitHub Desktop.
Save algermissen/413689b57e806716462b4dd01e3c2be9 to your computer and use it in GitHub Desktop.
Creates a simple root filesystem layout
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "Please provide dir to create the root file system in"
exit 1
fi
ROOT=$1
if [ -e "$ROOT" ]
then
echo "$ROOT already exists"
exit 1
fi
mkdir -p "$ROOT"/{etc,tmp,proc,sys,dev,home,mnt,root,usr/{bin,sbin,lib},var} && chmod a+rwxt "$ROOT"/tmp
cat > "$ROOT"/etc/passwd << 'EOF' &&
root::0:0:root:/root:/bin/sh
guest:x:500:500:guest:/home/guest:/bin/sh
nobody:x:65534:65534:nobody:/proc/self:/dev/null
EOF
cat > "$ROOT"/etc/group << 'EOF' &&
root:x:0:
guest:x:500:
EOF
echo "nameserver 8.8.8.8" > "$ROOT"/etc/resolv.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment