# ext4 and online resize[SOLVED]

## upengan78

Hi,

I came across this http://www.linuxtoday.com/high_performance/2012011200941OSKN and wondering which gentoo kernel version has this feature in it.

This is what I see available on my Gentoo box(x86_64).

eix gentoo-sources

```
[D] sys-kernel/gentoo-sources

     Available versions:  

   (2.6.32-r29)   2.6.32-r29!b!s

   (2.6.32-r39)   ~2.6.32-r39!b!s

   (2.6.32-r40)   ~2.6.32-r40!b!s

   (2.6.32-r41)   ~2.6.32-r41!b!s

   (3.0.17-r2)   3.0.17-r2!b!s

   (3.0.26)   ~3.0.26!b!s

   (3.0.29)   ~3.0.29!b!s

   (3.1.10-r1)   3.1.10-r1!b!s

   (3.2.1-r2)   3.2.1-r2!b!s

   (3.2.12)   3.2.12!b!s

   (3.2.14)   ~3.2.14!b!s

   (3.2.16)   ~3.2.16!b!s

   (3.3.0)   ~3.3.0!b!s

   (3.3.1)   ~3.3.1!b!s

   (3.3.2)   ~3.3.2!b!s

   (3.3.3)   ~3.3.3!b!s

   (3.3.4)   ~3.3.4!b!s

   {build deblob symlink}

     Installed versions:  2.6.38-r6(2.6.38-r6)!b!s(11:50:24 PM 06/24/2011)(-build -deblob -symlink) 2.6.39-r3(2.6.39-r3)!b!s(11:00:47 AM 07/18/2011)(-build -deblob -symlink) 3.0.3(3.0.3)!b!s(10:21:22 AM 08/18/2011)(-build -deblob -symlink) 3.0.6(3.0.6)!b!s(12:04:12 PM 12/07/2011)(-build -deblob -symlink) 3.1.6(3.1.6)!b!s(12:23:42 PM 01/25/2012)(symlink -build -deblob) 3.2.1-r2(3.2.1-r2)!b!s(10:02:43 AM 01/26/2012)(-build -deblob -symlink) 3.2.12(3.2.12)!b!s(04:09:22 PM 03/27/2012)(-build -deblob -symlink)

     Homepage:            http://dev.gentoo.org/~mpagano/genpatches

     Description:         Full sources including the Gentoo patchset for the 3.3 kernel tree

```

Last edited by upengan78 on Thu May 24, 2012 5:20 pm; edited 1 time in total

----------

## i92guboj

Well, any 3.3.x should work. Also, since this is quite new (and in constant movement), make sure you get the latest e2fsprogs as well. Then just use resize2fs. You shouldn't need anything else.

In any case, I'd just create a loopback fs into a tiny file, format it with ext4, and do the tests in there, before you get into the real thing.

And, of course.... make backups.

----------

## upengan78

Cool..thanks for that info and tips. Will give it  a try soon..

----------

## upengan78

So I compiled a new kernel - 3.3.5 and rebooted.

```
name -r

3.3.5-gentoo

```

Loop back device creation:

```
apple@tree.com ~ # cd /nfs1

apple@tree.com nfs1 # dd if=/dev/zero of=ext4.img bs=1024 count=470000

470000+0 records in

470000+0 records out

481280000 bytes (481 MB) copied, 2.2023 s, 219 MB/s

apple@tree.com nfs1 # losetup /dev/loop1 /nfs1/ext4.img 
```

Ext4FS creation on the device:

```

apple@tree.com nfs1 # mkfs.ext4 /dev/loop1 

mke2fs 1.42 (29-Nov-2011)

Discarding device blocks: done                            

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

117856 inodes, 470000 blocks

23500 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=67633152

58 block groups

8192 blocks per group, 8192 fragments per group

2032 inodes per group

Superblock backups stored on blocks: 

   8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Allocating group tables: done                            

Writing inode tables: done                            

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done 
```

Mounted the FS and copied a random file to the mounted to FS:

```
apple@tree.com nfs1 # mkdir /mnt/text4

apple@tree.com nfs1 # mount -t auto /dev/loop1 /mnt/text4/

apple@tree.com nfs1 # cp yEd-3.8.sh /mnt/text4/
```

Running Resize2fs: Getting error

```
apple@tree.com nfs1 # resize2fs -p /dev/loop1 100M

resize2fs 1.42 (29-Nov-2011)

Filesystem at /dev/loop1 is mounted on /mnt/text4; on-line resizing required

resize2fs: On-line shrinking not supported
```

Where did I go wrong?

EDIT: e2fsprogs

eix e2fsprogs

