All of lore.kernel.org
 help / color / mirror / Atom feed
* Determining if an ext4 fs uses the whole partition
@ 2012-04-30 17:19 Daniel Drake
  2012-04-30 17:29 ` Eric Sandeen
  2012-04-30 17:33 ` djwong
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Drake @ 2012-04-30 17:19 UTC (permalink / raw)
  To: linux-ext4

Hi,

OLPC has started using ext4 online resizing to grow our filesystems to
use the whole SD card on first boot - something we never did before.
Working very nicely, thanks!

I'm trying to simplify/improve the scripts involved in doing this.

How can I programatically check if an ext4 fs already fills its
partition, or if it has room to grow?


The numbers produced by dumpe2fs (e.g. block count) or "df" don't seem
to exactly line up with the sizes produced by fdisk.
One easy solution, if possible, would be to find out the number of the
last sector used by the filesystem. I could then very easily compare
this to the "end" information found in sysfs for the partition. Then I
can make the decision on whether to grow or not.

Thanks
Daniel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Determining if an ext4 fs uses the whole partition
  2012-04-30 17:19 Determining if an ext4 fs uses the whole partition Daniel Drake
@ 2012-04-30 17:29 ` Eric Sandeen
  2012-04-30 17:37   ` Jeff Moyer
  2012-04-30 18:18   ` Daniel Drake
  2012-04-30 17:33 ` djwong
  1 sibling, 2 replies; 7+ messages in thread
From: Eric Sandeen @ 2012-04-30 17:29 UTC (permalink / raw)
  To: Daniel Drake; +Cc: linux-ext4

On 4/30/12 12:19 PM, Daniel Drake wrote:
> Hi,
> 
> OLPC has started using ext4 online resizing to grow our filesystems to
> use the whole SD card on first boot - something we never did before.
> Working very nicely, thanks!
> 
> I'm trying to simplify/improve the scripts involved in doing this.
> 
> How can I programatically check if an ext4 fs already fills its
> partition, or if it has room to grow?
> 
> 
> The numbers produced by dumpe2fs (e.g. block count) or "df" don't seem
> to exactly line up with the sizes produced by fdisk.

Do you have an example of this?

For starters, use fdisk -u to get 512-byte sector units,
otherwise it's just inscrutable CHS magic.

i.e.:

# fdisk -lu /dev/sda2

Disk /dev/sda2: 526 MB, 526417920 bytes
255 heads, 63 sectors/track, 64 cylinders, total 1028160 sectors
Units = sectors of 1 * 512 = 512 bytes

so 1028160 512-byte sectors.

# dumpe2fs -h /dev/sda2 | grep "Block count\|Block size"
dumpe2fs 1.42.2 (27-Mar-2012)
Block count:              514080
Block size:               1024

so 514080 1k blocks, or 1028160 512-byte sectors, so bingo, it's full.

Of course you can't use an odd sector hanging off the end, so you'd
need to do a little rounding down to the nearest fs block size.
Otherwise, it should be straightforward.

Or, FWIW, it's harmless to invoke resize2fs if the fs already fills the
partition; it should just exit with a no-op.

> One easy solution, if possible, would be to find out the number of the
> last sector used by the filesystem. I could then very easily compare
> this to the "end" information found in sysfs for the partition. Then I
> can make the decision on whether to grow or not.

dumpe2fs should certainly be able to tell you.  Mounting the fs, and
doing statfs would, as well (f_blocks).  There should also be libext2fs
functions you could use if you want to do it in C...

-Eric

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Determining if an ext4 fs uses the whole partition
  2012-04-30 17:19 Determining if an ext4 fs uses the whole partition Daniel Drake
  2012-04-30 17:29 ` Eric Sandeen
@ 2012-04-30 17:33 ` djwong
  1 sibling, 0 replies; 7+ messages in thread
From: djwong @ 2012-04-30 17:33 UTC (permalink / raw)
  To: Daniel Drake; +Cc: linux-ext4

