# BlissOSx86 - Unpacking & Repacking ISO

This is a quick guide to the full round trip:

- extract a bootable ISO
- unpack compressed system image
- apply modifications
- repack it back into a bootable ISO.

## 1\. Prerequisites

Make sure you have the following packages installed:

1. `p7zip` - extracting iso
2. `squashfs-tools` / `erofs-utils` - unpacking system image
3. `genisoimage` - creating iso

## 2\. Extract ISO contents

```bash
7z x <ISO_PATH>.iso -oextracted
```

## 3\. Unpack system image

Depending on the build, you'll find either `system.sfs` (SquashFS) or `system.efs` (EROFS) inside the `extracted` folder.

## 3.1. Case A - `system.sfs`

### 3.1.1. Prerequisites

- Make sure you have the `squashfs-tools` package installed.

### 3.1.2. Extract system image

```bash
mkdir -p system-root
sudo unsquashfs -d system-root extracted/system.sfs
```

## 3.2. Case B - `system.efs`

### 3.2.1 Prerequisites

- Make sure you have the `erofs-utils` package installed.

### 3.2.2. Extract system image

```bash
mkdir -p system-root
sudo fsck.erofs --extract=system-root --preserve extracted/system.efs
```

## 4\. Mount system image

Whatever *case* you dealt with will finally give you a `system.img` which we all were waiting for from the beginning.

```bash
mkdir -p system_mnt/
sudo mount -o loop system-root/system.img system_mnt/
```

<div data-node-type="callout">
<div data-node-type="callout-emoji">🎉</div>
<div data-node-type="callout-text"><h2>Congrats if you are here! Now follow the other guides to modify your system</h2></div>
</div>

## 5\. Unmount system image

Now that you are done modifying your system image, you need to unmount it to proceed further.

```bash
sudo umount system_mnt/
rm -rfd system_mnt/
```

## 6\. Repack system image

Just like we faced two cases during unpacking, steps differ here also

### 6.1. Case A - `system.sfs`

- Create the `SquashFS` file

```bash
sudo mksquashfs system-root extracted/system.sfs -comp zstd -noappend
```

### 6.2. Case B - `system.efs`

- Create the `EROFS` file

```bash
sudo mkfs.erofs -z zlz4hc -C 65536 extracted/system.efs system-root
```

## 7\. ISO Creation

The final step before creating the bootable ISO file of your own modified system!

### 7.1. Prerequisites

- Make sure you have the `genisoimage` package installed.

### 7.2. Create ISO

```bash
mkisofs \
 -V "BlissOS-Custom" \
 -o BlissOS-Custom.iso \
 -b isolinux/isolinux.bin \
 -c isolinux/boot.cat \
 -boot-info-table \
 -boot-load-size 4 \
 -joliet-long \
 -no-emul-boot \
 -J \
 -l \
 -R \
 extracted/
```
