mtyka / shrinkwrap Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
The comments imply that you're adding 16 blocks to the new size but I don't think that is what happens?
Blocks and sectors confuse me so I might just not understand.
# Calculate the size of the resized filesystem in 512 blocks which we'll need
# later for fdisk to also resize the partition add 16 blocks just to be safe
NEWSIZE=$(cat /tmp/dumpe2fs |& awk -F: '/Block count/{count=$2} /Block size/{size=$2} END{print count*size/512 + 16}')
echo "NEW SIZE of partition: $NEWSIZE 512-blocks"
should count*size/512+16
not be (count+16)*size/512
?
Hello,
i got error message with this print statement.
I got it running using printf
awk '{printf "%.0f",($3+1)*512}
Line 50 in e6ad9a6
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:
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’
`
Linux:/RasPi Images/Backups$ ./shrinkwrap/shrinkwrap.sh RasPi.img
Disk RasPi.img: 14.94 GiB, 16021192704 bytes, 31291392 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: 0x00000000
Device Boot Start End Sectors Size Id Type
RasPi.img1 8192 31291391 31283200 14.9G c W95 FAT32 (LBA)
START of partition:
losetup: RasPi.img: failed to set up loop device: Device or resource busy
When I run your script, I get an error that the device is busy. I checked lsof grepped for my file but nothing comes up.
I'd like for this to work, and I'm willing to help but I'm not a coder. If there's anything that you would like for me to check on while I have it in this state, let me know. Otherwise I can think a few things to try like, reboot.
Hi, i'm on debian, i'm trying to shrink a raspbian image but i get this output: (Screenshot)
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.