Hello, On Mon, Jan 31, 2022 at 08:40:49AM -0600, Martin McCormick wrote: > #I should be telling resize2fs to squeeze everything in to a 7GB > #partition. > sudo resize2fs /dev/loop0p2 +7G
[…] > fdisk prompts for the first sector with a default of 2048 but I > type in 137215. The last sector is in the 62-million range and I > want only 7 GB as the size so I type +7G and it takes that. > > I then type w to save the changes and there is no > complaint. > > The first hint of trouble is when you do fdisk -l > /dev/loop0. The size count is still almost 30 GB but then a ray > of Sun in that P2 has a size of around 7 GB. What you have at this point is an image file that's 30 or so GB in size with a partition table, small first partition, ~7GB second partition and then nothing out to the end. 23GB or so of nothing. You've resized your last partition but you haven't resized your disk. If this were an LVM LV containing a disk image, at this point I'd be shrinking the LV itself. So, the analogous action for you is to shrink your image file. You need to work out the last sector of your second partition from your "fdisk -u -l" output, and use something like "truncate -s <size-in-bytes> /path/to/your.img" to truncate it down to the desired total size. Play around a bit. Leaving a few KiB of empty space at the end isn't going to hurt. > I am not sure what I missed but the manual page for > resize2fs warns you to use something like fdisk to trim off the > excess empty space which is what I thought I did. I would also > have thought that the disk image file should have deflated like a > punctured air mattress but it didn't. fdisk doesn't know what sort of device the disk is; its concern is just things inside the disk like partition tables. So while fdisk or parted can create and manipulate partitions, you need device-specific tools to resize what might be an LVM, LUKS, a floppy disk, etc etc - a lot of the time it not even being possible. Think about shrinking the last partition on a HDD. fdisk can't alter the physical construction of your HDD to have less capacity. But for virtual abstractions like loop devices and LVL logical volumes, there are tools to just shrink them. In the case of loop file, just truncate the backing file. You might have to deregister the loop device first; not sure. Cheers, Andy -- https://bitfolk.com/ -- No-nonsense VPS hosting