On Mon, Apr 30, 2012 at 11:19:31AM -0600, Daniel Drake wrote:
> Hi,
> 
> OLPC has started using ext4 online resizing to grow our filesystems to
> use the whole SD card on first boot - something we never did before.
> Working very nicely, thanks!
> 
> I'm trying to simplify/improve the scripts involved in doing this.
> 
> How can I programatically check if an ext4 fs already fills its
> partition, or if it has room to grow?

Is it not the case that there's room to grow if:

(ext4_block_count * ext4_block_size) - (bdev_size * 512) >= ext4_block_size

> The numbers produced by dumpe2fs (e.g. block count) or "df" don't seem
> to exactly line up with the sizes produced by fdisk.

How far off are the counts?  A small number of sectors, or many?

--D

> One easy solution, if possible, would be to find out the number of the
> last sector used by the filesystem. I could then very easily compare
> this to the "end" information found in sysfs for the partition. Then I
> can make the decision on whether to grow or not.
> 
> Thanks
> Daniel
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Determining if an ext4 fs uses the whole partition
  2012-04-30 17:29 ` Eric Sandeen
@ 2012-04-30 17:37   ` Jeff Moyer
  2012-04-30 19:01     ` Ted Ts'o
  2012-04-30 18:18   ` Daniel Drake
  1 sibling, 1 reply; 7+ messages in thread
From: Jeff Moyer @ 2012-04-30 17:37 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Daniel Drake, linux-ext4

Eric Sandeen <sandeen@redhat.com> writes:

> On 4/30/12 12:19 PM, Daniel Drake wrote:
>> Hi,
>> 
>> OLPC has started using ext4 online resizing to grow our filesystems to
>> use the whole SD card on first boot - something we never did before.
>> Working very nicely, thanks!
>> 
>> I'm trying to simplify/improve the scripts involved in doing this.
>> 
>> How can I programatically check if an ext4 fs already fills its
>> partition, or if it has room to grow?
>> 
>> 
>> The numbers produced by dumpe2fs (e.g. block count) or "df" don't seem
>> to exactly line up with the sizes produced by fdisk.
>
> Do you have an example of this?
>
> For starters, use fdisk -u to get 512-byte sector units,
> otherwise it's just inscrutable CHS magic.

Note that fdisk -u gives sector units, which may or may not be 512
bytes:

$ sudo fdisk -lu /dev/sdb
Note: sector size is 4096 (not 512)

Disk /dev/sdb: 300.1 GB, 300069052416 bytes
255 heads, 63 sectors/track, 4560 cylinders, total 73259046 sectors
Units = sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Cheers,
Jeff

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Determining if an ext4 fs uses the whole partition
  2012-04-30 17:29 ` Eric Sandeen
  2012-04-30 17:37   ` Jeff Moyer
@ 2012-04-30 18:18   ` Daniel Drake
  2012-04-30 18:26     ` Eric Sandeen
  1 sibling, 1 reply; 7+ messages in thread
From: Daniel Drake @ 2012-04-30 18:18 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: linux-ext4

On Mon, Apr 30, 2012 at 11:29 AM, Eric Sandeen <sandeen@redhat.com> wrote:
> For starters, use fdisk -u to get 512-byte sector units,
> otherwise it's just inscrutable CHS magic.
>
> i.e.:
>
> # fdisk -lu /dev/sda2
>
> Disk /dev/sda2: 526 MB, 526417920 bytes
> 255 heads, 63 sectors/track, 64 cylinders, total 1028160 sectors
> Units = sectors of 1 * 512 = 512 bytes
>
> so 1028160 512-byte sectors.
>
> # dumpe2fs -h /dev/sda2 | grep "Block count\|Block size"
> dumpe2fs 1.42.2 (27-Mar-2012)
> Block count:              514080
> Block size:               1024
>
> so 514080 1k blocks, or 1028160 512-byte sectors, so bingo, it's full.

