6 PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin"
12 # As we will write one byte, we have to subtract it from total size
16 echo "usage: $0 FILESYSTEM_TGZ FILESYSTEM_SIZE EXT4_BLOCK_SIZE" >&2
20 # Perform sanity checks before we install cleanup handler
21 if test -z "$SUDO_UID"; then
22 echo "$0: error: use sudo to run this script" >&2
26 if test "$SUDO_UID" -ne "`stat -c '%u' \"$INFILE\" 2>/dev/null`"; then
27 echo "$0: error: you aren't owner of input file $INFILE" >&2
34 test "$OUTFILE" -a -f "$OUTFILE" && rm -f "$OUTFILE" >&2
38 if mountpoint -q "$MNT"; then
41 rmdir "$MNT" >&2 || true
48 MNT="`mktemp -d /tmp/make-ext4.mountpoint.XXXXXX 2>/dev/null`"
49 OUTFILE="`mktemp /tmp/make-ext4.filesystem.XXXXXX 2>/dev/null`"
52 # Create sparse file for filesystem
53 dd if=/dev/zero of="$OUTFILE" bs=1 seek="$SEEK" count=1 >&2
54 mkfs.ext4 -O '^huge_file' -F "$OUTFILE" -b "$EXT4_BLOCK_SIZE" >&2
56 mount -o loop "$OUTFILE" "$MNT" >&2
57 tar xlpsfC "$INFILE" "$MNT" >&2
60 # Allow user to do what he wants with newly created file
61 chown "$SUDO_UID:$SUDO_GID" "$OUTFILE" >&2