Hacker News new | ask | show | jobs
by ravenstine 929 days ago
I've been doing something similar recently, though it doesn't directly convert a tar to an ext4 FS. But maybe this can help you get to where you want to be.

On Alpine Linux:

```

apk add --no-cache coreutils e2fsprogs

```

```

#!/bin/sh

# Untar the tar file

mkdir -p /tmp/my_untarred_files_dir

tar -xvf my_tar_file.tar -C /tmp/my_untarred_files_dir

# Make an empty image file.

dd if=/dev/zero of="fs.raw" bs=1M count=1024

# Format the file as ext4 (with journaling) and copy untarred files into it

mke2fs -t ext4 -j -d "/tmp/my_untarred_files_dir" "fs.raw"

```

If you want to make a qcow2 image, you can then do this:

```

apk add --no-cache qemu-img

qemu-img convert -O qcow2 "fs.raw" "fs.qcow2"

```