shrinkwrap icon indicating copy to clipboard operation
shrinkwrap copied to clipboard

truncate: Invalid number:

Open darkphox opened this issue 5 years ago • 4 comments

Hi there, this is my first time submitting an issue so please let me know if I can provide more information.

I used shrinkwrap on my Rpi4b to shrink a backup image file on an attached USB drive. I created the image with win32diskimager.

There's an error that re-reading the partition table failed, but also a note to "ignore that error and everything seems fine until nearly the end. At the point where the script attempts to truncate the img file, I get the error "truncate: Invalid number: ‘8.51628e+09’" and the source file remains at a full un-shrunken size. Full log is attached and pasted below:

shrinkwrap log.txt

pi@nasberry:~/shrinkwrap $ sudo ./shrinkwrap.sh /home/pi/Desktop/NASBerry/12-Backups/00_NASBerry/20191126_NASBerry_Backup.img Disk /home/pi/Desktop/NASBerry/12-Backups/00_NASBerry/20191126_NASBerry_Backup.img: 119.3 GiB, 128043712512 bytes, 250085376 sectors 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: 0x5e3da3da

Device Boot Start End Sectors Size Id Type /home/pi/Desktop/NASBerry/12-Backups/00_NASBerry/20191126_NASBerry_Backup.img1 8192 532479 524288 256M c W95 /home/pi/Desktop/NASBerry/12-Backups/00_NASBerry/20191126_NASBerry_Backup.img2 532480 250085375 249552896 119G 83 Linu START of partition: 532480 losetup: /dev/loop0: detach failed: No such device or address Good - no /dev/loop0 is already free NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT loop0 7:0 0 119.3G 0 loop ├─loop0p1 259:0 0 256M 0 part └─loop0p2 259:1 0 119G 0 part e2fsck 1.44.5 (15-Dec-2018) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information rootfs: 197549/7768320 files (0.5% non-contiguous), 2186120/31194112 blocks resize2fs 1.44.5 (15-Dec-2018) Resizing the filesystem on /dev/loop0p2 to 2012607 (4k) blocks. Begin pass 2 (max = 250881) Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 3 (max = 952) Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 4 (max = 19052) Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX The filesystem on /dev/loop0p2 is now 2012607 (4k) blocks long.

dumpe2fs 1.44.5 (15-Dec-2018) Filesystem volume name: rootfs Last mounted on: / Filesystem UUID: efc2ea8b-042f-47f5-953e-577d8860de55 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file dir_nlink extra_isize Filesystem flags: unsigned_directory_hash Default mount options: user_xattr acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 505920 Block count: 2012607 Reserved block count: 81508 Free blocks: 284329 Free inodes: 308371 First block: 0 Block size: 4096 Fragment size: 4096 Reserved GDT blocks: 389 Blocks per group: 32768 Fragments per group: 32768 Inodes per group: 8160 Inode blocks per group: 510 Flex block group size: 16 Filesystem created: Wed Sep 25 19:44:35 2019 Last mount time: Sun Nov 24 21:49:52 2019 Last write time: Wed Nov 27 09:28:57 2019 Mount count: 0 Maximum mount count: -1 Last checked: Wed Nov 27 09:19:04 2019 Check interval: 0 () Lifetime writes: 42 GB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 32 Desired extra isize: 32 Journal inode: 8 Default directory hash: half_md4 Directory Hash Seed: 2a510282-7c57-4970-8f9a-1514cd4b5a23 Journal backup: inode blocks Journal features: journal_incompat_revoke Journal size: 64M Journal length: 16384 Journal sequence: 0x000275a4 Journal start: 0

NEW SIZE of partition: 16100872 512-blocks

