Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Script that creates a FAT32 disk image from directory contents without root privileges

License

NotificationsYou must be signed in to change notification settings

CPL-1/dir2fat32

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Create a FAT32 disk image from the contents of a directory, without mounting orroot privileges, completely automatically.

Prerequisites

dir2fat32 requires the following packages to be installed on the host Linuxsystem:

  • util-linux (fdisk)
  • dosfstoos (mkfs.vfat)
  • mtools (mmd,mcopy)

Quick usage guide

Before running the script, you need to prepare the source directory. Thedirectory should not contain any symlinks or paths with characters that areillegal on FAT32. Note that file and directory permissions do not reallymatter.

Once the directory is prepared, invoke the dir2fat32 script:

$ ./dir2fat32.sh test.img 200 test==============================================Output file:      test.imgPartition size:   200 MiBImage size:       208 MiBSector size:      512 BSource dir:       test=================================================> Creating container image===> Creating FAT32 partition image===> Copying files  Creating hardware  Copying bash_functions.sh  Copying aliases_example.txt  Copying colors.sh  Copying alias_manager.sh  Copying hardware/backlight.sh  Copying README.rst===> Copying partition into container===> Removing partition image file===> DONE

The above example creates an image file calledtest.img that is 208 MiB insize and contains the contents of thetest directory.

The image has a DOS partition table with a single FAT32 partition. You canverify this withfdisk:

$ fdisk -l test.imgDisk test.img: 216 MiB, 226492416 bytes, 442368 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x23410f22Device     Boot Start    End Sectors  Size Id Typetest.img1       16384 425983  409600  200M  b W95 FAT32

The disk image can be mounted for testing purposes using loopback devices.

$ sudo modprobe loop$ losetup /dev/loop0 test.img$ sudo partprobe test.img$ mkdir -p mnt$ sudo mount /dev/loop0p1 mnt$ ls mnt... contents of the test directory ...

The logical sector size can be set using the-S option. The valid valuesare the same as for the-S option formkfs.fat command, and those are:512, 1024, 2048, 4096, 8192, 16384, 32768. For flash-based media such as SDcards and USB sticks, this value should ideally match the page size for optimalperformance.

Note that setting the logical sector size too high willrender a technicallyincorrect partition image which has less clusters than a FAT32 partitionshould. This can lead to mounting issues due to the FAT type being determinedsolely based on the number of clusters. A warning is shown if the number ofclusters is low:

===> Creating FAT32 partition imageWARNING: Not enough clusters for a 32 bit FAT!

Why is my image larger than the specified size?

The size of the generated image is always several MiB larger than the specifiedsize. The specified size is the size of the partition and there is someoverhead as well as 8 MiB offset.

License

This script is released under GNU GPLv3. See theCOPYING file for moredetails or visithttp://www.gnu.org/licenses/.

About

Script that creates a FAT32 disk image from directory contents without root privileges

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell100.0%

[8]ページ先頭

©2009-2025 Movatter.jp