Examine Partition Table

[[email protected] ~]# parted
GNU Parted 1.8.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
 
(parted) print
 
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 223GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
 
Number  Start   End     Size    Type      File system  Flags
 1      32.3kB  107MB   107MB   primary   ext3         boot
 2      107MB   8694MB  8587MB  primary   linux-swap
 3      8694MB  11.3GB  2624MB  primary   ext3
 4      11.3GB  58.0GB  46.7GB  extended
 5      11.3GB  13.4GB  2097MB  logical   ext3
 6      13.4GB  15.0GB  1571MB  logical   ext3
 7      15.0GB  16.0GB  1045MB  logical   ext3
 8      16.0GB  58.0GB  41.9GB  logical   ext3

Resize Extended Partition

(parted) help resize
  resize NUMBER START END resize partition NUMBER and its file system
 
        NUMBER is the partition number used by Linux.  On MS-DOS disk labels, the primary partitions number from 1 to 4,
        logical partitions from 5 onwards.
        START and END are disk locations, such as 4GB or 10%.  Negative values count from the end of the disk.  For example,
        -1s specifies exactly the last sector.
        The partition must have one of the following FS-TYPEs: ext3, ext2, fat32, fat16, hfsx, hfs+, hfs, linux-swap.  At the
        moment resize does not support ext3 file systems.

The NUMBER of the partition to resize from the above table is ‘4‘ – the extended partition

(parted) resize 4 11.3GB 223GB

Verify the Resize Results

After running the resize command, you will want to verify your changes by printing the partition table and comapring with the original values of the table prior to the changes.

(parted) print
 
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 223GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
 
Number  Start   End     Size    Type      File system  Flags
 1      32.3kB  107MB   107MB   primary   ext3         boot
 2      107MB   8694MB  8587MB  primary   linux-swap
 3      8694MB  11.3GB  2624MB  primary   ext3
 4      11.3GB  223GB   212GB   extended
 5      11.3GB  13.4GB  2097MB  logical   ext3
 6      13.4GB  15.0GB  1571MB  logical   ext3
 7      15.0GB  16.0GB  1045MB  logical   ext3
 8      16.0GB  58.0GB  41.9GB  logical   ext3
 
(parted)

Adding a New Logical Partition

At this point, we will switch to fdisk. Again, this is by preference, the same actions could be completed with fdisk.

[[email protected] ~]# fdisk /dev/sda
 
The number of cylinders for this disk is set to 27152.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
 
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
 
Command (m for help):

Print the partition table, making sure the sizes are as expected.

Command (m for help): p
 
Disk /dev/sda: 223.3 GB, 223338299392 bytes
255 heads, 63 sectors/track, 27152 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1057     8385930   82  Linux swap / Solaris
/dev/sda3            1058        1376     2562367+  83  Linux
/dev/sda4            1377       27152   207045720    5  Extended
/dev/sda5            1377        1631     2048256   83  Linux
/dev/sda6            1632        1822     1534176   83  Linux
/dev/sda7            1823        1949     1020096   83  Linux
/dev/sda8            1950        7049    40965718+  83  Linux
 
Command (m for help):

We will be adding a new logical partition. It will automatically be numbered by fdisk as /dev/sda9 for this example. The new logical partition will begin at the end of /dev/sda8 and take the remaining space of the exteneded partition. Running the command to create a new partition, verify and take the default values to size as explained.

Command (m for help): n
First cylinder (7050-27152, default 7050):
Using default value 7050
Last cylinder or +size or +sizeM or +sizeK (7050-27152, default 27152):
Using default value 27152
 
Command (m for help): p
 
Disk /dev/sda: 223.3 GB, 223338299392 bytes
255 heads, 63 sectors/track, 27152 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1057     8385930   82  Linux swap / Solaris
/dev/sda3            1058        1376     2562367+  83  Linux
/dev/sda4            1377       27152   207045720    5  Extended
/dev/sda5            1377        1631     2048256   83  Linux
/dev/sda6            1632        1822     1534176   83  Linux
/dev/sda7            1823        1949     1020096   83  Linux
/dev/sda8            1950        7049    40965718+  83  Linux
/dev/sda9            7050       27152   161477316   83  Linux
 
Command (m for help):

At this point, you must write the changes to the partition table. You will get warinings and ominous looking messages. Don’t worry, those are normal.

Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
 
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
 
[[email protected] ~]#

Reboot

Format the New Partition

When the system is back up, verify the changes writted to the partition table.

[[email protected] ~]# fdisk -l
 
Disk /dev/sda: 223.3 GB, 223338299392 bytes
255 heads, 63 sectors/track, 27152 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1057     8385930   82  Linux swap / Solaris
/dev/sda3            1058        1376     2562367+  83  Linux
/dev/sda4            1377       27152   207045720    5  Extended
/dev/sda5            1377        1631     2048256   83  Linux
/dev/sda6            1632        1822     1534176   83  Linux
/dev/sda7            1823        1949     1020096   83  Linux
/dev/sda8            1950        7049    40965718+  83  Linux
/dev/sda9            7050       27152   161477316   83  Linux
[[email protected] ~]#

At this point, you are ready to format the partition for use. This example is using RHEL 5, so we will useext3 for the partition. However, any partition format can be used that is supported.

[[email protected] ~]# mkfs.ext3 /dev/sda9
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
20185088 inodes, 40369329 blocks
2018466 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1232 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872
 
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
 
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[[email protected] ~]#