```
[I] sys-fs/e2fsprogs

     Available versions:  [M]~1.41.7-r1 1.41.12 ~1.41.12-r1 1.41.14 1.42 ~1.42.1 {elibc_FreeBSD nls static-libs}

     Installed versions:  1.42(11:33:12 AM 02/23/2012)(nls -elibc_FreeBSD -static-libs)

     Homepage:            http://e2fsprogs.sourceforge.net/

     Description:         Standard EXT2/EXT3/EXT4 filesystem utilities

```

```
[I] sys-libs/e2fsprogs-libs

     Available versions:  [M]~1.41.7 1.41.12 1.41.14 1.42 ~1.42.1 {nls static-libs}

     Installed versions:  1.42(10:44:17 AM 02/23/2012)(nls -static-libs)

     Homepage:            http://e2fsprogs.sourceforge.net/

     Description:         e2fsprogs libraries (common error and subsystem)
```

----------

## i92guboj

You didn't do anything wrong. "resize" is not exactly the same than "shrink". "resize" can be "shink" or "grow". You can grow an fs on-line, but you can't "shrink" it, at least for now.

----------

## upengan78

OK. Thanks. 

Thinking about growing ext4 now. So I thought I 'd create a small size partiton in loopback device and grow it to the loopback device size. Is it possible? 

I gave it a try. Got stuck at a partition in lopback device. I can create a partition like this,

```

fdisk /dev/loop1 

Command (m for help): p

Disk /dev/loop1: 481 MB, 481280000 bytes

160 heads, 6 sectors/track, 979 cylinders, total 940000 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

Disk identifier: 0xbb3c272b

      Device Boot      Start         End      Blocks   Id  System

/dev/loop1p1            2048      411647      204800   83  Linux
```

but I can't mkfs.ext4 /dev/loop1p1 <-- there is only /dev/loop1 not /dev/loop1p1 . I am stuck.

Any way to get this going?

----------

## i92guboj

You need to use loopback devices here. I googled quickly and found this, which will save me some writting   :Laughing: 

http://wiki.osdev.org/Loopback_Device

It's not difficult, just don't be scared by the offsets.

----------

## upengan78

 *i92guboj wrote:*   

> You need to use loopback devices here. I googled quickly and found this, which will save me some writting  
> 
> http://wiki.osdev.org/Loopback_Device
> 
> It's not difficult, just don't be scared by the offsets.

 

Well, thanks but thatdoes look scary. Will give it a try for sure and let you know how that goes. 

Thanks again!

----------

## upengan78

Got it. Looks like it worked.

 df -kh

```
Filesystem             Size  Used Avail Use% Mounted on

/dev/loop0              99M   52M   43M  55% /mnt/text4

```

# resize2fs /dev/loop0

```
resize2fs 1.42.1 (17-Feb-2012)

Filesystem at /dev/loop0 is mounted on /mnt/text4; on-line resizing required

old_desc_blocks = 1, new_desc_blocks = 2

The filesystem on /dev/loop0 is now 503872 blocks long.
```

# df -kh

```
Filesystem             Size  Used Avail Use% Mounted on

/dev/loop0             489M   63M  406M  14% /mnt/text4
```

Thanks very much again.

----------

## i92guboj

You are welcome.

This kind of stuff can look scary at first sight, but to me picking an offset is not too different from picking a graphic line in gparted and dragging it somewhere to resize a partition or create it. But that's maybe because I've been using text interfaces for a longer time than I've been using GUIs  :Wink: 

By the way, now that you know the right way to do it, I can tell you that gparted can also partition loopback files without all this paraphernalia.  :Laughing: 

----------

## upengan78

 *i92guboj wrote:*   

> You are welcome.
> 
> This kind of stuff can look scary at first sight, but to me picking an offset is not too different from picking a graphic line in gparted and dragging it somewhere to resize a partition or create it. But that's maybe because I've been using text interfaces for a longer time than I've been using GUIs 
> 
> By the way, now that you know the right way to do it, I can tell you that gparted can also partition loopback files without all this paraphernalia. 

 

YOU!! Why you didn't tell me that before!  :Mad: 

 :Laughing: 

----------

## i92guboj

I saw you were decided to use fdisk and to learn, and didn't want to spoil the fun of it   :Laughing: 

----------

## upengan78

 *i92guboj wrote:*   

> I saw you were decided to use fdisk and to learn, and didn't want to spoil the fun of it  

 

Yeah, right. Thanks!!

Actually, my experience with fdisk was only upto choosing letters in fdisk's interface and letting it do everything. I am not too comfortable when it comes to CHS stuff. Is there a place where I can read about CHS stuff , MBR and this all in relation to linux file systems..I am always confused about these things as different file systems have different implementations but once I know what to look for and what tool may help in such cases(where data starts, are CHS numbers shown in fdisk correct, what they mean, etc..), I will be in better position then. 

It is only when playing with loopback drive partitions I am seeing such a long fdisk command  :Very Happy: 

Thanks again!

----------

