Difference between revisions of "Resize partition and file system"

From Wiki at Neela Nurseries
Jump to: navigation, search
 
Line 150: Line 150:
 
Pass 5: Checking group summary information
 
Pass 5: Checking group summary information
 
/dev/sdb10: 11/3694592 files (0.0% non-contiguous), 277913/14752316 blocks
 
/dev/sdb10: 11/3694592 files (0.0% non-contiguous), 277913/14752316 blocks
 +
 +
 +
$ sudo resize2fs /dev/sdb10 15468933
 +
resize2fs 1.42.12 (29-Aug-2014)
 +
The containing partition (or device) is only 14752316 (4k) blocks.
 +
You requested a new size of 15468933 blocks.
 +
 +
$ sudo resize2fs /dev/sdb10 12303431
 +
resize2fs 1.42.12 (29-Aug-2014)
 +
Resizing the filesystem on /dev/sdb10 to 12303431 (4k) blocks.
 +
The filesystem on /dev/sdb10 is now 12303431 (4k) blocks long.
  
 
$
 
$
 
  
  

Latest revision as of 18:05, 20 December 2017

Wiki Main Page | User Page of Ted | Linux From Scratch 8.1 - separate article




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.


Summary

Before running resize2fs on a mounted file system, Ted runs e2fsck file system checking utility first. Then resize2fs can be used to tell us how many 4k or (nk) blocks are present on the block device on which the file system exists. On 2017-12-20 Wednesday, resizing an unused partition which is formatted ext4 and starts out at about 60GB in size:


                                          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       ext4                                        10001.95
     sdb8                             Logical       ext4                                        20003.89
     sdb9                             Logical       ext4                                        50001.48
     sdb10                            Logical       ext4                                        60425.52     *






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

                                 Quit program without writing partition table


<q> to quit . . .

$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
scale = 3

# figuring size of 60GB partition in 4k blocks:
# cfdisk shows size of 60425.52 MB
60425.52 * 1024
61875732.48
61875732.48 / 4096
15106.380

quit


$ sudo e2fsck -f /dev/sdb10
e2fsck 1.42.12 (29-Aug-2014)
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/sdb10: 11/3694592 files (0.0% non-contiguous), 277913/14752316 blocks


$ sudo resize2fs /dev/sdb10 15468933 
resize2fs 1.42.12 (29-Aug-2014)
The containing partition (or device) is only 14752316 (4k) blocks.
You requested a new size of 15468933 blocks.

$ sudo resize2fs /dev/sdb10 12303431
resize2fs 1.42.12 (29-Aug-2014)
Resizing the filesystem on /dev/sdb10 to 12303431 (4k) blocks.
The filesystem on /dev/sdb10 is now 12303431 (4k) blocks long.

$




- - - top of page - - -