{"id":22370031,"url":"https://github.com/andreicherniaev/buildroot_qemu_mount_f2fs_compression_x86","last_synced_at":"2026-01-05T19:45:49.830Z","repository":{"id":261801588,"uuid":"885377122","full_name":"AndreiCherniaev/buildroot_QEMU_mount_f2fs_compression_x86","owner":"AndreiCherniaev","description":"Linux which can mount f2fs filesystem with compression","archived":false,"fork":false,"pushed_at":"2024-11-12T14:02:15.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T19:42:41.622Z","etag":null,"topics":["buildroot","example","f2fs","mount"],"latest_commit_sha":null,"homepage":"https://stackoverflow.com/questions/79168984/how-to-mount-f2fs-with-option-compress-algorithm","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AndreiCherniaev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-08T13:22:12.000Z","updated_at":"2024-11-12T14:02:18.000Z","dependencies_parsed_at":"2024-11-08T14:39:27.633Z","dependency_job_id":"5ed90038-7c6c-48d2-901f-b85d94e0a034","html_url":"https://github.com/AndreiCherniaev/buildroot_QEMU_mount_f2fs_compression_x86","commit_stats":null,"previous_names":["andreicherniaev/buildroot_qemu_mount_f2fs_compression_x86"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreiCherniaev%2Fbuildroot_QEMU_mount_f2fs_compression_x86","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreiCherniaev%2Fbuildroot_QEMU_mount_f2fs_compression_x86/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreiCherniaev%2Fbuildroot_QEMU_mount_f2fs_compression_x86/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreiCherniaev%2Fbuildroot_QEMU_mount_f2fs_compression_x86/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndreiCherniaev","download_url":"https://codeload.github.com/AndreiCherniaev/buildroot_QEMU_mount_f2fs_compression_x86/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245690481,"owners_count":20656592,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["buildroot","example","f2fs","mount"],"created_at":"2024-12-04T19:31:53.246Z","updated_at":"2026-01-05T19:45:49.825Z","avatar_url":"https://github.com/AndreiCherniaev.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"How to build Linux image which can mount f2fs filesystem with compression. So I want this script to be working\n```\nmkdir -p /mnt/sda2\nmount -o compress_algorithm=zstd:1,compress_chksum,atgc,gc_merge,lazytime /dev/sda2 /mnt/sda2\n```\n# Details\n## Ubuntu and f2fs\nIn Ubuntu 24.04.1 works good. First step I can make f2fs partition\n```\n# mkfs.f2fs -f -l mylable123 -i -O extra_attr,inode_checksum,sb_checksum,compression -e raw -E bin /dev/sdb\n\n    F2FS-tools: mkfs.f2fs Ver: 1.16.0 (2023-04-11)\n\nInfo: Disable heap-based policy\nInfo: Debug level = 0\nInfo: Add new cold file extension list\nInfo: Add new hot file extension list\nInfo: Label = mylable123\nInfo: Trim is enabled\nInfo: Enable Compression\nInfo: [/dev/sdb] Disk Model: Flash Disk      \n    /dev/sdb appears to contain a partition table (dos).\nInfo: Segments per section = 1\nInfo: Sections per zone = 1\nInfo: sector size = 512\nInfo: total sectors = 15974400 (7800 MB)\nInfo: zone aligned segment0 blkaddr: 512\nInfo: format version with\n  \"Linux version 6.8.0-48-generic (buildd@lcy02-amd64-010) (x86_64-linux-gnu-gcc-13 (Ubuntu 13.2.0-23ubuntu4) 13.2.0, GNU ld (GNU Binutils for Ubuntu) 2.42) #48-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 27 14:04:52 UTC 2024\"\nInfo: [/dev/sdb] Discarding device\nInfo: This device doesn't support BLKSECDISCARD\nInfo: This device doesn't support BLKDISCARD\nInfo: Overprovision ratio = 1.710%\nInfo: Overprovision segments = 67 (GC reserved = 65)\nInfo: format successful\n```\nSecond (and main for me) step - I can mount with compression:\n```\nmkdir -p /mnt/sda2\nmount -o compress_algorithm=zstd:1,compress_chksum,atgc,gc_merge,lazytime /dev/sdb /mnt/sda2\numount /mnt/sda2\n```\n\n## Own kernel and f2fs\n### Mainline 6.6\nLet's try to make our own Linux image. First time I have tried to use kernel 6.6 config but with f2fs options enabled\n```\nCONFIG_F2FS_FS=y\nCONFIG_F2FS_CHECK_FS=y\nCONFIG_F2FS_FAULT_INJECTION=y\nCONFIG_F2FS_FS_COMPRESSION=y\n```\nFail:\n```\n# mount -o compress_algorithm=zstd:1,compress_chksum,atgc,gc_merge,lazytime /dev/sda2 /mnt/sda2\nmount: mounting /dev/sda2 on /mnt/sda2 failed: Invalid argument\n```\n### Ubuntu's kernel 6.8\nThen I taken `/boot/config-6.8.0-48-generic` kernel config from Ubuntu 24 where f2fs compression can works and try to use it. I have cut some parts relative to hardware drivers... Of course, it's good practice not to change anything, but I can't compile Ubuntu kernel as is due to a lot of build failures... Finally the same problem, log\n```\n# uname -a\nLinux buildroot 6.8.0 #2 SMP PREEMPT_DYNAMIC Fri Nov  8 21:36:02 KST 2024 i686 GNU/Linux\n# mkdir /mnt/sda2\n# mount -o compress_algorithm=zstd:1,compress_chksum,atgc,gc_merge,lazytime /dev\n/sdc /mnt/sda2/\n[  582.682848] ext3: Unknown parameter 'compress_algorithm'\n[  582.683882] ext2: Unknown parameter 'compress_algorithm'\n[  582.684615] ext4: Unknown parameter 'compress_algorithm'\n[  582.685248] squashfs: Unknown parameter 'compress_algorithm'\n[  582.686661] fuseblk: Unknown parameter 'compress_algorithm'\nmount: mounting /dev/sdc on /mnt/sda2/ failed: Invalid argument\n```\n# How to repeat\n## Clone\n```\ngit clone --remote-submodules --recurse-submodules -j8 https://github.com/AndreiCherniaev/buildroot_QEMU_f2fs_x86.git\ncd buildroot_QEMU_f2fs_x86\n```\n## Make image\n```\nmake clean -C buildroot\nmake BR2_EXTERNAL=$PWD/my_external_tree -C $PWD/buildroot f2fs_qemu_x86_defconfig\nmake -C buildroot\n```\n## Save non-default buildroot .config\nTo save non-default buildroot's buildroot/.config to $PWD/my_external_tree/configs/f2fs_qemu_x86_defconfig\n```\nmake -C $PWD/buildroot savedefconfig BR2_DEFCONFIG=$PWD/my_external_tree/configs/f2fs_qemu_x86_defconfig\n```\n## Tune and rebuild Kernel\nTune Linux kernel\n```\nmake linux-menuconfig -C buildroot\n```\nRebuild kernel\n```\nmake linux-dirclean -C buildroot \u0026\u0026 make linux-rebuild -C buildroot \u0026\u0026 make -C buildroot\n```\n## Save non-default Linux .config\nIn case of Buildroot to save non-default Linux's .config to my_external_tree/board/my_company/my_board/kernel.config\n```\nmake -C $PWD/buildroot/ linux-update-defconfig BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=$PWD/my_external_tree/board/my_company/my_board/kernel.config\n```\n## Save non-default BusyBox .config\n```\nmake -C $PWD/buildroot/ busybox-update-config BR2_PACKAGE_BUSYBOX_CONFIG=$PWD/my_external_tree/board/my_company/my_board/MyBusyBox.config\n```\n## Start in QEMU\nThis code is based on [emulation script](https://github.com/buildroot/buildroot/tree/master/board/qemu/x86_64), run the emulation with:\n```\nqemu-system-i386 -M pc -kernel buildroot/output/images/bzImage -drive file=buildroot/output/images/rootfs.ext2,if=virtio,format=raw -append \"rootwait root=/dev/vda console=tty1 console=ttyS0\" -serial stdio -net nic,model=virtio -net user\n```\nLogin is `root`. Unfortunatly in my machine there is no blockdev which I can try to mount so mount will fails because can't lookup /dev/sda2. So I am ready for such error, but looks like f2fs code doesn't trig when I try mount... Let's check again using steps from \"Ubuntu's kernel 6.8\":\n```\n# uname -a\nLinux buildroot 6.8.0 #2 SMP PREEMPT_DYNAMIC Fri Nov  8 21:36:02 KST 2024 i686 GNU/Linux\n# modinfo f2fs\nfilename:       /lib/modules/6.8.0/kernel/fs/f2fs/f2fs.ko\nauthor:         Samsung Electronics's Praesto Team\ndescription:    Flash Friendly File System\nlicense:        GPL\nparm:           num_compress_pages:Number of intermediate compress pages to preallocate\nalias:          fs-f2fs\ndepends:        zstd_compress,lz4_compress,lz4hc_compress\nintree:         Y\nvermagic:       6.8.0 SMP preempt modversions 686\n\n# mkdir /mnt/sda2\n# mount -o compress_algorithm=zstd:1,compress_chksum,atgc,gc_merge,lazytime /dev\n/sdc /mnt/sda2/\n[  582.682848] ext3: Unknown parameter 'compress_algorithm'\n[  582.683882] ext2: Unknown parameter 'compress_algorithm'\n[  582.684615] ext4: Unknown parameter 'compress_algorithm'\n[  582.685248] squashfs: Unknown parameter 'compress_algorithm'\n[  582.686661] fuseblk: Unknown parameter 'compress_algorithm'\nmount: mounting /dev/sdc on /mnt/sda2/ failed: Invalid argument\n```\n\n## Steps\nBased on \"boot/grub2/readme.txt\"\n1. Create a disk image\n```\ncd /tmp\ndd if=/dev/zero of=disk.img bs=1M count=128\n```\n2. Partition it with GPT partitions usinig `cgdisk disk.img` or\n```\nparted --script disk.img mklabel gpt mkpart primary 1MiB 127MiB\n```\n3. Setup loop device and loop partitions\n```\nloop_dev=$(sudo losetup -f --show disk.img)\nsudo partx -a \"$loop_dev\"\n```\n5. Prepare the root partition\n```\nsudo mkfs.f2fs -f -l mylable123 -i -O extra_attr,inode_checksum,sb_checksum,compression -e raw -E bin \"$loop_dev\"\n```\nAnother example `sudo mkfs.ext3 -L root \"$loop_dev\"p1`\n6. Cleanup loop device\n```\npartx -d \"$loop_dev\"\nlosetup -d \"$loop_dev\"\n```\n\n## Build mkfs.f2fs from source code\nTo avoid extra dialog from gdb...\n```\ncat \u003c\u003cEOF \u003e ~/.gdbinit\nset debuginfod enabled on\nEOF\n```\nBuild\n```\nsudo apt install git uuid-dev libselinux1-dev libtool dh-autoreconf\ngit clone https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git \u0026\u0026 cd \"f2fs-tools\"\n./autogen.sh\n./configure\nmake -j$(( $(nproc) + 1))\n```\nStart\n```\n\"$HOME/mycode/f2fs-tools/mkfs/mkfs.f2fs\" -V\n```\nStart debug\n```\nlibtool --mode=execute gdb -ex=r --args \"$HOME/mycode/f2fs-tools/mkfs/mkfs.f2fs\" -f -l mylable123 -i -O extra_attr,inode_checksum,sb_checksum,compression -e raw -E bin \"$loop_dev\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreicherniaev%2Fbuildroot_qemu_mount_f2fs_compression_x86","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreicherniaev%2Fbuildroot_qemu_mount_f2fs_compression_x86","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreicherniaev%2Fbuildroot_qemu_mount_f2fs_compression_x86/lists"}