You are not logged in.

#1 2019-11-08 02:23:06

atomikegg
Member
Registered: 2019-08-14
Posts: 55

[Solved] How to Align Shrunk Partition to OS?

Pure arch. Apologies for my ignorance.
i successfully installed arch to a 6G VirtualBox partition.

I shrunk the partition, and now i can't mount it from the live installation iso media. I think there's a mismatch between physical blocks and file-system blocks.

# e2fsck -p -f /dev/sda1
/dev/sda1: The filesystem size (according to the superblock) is 1572603 blocks
The physical size of the device is 1572480 blocks
Either the superblock or the partition table is likely to be corrupt!

How to restore the partition to it's original size, so it can be mounted?

i noticed that using cfdisk to resize the partition to it's original 6G fixed this problem-- i was able to mount the partition. So, fixing by resizing seems to work.

Then, i did the process again-- shrunk the partition, then resized to it's original 6G. But second time, resizing with cfdisk didn't fix this problem-- i can't mount the partition. It seems cfdisk didn't resize exactly to the same size, even tho' i entered 6G both times.

So, i think i need to enter a more precise size, not just "6G". I'm still fuzzy on disk math. What size should i use, and which is best tool to use? Here are some stats. Hope this helps:

# mount /dev/sda1 /mnt
mount: /mnt: wrong fs type, bad option, bad superblock on /dev/sda1, missing codepage or helper program, or other error.

# fdisk -l
Disk /dev/sda: 6 GiB, 6442450944 bytes, 12582912 sectors
Disk model: VBOX HARDDISK   
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: gpt
Disk identifier: D69BDA20-F725-4C39-9B0B-A8D8E14FA398

Device     Start      End  Sectors Size Type
/dev/sda1   2048 12581887 12579840   6G Linux filesystem

Disk /dev/loop0: 520.88 MiB, 546164736 bytes, 1066728 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

# file -s /dev/sda1
/dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=dd91e9b9-9d4f-47b7-b579-c931aad986c9 (extents) (64bit) (large files) (huge files)

# lsblk -b
NAME   MAJ:MIN RM       SIZE RO TYPE MOUNTPOINT
loop0    7:0    0  546164736  1 loop /run/archiso/sfs/airootfs
sda      8:0    0 6442450944  0 disk 
+-sda1   8:1    0 6440878080  0 part 
sr0     11:0    1  665845760  0 rom  /run/archiso/bootmnt

# parted -l
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 6442MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  6442MB  6441MB  ext4

Model: VBOX CD-ROM (scsi)
Disk /dev/sr0: 666MB
Sector size (logical/physical): 2048B/2048B
Partition Table: msdos
Disk Flags: 

Number  Start  End    Size   Type     File system  Flags
 2      336kB  269MB  268MB  primary               esp

# blkid
/dev/sda1: UUID="dd91e9b9-9d4f-47b7-b579-c931aad986c9" TYPE="ext4" PARTUUID="f46d8306-6648-e546-a0ec-84f8b4ccefa1"
/dev/sr0: UUID="2019-11-01-16-33-14-00" LABEL="ARCH_201911" TYPE="iso9660" PTUUID="65cc13ea" PTTYPE="dos"
/dev/loop0: TYPE="squashfs"

Last edited by atomikegg (2019-11-09 00:21:17)

Offline

#2 2019-11-08 10:06:42

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 7,798

Re: [Solved] How to Align Shrunk Partition to OS?

You need to resize the filesystem, best before shrinking the partition: https://wiki.archlinux.org/index.php/Pa … partitions (this just happens to be on the parted article, it doesn't matter and should hold true for any other partitioning tools as well.)

Offline

#3 2019-11-08 10:16:45

sabroad
Member
Registered: 2015-05-24
Posts: 57

Re: [Solved] How to Align Shrunk Partition to OS?

atomikegg wrote:

I shrunk the partition, and now i can't mount it. I think there's a mismatch between physical blocks and file-system blocks.

# e2fsck -p -f /dev/sda1
/dev/sda1: The filesystem size (according to the superblock) is 1572603 blocks
The physical size of the device is 1572480 blocks
Either the superblock or the partition table is likely to be corrupt!

How to restore the partition to it's original size, so it can be mounted?

[...] i need to enter a more precise size, not just "6G". I'm still fuzzy on disk math. What size should i use [...]

# fdisk -l
Disk /dev/sda: 6 GiB, 6442450944 bytes, 12582912 sectors
Disk model: VBOX HARDDISK   
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: gpt
Disk identifier: D69BDA20-F725-4C39-9B0B-A8D8E14FA398

Device     Start      End  Sectors Size Type
/dev/sda1   2048 12581887 12579840   6G Linux filesystem

To fix your partitions, you'll need to expand it  to match filesystem size.

To calculate the exact partition size from filesystem size, you'll need the following formula:

BLOCKS * BLOCK_SIZE = SECTORS * SECTOR_SIZE
or
SECTORS = BLOCKS * BLOCK_SIZE / SECTOR_SIZE

To determine the filesystem block size:

$ sudo dumpe2fs /dev/sda1 | fgrep "Block size"
dumpe2fs 1.44.6 (5-Mar-2019)
Block size:               4096

edit: answers on a postcard

SECTORS = BLOCKS * BLOCK_SIZE / SECTOR_SIZE
12580824 = 1572603 * 4096 / 512

Last edited by sabroad (2019-11-08 10:18:16)


--
saint_abroad

Offline

#4 2019-11-08 19:36:06

atomikegg
Member
Registered: 2019-08-14
Posts: 55

Re: [Solved] How to Align Shrunk Partition to OS?

thx for the helpful replies. i used a fix from @V1del's parted article, not based on calculating size: resize2fs

First some comments about sizes:

`dumpe2fs /dev/sda1 | fgrep "Block size"` gave a block size of 4096.

@sabroad:

SECTORS = BLOCKS * BLOCK_SIZE / SECTOR_SIZE

I'm unclear what to do with that info. Don't i need to determine total size in bytes?

What do we do with total sectors? Is total size = total blocks * block_size? That would be:
    1572603 * 4096 = 6,441,381,888

i tried to resize to 6,441,381,888 using cfdisk, and got a "too big" error.

cfdisk reported max allowed size (which was less than this number), so i used that size. cfdisk accepted that size.

But still not able to mount.

then i did:

# resize2fs /dev/sda1
Run e2fsck -f /dev/sda1 first. 

# e2fsck -f /dev/sda1 
corrupt! abort?
no

# resize2fs /dev/sda1

# mount /dev/sda1 /mnt

mounted without error.

Last edited by atomikegg (2019-11-08 19:37:58)

Offline

Board footer

Powered by FluxBB