- Notifications
You must be signed in to change notification settings - Fork0
Script that creates a FAT32 disk image from directory contents without root privileges
License
CPL-1/dir2fat32
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Create a FAT32 disk image from the contents of a directory, without mounting orroot privileges, completely automatically.
dir2fat32 requires the following packages to be installed on the host Linuxsystem:
- util-linux (
fdisk
) - dosfstoos (
mkfs.vfat
) - mtools (
mmd
,mcopy
)
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!
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.
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
Packages0
Languages
- Shell100.0%