Resize partition and ext4 file system cfdisk, e2fsck and resize2fs

From Wiki at Neela Nurseries
Jump to: navigation, search


To resize both partition and an existing ext4 journaled file system on same partition, Ted uses following three utilities. Arguments to these utilities are specific to a certain disk but steps overall can be generalized:



ted@localhost:~$ cfdisk /dev/sdb . . .

                                                cfdisk (util-linux 2.20.1)

                                                   Disk Drive: /dev/sdb
                                            Size: 160041885696 bytes, 160.0 GB
                                  Heads: 255   Sectors per Track: 63   Cylinders: 19457

      Name              Flags            Part Type       FS Type                   [Label]               Size (MB)
 ------------------------------------------------------------------------------------------------------------------------
      sdb1              Boot              Primary        ext4                                               106.93        
      sdb5                                Logical        ext4                                             18498.66
      sdb6                                Logical        Linux                                             1003.49
      sdb7                                Logical        Linux                                            10001.95
      sdb8                                Logical        Linux                                            20003.89
      sdb9                                Logical        Linux                                            50001.48
      sdb10                               Logical        Linux                                            60425.52       *




       [ Bootable ]  [  Delete  ]  [   Help   ]  [ Maximize ]  [  Print   ]  [   Quit   ]  [   Type   ]
       [  Units   ]  [  Write   ]

                                       Quit program without writing partition table


# Note:  for final four partitions in general Ted entered one MB greater than desired to achieve the tens of GB value
#   with a little extra showing, due to disk geometry.  For example to get at least 10GB, which is 10000MB, Ted entered
#  '10002' when cfdisk prompts for size of new partition.



ted@localhost:~$

ted@localhost:~$ sudo e2fsck -f /dev/sdb5
e2fsck 1.42.5 (29-Jul-2012)
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
/dev/sdb5: 78593/469568 files (0.3% non-contiguous), 1323428/1875580 blocks

ted@localhost:~$ sudo resize2fs /dev/sdb5 4516265
resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/sdb5 to 4516265 (4k) blocks.
The filesystem on /dev/sdb5 is now 4516265 blocks long.

ted@localhost:~$


Ted didn't automatically know that resize2fs needed its final argument, a numeric argument, to express blocks on the given physical disk. There is mention in forums and manual page for this file system resizing utility taking new size in units of GB, MB and other units. Numeric value has to be expressed as an integer, no decimal point. Ted tried using the closest byte-wise integer value he could determine from partition size listed in cfdisk. Utility resize2fs complained of this value being too large -- it is too large when it represents 4k blocks on the disk -- but resize2fs also reports in the same message what number of blocks are available in the partition. In this way Ted found out to give 4516265 as final argument to file system resizing util.


 $ sudo resize2fs /dev/sdb5 18498660


In more detail here are the warnings and stop messages from resize utility:



$ sudo resize2fs /dev/sdb5 18498660
resize2fs 1.42.5 (29-Jul-2012)
The containing partition (or device) is only 4516265 (4k) blocks.
You requested a new size of 18498660 blocks.

$ sudo resize2fs /dev/sdb5 4516265
resize2fs 1.42.5 (29-Jul-2012)
Please run 'e2fsck -f /dev/sdb5' first.



^ References


- - - top of article - - -