ya-mouse / fatresize Goto Github PK
View Code? Open in Web Editor NEWResize FAT partitions using libparted
License: GNU General Public License v3.0
Resize FAT partitions using libparted
License: GNU General Public License v3.0
It would be great, if fatresize had a special option for working with fat32 partitions less than 512 MiB.
Mostly many EFI partitions has size less than 512 MiB and fatresize can't work properly with them.
The most incomprehensible thing is why "fatresize -i" show "Min size" also limited to 512 MiB.
Attempted on an external WD:
~ $ sudo fatresize -p -v -s 1800G /dev/sdb2
fatresize 1.0.2 (06/16/18)
.Resizing file system.
Killed
It looks like the changelog in the repo is out of date, as of 321973b (see here) – should this be altered to favor GitHub's releases system, maybe, or else updated with the recent information? (1.0.3 and 1.0.4 have been released, it seems, whereas the file has the most recent entry at "planned 1.0.3".)
In version 0.1 it was possible to resize the FAT partition to a maximum size e.g. by:
fatresize /dev/sdb1
Version 1.0.3 always requires a size to be set and complains if it is outside of the device.
fatresize -i /dev/sdb1
already knows the maximum size.
Would be nice to have the following:
fatresize -s max /dev/sdb1
After letting it seemingly successfully shrink a FAT32 partition on an microSD card,
Hi,
I'm the current SUSE parted maintainer and it has been reported to me that calling fatresize
with /dev/mmcblk0p1
fails (openSUSE bug: https://bugzilla.suse.com/show_bug.cgi?id=959181).
I can reproduce this with latest master commit 46cf019.
# ./fatresize -s 5G /dev/mmcblk0p1
fatresize 1.0.3 ()
Error: Could not stat device /dev/mmcblk0p - No such file or directory.
Parted supports those devices properly. Can you please develop a fix? TIA
kodi@arch-msi ~/Documents » sudo fatresize -i ./blue3ds.img
fatresize 1.1.0 (20200405)
part(start=0, end=124702719, length=124702720)
FAT: fat32
Cur size: 63847792640
Min size: 43381676032
Max size: 63847792640
kodi@arch-msi ~/Documents » sudo fatresize --size 45381676032 ./blue3ds.img
fatresize 1.1.0 (20200405)
part(start=0, end=124702719, length=124702720)
zsh: segmentation fault sudo fatresize --size 45381676032 ./blue3ds.img
Hello,
this is my first bug report so please correct me if I am doing something wrong. I am using Arch Linux with fatresize 1.1.0 (20200405) and tried to maximize a FAT filesystem inside a 4GiB partition on a 8GiB virtual disk created with qemu-nbd. I've used the following command:
sudo fatresize -ps max /dev/nbd0p1
However this fails with the following error:
fatresize 1.1.0 (20200405)
.part(start=2048, end=8390655, length=8388608)
Error: The location 8591MB is outside of the device /dev/nbd0.
I really can't explain why this happens, because it event prints out the correct start and end of the partition, but then seems like it is somehow trying to resize the partition to 8591MB.
Please would you have a look at this :)
I have cloned the 1.1.0 but the binary shows 1.0.3 with the date of compilation
roberto@vm-ubuntu18:~/tinycore-editor$ sudo fatresize -i /dev/loop0p1
fatresize 1.0.3 (20210815)
part(start=2048, end=266239, length=264192)
FAT: fat16
Cur size: 67108864
Min size: 33728000
Max size: 136314880
roberto@vm-ubuntu18:~/tinycore-editor$ sudo fatresize -s 136314880 /dev/loop0p1
fatresize 1.0.3 (20210815)
part(start=2048, end=266239, length=264192)
Error: The location 137MB is outside of the device /dev/loop0.
roberto@vm-ubuntu18:~/tinycore-editor$ sudo fatresize -s 129M /dev/loop0p1
fatresize 1.0.3 (20210815)
part(start=2048, end=266239, length=264192)
No Implementation: GNU Parted cannot resize this partition to this size. We're working on it!
My EFI System Partition is too small (100m; Microsoft's fault). So I'm trying to grow it, with mixed results.
$ sudo fatresize -i /dev/sda2
fails with the message: Error: /dev/sda2 is ntfs, not a valid FAT16/FAT32 partition.
(The wording has changed due to a commit (I just issued a pull request for it.))
So: fatresize thinks that the FS (or, perhaps, the partition type) is ntfs. Why?
parted does not think that this is an NTFS. It says:
Number Start End Size File system Name Flags
2 524MB 733MB 209MB fat32 EFI System Partition boot, esp
Why does fatresize thinks that this partition is ntfs?
Any recommendations on how to proceed?
(I don't know if there are fancy things about an ESP that I should beware of.)
Got this 'bug' (according to the program itself) while trying to shrink a DD image of a Raspberry Pi boot partition.
/usr/sbin/fatresize -v -s 200M -p boot_partition.fs
fatresize 1.1.0 (20201114)
.part(start=0, end=524287, length=524288)
Backtrace has 5 calls on stack:
5: /lib/aarch64-linux-gnu/libparted.so.2(ped_assert+0x54) [0xffffb7156b34]
4: /lib/aarch64-linux-gnu/libparted.so.2(ped_disk_max_partition_length+0) [0xffffb715b870]
3: /usr/sbin/fatresize(+0x2494) [0xaaaadff02494]
2: /lib/aarch64-linux-gnu/libc.so.6(__libc_start_main+0xe8) [0xffffb6ff3e18]
1: /usr/sbin/fatresize(+0x2908) [0xaaaadff02908]
Bug: Assertion (disk != NULL) at ../../libparted/disk.c:1620 in function ped_disk_get_partition_by_sector() failed.
Aborted
It is able to read the file:
parallels@debian-gnu-linux-11:~/fatresize$ /usr/sbin/fatresize -i boot_partition.fs
fatresize 1.1.0 (20201114)
part(start=0, end=524287, length=524288)
FAT: fat32
Cur size: 268435456
Min size: 44493312
Max size: 268435456
I'm trying to shrink my EFI FAT16 partition by 1 MB to make some space for the bcache superblock.
$ sudo parted /dev/vda
GNU Parted 3.1
Using /dev/vda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit s
(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 52428800s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
128 2048s 22527s 20480s fat16 EFI System Partition boot
1 22528s 52428766s 52406239s xfs Linux
But fatresize fails to detect the correct boundaries and size of the partition
$ sudo ./fatresize /dev/vda -n 128 -i
fatresize 1.0.3 (20230501)
part(start=2048, end=22527, length=20480)
FAT: fat16
Cur size: 10485760
Min size: 10518528
Max size: 26843545600
And the resize fails:
$ sudo ./fatresize /dev/vda -n 128 -s 9Mi
fatresize 1.0.3 (20230501)
part(start=2048, end=22527, length=20480)
Error: Unable to satisfy all constraints on the partition.
I'm running the latest version of fatresize from this repo, compiled from source code. The OS is Amazon Linux 2 aarch64, running locally in a KVM VM.
$ ./fatresize --version
./fatresize: unrecognized option '--version'
fatresize 1.0.3 (20230501)
Usage: fatresize [options] device (e.g. /dev/hda1, /dev/sda2)
Resize an FAT16/FAT32 volume non-destructively:
-s, --size SIZE Resize volume to SIZE[k|M|G|ki|Mi|Gi] bytes or "max"
-i, --info Show volume information
-f, --force-yes Do not ask questions
-n, --partition NUM Specify partition number
-p, --progress Show progress
-q, --quiet Be quiet
-v, --verbose Verbose
-h, --help Display this help
Please report bugs to [email protected]
When trying to shrink a fat16 partition, fatresize just spits out its version and does nothing.
[james@voidD620 ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 1.8T 0 disk
└─sda1 8:1 0 1.8T 0 part
└─voidD620 254:0 0 1.8T 0 crypt
└─voidD620-root 254:1 0 1.8T 0 lvm /
sdb 8:16 1 59.1G 0 disk
├─sdb1 8:17 1 59G 0 part
└─sdb2 8:18 1 32M 0 part
sr0 11:0 1 1024M 0 rom
[james@voidD620 ~]$ sudo fatresize -s 28M /dev/sdb2
Password:
fatresize 1.0.3 (20200810)
[james@voidD620 ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 1.8T 0 disk
└─sda1 8:1 0 1.8T 0 part
└─voidD620 254:0 0 1.8T 0 crypt
└─voidD620-root 254:1 0 1.8T 0 lvm /
sdb 8:16 1 59.1G 0 disk
├─sdb1 8:17 1 59G 0 part
└─sdb2 8:18 1 32M 0 part
sr0 11:0 1 1024M 0 rom
[james@voidD620 ~]$
Disk /dev/sdb: 59.06 GiB, 63417876480 bytes, 123863040 sectors
Disk model: USB 3.0 FD
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1c9d51dc
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 123797503 123795456 59G 7 HPFS/NTFS/exFAT
/dev/sdb2 123797504 123863039 65536 32M ef EFI (FAT-12/16/32)
The -n
option is required now, because not using it means that the program will crash (it expects getting a disk image, not a partition). This makes all examples broken, because they don't use -n
. The man page is also outdated.
I "fixed" a bit of it enough to work, but it's not a proper solution: rhn@86f3ac1
When executing fatresize as a user that lacks permissions to the specified device, it fails with the following message:
You must specify exactly one existing device.
Since the user specified a device, this message is misleading. I ran into this issue and I suspect the two users participating in this reddit thread did as well.
The root cause seems to be the ped_device_get
call in the probe_device
function which errors out due to lack of permissions, but the error message is swallowed instead of reported back to the user.
I'll create a PR shortly that doesn't address the root cause, but at least provides an error message that hints to the user that their lack of permissions may be the problem.
In the following case I wished to resize a 512MiB FAT16 filesystem to a 4GiB one but forgot about the 2GiB limit. This is a log:
# fatresize -s 3700Mi -i /dev/sda1
fatresize 1.0.2 (06/16/18)
FAT: fat16
Size: 512451072
Min size: 489846784
Max size: 4000317440
# fatresize -s 3700Mi /dev/sda1
fatresize 1.0.2 (06/16/18)
Warning: The file system can only be resized to this size by converting to FAT32.
If you convert to FAT32, and MS Windows is installed on this partition, then you
must re-install the MS Windows boot loader. If you want to do this, you should
consult the Parted manual (or your distribution's manual). Also, converting to
FAT32 will make the file system unreadable by MS DOS, MS Windows 95a, and
MS Windows NT.
# fatresize -i /dev/sda1
fatresize 1.0.2 (06/16/18)
FAT: fat32
Size: 3879977472
Min size: 536870912
Max size: 4000317440
fatresize provided a warning but did not ask me to confirm that I wanted to proceed before converting the filesystem to FAT32, which (1) is surprising behavior, (2) is not something I asked the tool to do, (3) left the filesystem in a useless state since this was being used for a DOS machine.
My suggestion is to implement one of the following:
--allow-filesystem-conversion
".Probably something to do with docbook-to-man
As I don't have a physical device for my floppy image (see #14), I've created a /dev/loop0 device with a command
sudo losetup /dev/loop1 ./floppy.img
However, when I try to use a command like
sudo fatresize -s 2880k /dev/loop1
I get this output:
fatresize 1.0.3 (03/05/20)
You must specify exactly one existing device.
Perhaps this has to do with /dev/loop1 device having one more letter than i.e. /dev/sdd1
Temporary solution is to insert a return 0;
to line 4795 to skip this check.
If I get the maximum size from fatresize -i
and want to set it, then fatresize segfaults in try_snap(&end, end_range,
.
# fatresize -i /dev/sdb1
FAT: fat32
Size: 31103909888
Min size: 536870912
Max size: 31104958464
# fatresize -s 31104958464 /dev/sdb1
fatresize 1.0.3 ()
Segmentation fault
dmesg
+ objdump -S /usr/sbin/fatresize | less
points to try_snap(&end, end_range,
.
I'm an ArchLinux user, when I try to compile version 1.0.4 the compilation process is interrupted with the following error:
make[1]: Entering directory '/tmp/makepkg/fatresize/src/fatresize-1.0.4'
gcc -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -D_FILE_OFFSET_BITS=no -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o fatresize fatresize.o -lparted-fs-resize -lparted -ldl
fatresize.o: In function `try_snap':
fatresize.c:(.text.unlikely+0xad): undefined reference to `ped_assert'
fatresize.o: In function `main':
fatresize.c:(.text.startup+0xc83): undefined reference to `ped_assert'
fatresize.c:(.text.startup+0xd42): undefined reference to `ped_assert'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:416: fatresize] Error 1
make[1]: Leaving directory '/tmp/makepkg/fatresize/src/fatresize-1.0.4'
make: *** [Makefile:319: all] Error 2
==> ERROR: There was an error to build ().
Canceling ...
Any idea or suggestion?
Thanks
When trying to resize a partition other than 1 on a real disk the first partition is selected instead
# fatresize /dev/mmcblk0p2 -vvv -s 800M
fatresize 1.1.0 (20201114)
ped_device_get(/dev/mmcblk0)
ped_device_open()
ped_disk_new()
ped_disk_get_partition(1)
Error: Partition /dev/mmcblk0p1 is being used. You must unmount it before you modify it with Parted.
Workaround is to specify -n 2
in this case.
Found this as a regression to 1.0.2-11
when updating from an older yocto project.
I think this relates to #24
I have an ebook reader unbricking image which I transfer to a microSD card.
Using GPARTED I can grow the DOS FAT32 partition to take up all the free space.
Once grown I'm not able to read the partition's information
paag@840g5 ~/tmp/kobo sudo fdisk -l /dev/sda
Disk /dev/sda: 7,4 GiB, 7948206080 bytes, 15523840 sectors
Disk model: SD/MMC
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x66e8b073
Device Boot Start End Sectors Size Id Type
/dev/sda1 19456 543744 524289 256M 83 Linux
/dev/sda2 543745 1068033 524289 256M 83 Linux
/dev/sda3 1068034 15523839 14455806 6,9G b W95 FAT32
paag@840g5 ~/tmp/kobo sudo fatresize -i /dev/sda3
fatresize 1.1.0 (20201114)
.Error: /dev/sda3 is not valid FAT16/FAT32 partition.
sudo fsck.vfat /dev/sda3
fsck.fat 4.2 (2021-01-31)
There are differences between boot sector and its backup.
This is mostly harmless. Differences: (offset:original/backup)
65:00/01
1) Copy original to backup
2) Copy backup to original
3) No action
[123?q]? 1
*** Filesystem was changed ***
The changes have not yet been written, you can still choose to leave the
filesystem unmodified:
1) Write changes
2) Leave filesystem unchanged
[12?q]? 1
/dev/sda3: 84 files, 1444/1803444 clusters
Probably happen because of incompatibility with a modern libparted.
fatresize.c: In function ‘snap’:
fatresize.c:268:74: error: macro "PED_ASSERT" passed 2 arguments, but takes just 1
FAT_ASSERT(ped_geometry_test_sector_inside (range, *sector), return 0);
^
fatresize.c:51:34: error: ‘PED_ASSERT’ undeclared (first use in this function)
#define FAT_ASSERT(cond, action) PED_ASSERT(cond, action)
^
fatresize.c:268:5: note: in expansion of macro ‘FAT_ASSERT’
FAT_ASSERT(ped_geometry_test_sector_inside (range, *sector), return 0);
^~~~~~~~~~
fatresize.c:51:34: note: each undeclared identifier is reported only once for each function it appears in
#define FAT_ASSERT(cond, action) PED_ASSERT(cond, action)
^
fatresize.c:268:5: note: in expansion of macro ‘FAT_ASSERT’
FAT_ASSERT(ped_geometry_test_sector_inside (range, *sector), return 0);
^~~~~~~~~~
fatresize.c: In function ‘snap_to_boundaries’:
fatresize.c:317:32: error: macro "PED_ASSERT" passed 2 arguments, but takes just 1
FAT_ASSERT (start_part, return);
^
fatresize.c:51:34: error: ‘PED_ASSERT’ undeclared (first use in this function)
#define FAT_ASSERT(cond, action) PED_ASSERT(cond, action)
^
fatresize.c:317:2: note: in expansion of macro ‘FAT_ASSERT’
FAT_ASSERT (start_part, return);
^~~~~~~~~~
fatresize.c:337:34: error: macro "PED_ASSERT" passed 2 arguments, but takes just 1
FAT_ASSERT (start <= end, return);
I need to resize a floppy image from 1440KB (1474560 bytes) "High Density" aka standard floppy to 2880KB (2949120 bytes) "Extended Density" floppy, and sadly discovered there are no opensource Linux tools for that! Manual hexedit of 0x13/0x14 bytes from 0x0B40 to 0x1680 and 0x18 byte from 0x12 to 0x24 - also didn't work for me (but I just learned about FAT structure and may be missing something). + #15
Please add FAT12 resizing support - it may be really important in some situations.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.