Hmm yes, following the same process I can get the same results. I must
have misread/miscalculated something when I looked earlier.
User error :)

> Or, FWIW, it's harmless to invoke resize2fs if the fs already fills the
> partition; it should just exit with a no-op.

Thanks for pointing this out - its probably my best option, coming to
think of it.

>> One easy solution, if possible, would be to find out the number of the
>> last sector used by the filesystem. I could then very easily compare
>> this to the "end" information found in sysfs for the partition. Then I
>> can make the decision on whether to grow or not.
>
> dumpe2fs should certainly be able to tell you.  Mounting the fs, and
> doing statfs would, as well (f_blocks).  There should also be libext2fs
> functions you could use if you want to do it in C...

Trying the statfs approach (the fs in question is already mounted):

# dumpe2fs -h /dev/mmcblk0p2 | grep "Block count\|Block size"
dumpe2fs 1.42 (29-Nov-2011)
Block count:              949248
Block size:               4096

# stat -f /
  File: "/"
    ID: f09a7645207bdd68 Namelen: 255     Type: ext2/ext3
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 934935     Free: 198205     Available: 188947
Inodes: Total: 227824     Free: 133103

The numbers don't agree.

(Not a big deal, since I can use the other 2 approaches you mentioned,
just wanted to point it out)

Thanks
Daniel
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Determining if an ext4 fs uses the whole partition
  2012-04-30 18:18   ` Daniel Drake
@ 2012-04-30 18:26     ` Eric Sandeen
  0 siblings, 0 replies; 7+ messages in thread
From: Eric Sandeen @ 2012-04-30 18:26 UTC (permalink / raw)
  To: Daniel Drake; +Cc: linux-ext4

On 4/30/12 1:18 PM, Daniel Drake wrote:

...

> Trying the statfs approach (the fs in question is already mounted):
> 
> # dumpe2fs -h /dev/mmcblk0p2 | grep "Block count\|Block size"
> dumpe2fs 1.42 (29-Nov-2011)
> Block count:              949248
> Block size:               4096
> 
> # stat -f /
>   File: "/"
>     ID: f09a7645207bdd68 Namelen: 255     Type: ext2/ext3
> Block size: 4096       Fundamental block size: 4096
> Blocks: Total: 934935     Free: 198205     Available: 188947
> Inodes: Total: 227824     Free: 133103
> 
> The numbers don't agree.
> 
> (Not a big deal, since I can use the other 2 approaches you mentioned,
> just wanted to point it out)

Oh, that's because statfs on extN subtracts out the "overhead" from superblocks,
block group descriptors, etc.    I guess that's a reasonable interpretation
of "/* total data blocks in file system */" but honestly I forgot that
it did that... TBH, not entirely sure why it does.

-Eric

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Determining if an ext4 fs uses the whole partition
  2012-04-30 17:37   ` Jeff Moyer
@ 2012-04-30 19:01     ` Ted Ts'o
  0 siblings, 0 replies; 7+ messages in thread
From: Ted Ts'o @ 2012-04-30 19:01 UTC (permalink / raw)
  To: Jeff Moyer; +Cc: Eric Sandeen, Daniel Drake, linux-ext4

On Mon, Apr 30, 2012 at 01:37:42PM -0400, Jeff Moyer wrote:
> 
> Note that fdisk -u gives sector units, which may or may not be 512
> bytes:
> 
> $ sudo fdisk -lu /dev/sdb
> Note: sector size is 4096 (not 512)

Note: you can also get the same numbers from /proc/partitions.

Regards,

					- Ted

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-04-30 19:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-30 17:19 Determining if an ext4 fs uses the whole partition Daniel Drake
2012-04-30 17:29 ` Eric Sandeen
2012-04-30 17:37   ` Jeff Moyer
2012-04-30 19:01     ` Ted Ts'o
2012-04-30 18:18   ` Daniel Drake
2012-04-30 18:26     ` Eric Sandeen
2012-04-30 17:33 ` djwong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.