Welcome to fdisk (util-linux 2.33.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.

Command (m for help): Disk /dev/loop0: 119.3 GiB, 128043712512 bytes, 250085376 sectors 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: 0x5e3da3da

Device Boot Start End Sectors Size Id Type /dev/loop0p1 8192 532479 524288 256M c W95 FAT32 (LBA) /dev/loop0p2 532480 250085375 249552896 119G 83 Linux

Command (m for help): Partition number (1,2, default 2): Partition 2 has been deleted.

Command (m for help): Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): Partition number (2-4, default 2): First sector (2048-250085375, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (532480-250085375, default 250085375): Created a new partition 2 of type 'Linux' and of size 7.7 GiB. Partition #2 contains a ext4 signature.

Command (m for help):

Command (m for help): Disk /dev/loop0: 119.3 GiB, 128043712512 bytes, 250085376 sectors 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: 0x5e3da3da

Device Boot Start End Sectors Size Id Type /dev/loop0p1 8192 532479 524288 256M c W95 FAT32 (LBA) /dev/loop0p2 532480 16633352 16100873 7.7G 83 Linux

Command (m for help): The partition table has been altered. Calling ioctl() to re-read partition table. Re-reading the partition table failed.: Invalid argument

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

Ignore that error. Disk /home/pi/Desktop/NASBerry/12-Backups/00_NASBerry/20191126_NASBerry_Backup.img: 119.3 GiB, 128043712512 bytes, 250085376 sectors 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: 0x5e3da3da

Device Boot Start End Sectors Size Id Type /home/pi/Desktop/NASBerry/12-Backups/00_NASBerry/20191126_NASBerry_Backup.img1 8192 532479 524288 256M c W95 /home/pi/Desktop/NASBerry/12-Backups/00_NASBerry/20191126_NASBerry_Backup.img2 532480 16633352 16100873 7.7G 83 Linu TRUNCATE AT: 8.51628e+09 bytes truncate: Invalid number: ‘8.51628e+09’ `

darkphox avatar Nov 27 '19 16:11 darkphox

I have the same issue running in my Raspberry Pi 4 with 32bit or 64bit raspbian OS, the partition has been resized, but the file size is not changed.

Thanks mtyka for sharing the tools to shrinkwrap the image file, it can easily backup and restore the SD card even to other SD card with slightly difference in size, which can solve the issue of block size difference among brands. It'd be better if the file size can be reduced while the partition is resized.

Super169 avatar Aug 17 '20 01:08 Super169

same thing:

sudo ./shrinkwrap/shrinkwrap.sh ./rPi_clean_backup_shrinked.img
Disk ./rPi_clean_backup_shrinked.img: 29.8 GiB, 32010928128 bytes, 62521344 sectors
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: 0x2e343b40

Device                           Boot  Start      End  Sectors  Size Id Type
./rPi_clean_backup_shrinked.img1        8192   532479   524288  256M  c W95 FAT32 (LBA)
./rPi_clean_backup_shrinked.img2      532480 62521343 61988864 29.6G 83 Linux
START of partition: 532480
NAME      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0       7:0    0 29.8G  0 loop
├─loop0p1 259:0    0  256M  0 part
└─loop0p2 259:1    0 29.6G  0 part
e2fsck 1.44.5 (15-Dec-2018)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
rootfs: 230623/1937712 files (0.1% non-contiguous), 2029045/7748608 blocks
resize2fs 1.44.5 (15-Dec-2018)
Resizing the filesystem on /dev/loop0p2 to 2046430 (4k) blocks.
Begin pass 2 (max = 920219)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 237)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 26014)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/loop0p2 is now 2046430 (4k) blocks long.

dumpe2fs 1.44.5 (15-Dec-2018)
Filesystem volume name:   rootfs
Last mounted on:          /tmp/tmp.irUfXwyZ9S
Filesystem UUID:          05c2c54d-f13e-4442-bf69-70e99c3d748d
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         unsigned_directory_hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              515088
Block count:              2046430
Reserved block count:     102321
Free blocks:              108720
Free inodes:              284465
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      1024
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8176
Inode blocks per group:   511
Flex block group size:    16
Filesystem created:       Thu Aug 27 19:29:10 2020
Last mount time:          Sat Aug 29 12:31:33 2020
Last write time:          Sat Aug 29 18:16:14 2020
Mount count:              0
Maximum mount count:      -1
Last checked:             Sat Aug 29 18:13:15 2020
Check interval:           0 (<none>)
Lifetime writes:          12 GB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      310f2866-8a93-434c-a35b-403619b3c1af
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x98a0f5fe
Journal features:         journal_64bit journal_checksum_v3
Journal size:             128M
Journal length:           32768
Journal sequence:         0x00000192
Journal start:            0
Journal checksum type:    crc32c
Journal checksum:         0x1f3ea62a

NEW SIZE of partition: 16371456  512-blocks

Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): Disk /dev/loop0: 29.8 GiB, 32010928128 bytes, 62521344 sectors
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: 0x2e343b40

Device       Boot  Start      End  Sectors  Size Id Type
/dev/loop0p1        8192   532479   524288  256M  c W95 FAT32 (LBA)
/dev/loop0p2      532480 62521343 61988864 29.6G 83 Linux

Command (m for help): Partition number (1,2, default 2):
Partition 2 has been deleted.

Command (m for help): Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): Partition number (2-4, default 2): First sector (2048-62521343, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (532480-62521343, default 62521343):
Created a new partition 2 of type 'Linux' and of size 7.8 GiB.
Partition #2 contains a ext4 signature.

Command (m for help):

Command (m for help):
Disk /dev/loop0: 29.8 GiB, 32010928128 bytes, 62521344 sectors
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: 0x2e343b40

Device       Boot  Start      End  Sectors  Size Id Type
/dev/loop0p1        8192   532479   524288  256M  c W95 FAT32 (LBA)
/dev/loop0p2      532480 16903936 16371457  7.8G 83 Linux

Command (m for help): The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Invalid argument

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

Ignore that error.
Disk ./rPi_clean_backup_shrinked.img: 29.8 GiB, 32010928128 bytes, 62521344 sectors
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: 0x2e343b40

Device                           Boot  Start      End  Sectors  Size Id Type
./rPi_clean_backup_shrinked.img1        8192   532479   524288  256M  c W95 FAT32 (LBA)
./rPi_clean_backup_shrinked.img2      532480 16903936 16371457  7.8G 83 Linux
TRUNCATE AT: 8.65482e+09 bytes
truncate: Invalid number: ‘8.65482e+09’

Looks like problem in the disk ( I do this in HDD attached disk, prbably it's partition scheme different)

skywinder avatar Aug 29 '20 17:08 skywinder

The problem is that the print statement that passes the new file size in bytes for truncate to operate on converts to scientific notation once you get past a certain size. Change line 50:

FINALEND_BYTES=$(cat /tmp/fdisk_new.log | grep "83 Linux" | awk '{print ($3+1)*512}')

to use printf instead:

FINALEND_BYTES=$(cat /tmp/fdisk_new.log | grep "83 Linux" | awk '{printf "%.0f", ($3+1)*512}')

Now instead of an output like "TRUNCATE AT: 8.65482e+09 bytes", you'll get "TRUNCATE AT: 865482836542769 bytes" and the truncate should work.

chantling avatar Sep 07 '20 23:09 chantling

Hi. We've just bumped into this issue. We can open a pull request with the fix. Does that sound good?

Jorl17 avatar Feb 15 '21 12:02 Jorl17