To extend the size of an ext3/ext4 formatted disk (partition and filesystem) in Linux; you can use fdisk and resize2fs programs..
The approach for extending the disk size is basically first extending the partition of the related filesystem, and then extending the filesystem to the available blocks of the extended partition.
To extend a partition, we use fdisk.. At least for Oracle Enterprise Linux 5 /Redhat 5 , you dont even unmount the related mount point before doing the work..
Basically, we use fdisk to drop the partition and recreate it with the new size.. We declare the new partition's start point as the old one.. Also cylinder,sector, head etc.. configuration of the new partition should match with the old one.
Here is an example ;
Extending second partition(/dev/sda2) of device /dev/sda , which is mounted to "/" bytheway..
------------------------------------------------------------------------------------------
fdisk /dev/sda
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) : p
Disk /dev/sda: 118.1 GB, 118111600640 bytes
255 heads, 63 sectors/track , 14359 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical / physical) : 512 bytes /512 bytes
I/O size (minimum / optimal) : 512 bytes / 512 bytes
Disk identifier : 0x0001b304
Device Boot Start End Blocks Id System
/dev/sda1 1 523 4194304 82 Linux swap /Solaris
Partition 1 does not end on cylinder boundary.
/dev/sda2 * 523 13055 100662272 83 Linux
Command (m for help) : d
Partition number (1-4) : 2
Command (m for help) : p
Disk /dev/sda: 118.1 GB, 118111600640 bytes
255 heads, 63 sectors/track , 14359 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical / physical) : 512 bytes /512 bytes
I/O size (minimum / optimal) : 512 bytes / 512 bytes
Disk identifier : 0x0001b304
Device Boot Start End Blocks Id System
/dev/sda1 1 523 4194304 82 Linux swap /Solaris
Partition 1 does not end on cylinder boundary.
Command (m for help) : n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4) : 2
First cylinder (523-14359, default 523):
Using default value 523
Last cylinder, +cylinders or +size{K,M,G} (523-14359, default 14359) :
Using default value 14359
Command (m for help) : p
Disk /dev/sda: 118.1 GB, 118111600640 bytes
255 heads, 63 sectors/track , 14359 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical / physical) : 512 bytes /512 bytes
I/O size (minimum / optimal) : 512 bytes / 512 bytes
Disk identifier : 0x0001b304
Device Boot Start End Blocks Id System
/dev/sda1 1 523 4194304 82 Linux swap /Solaris
Partition 1 does not end on cylinder boundary.
/dev/sda2 * 523 13055 100662272 83 Linux
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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
------------------------------------------------------------------------------------------
That's all.. We created our new partition with the desired size..
Now we are ready to extend our filesystem to the unallocated portion of the new partition ..
We use resize2fs for this..
But to able to make linux use the new partition table, we need to run partprobe command.. To be able to use partprobe , we need to unmount the relevant mount point.. So It seems, in case of extending a root partition, we need to reboot for this.
When the new partition table comes to play, we use resize2fs to extend our filesystem...
Note that, resize2fs may want you to run e2fsck, if so run it..
Example: resize2fs /dev/sda2...
Note that: This is a defective operation... Any mistake or misfortune can make the filesystem unavailable. Always take your backup before these kind of opearations.
Writings on this site does not guarantee anything... The method may change according to your environment...
The approach for extending the disk size is basically first extending the partition of the related filesystem, and then extending the filesystem to the available blocks of the extended partition.
To extend a partition, we use fdisk.. At least for Oracle Enterprise Linux 5 /Redhat 5 , you dont even unmount the related mount point before doing the work..
Basically, we use fdisk to drop the partition and recreate it with the new size.. We declare the new partition's start point as the old one.. Also cylinder,sector, head etc.. configuration of the new partition should match with the old one.
Here is an example ;
Extending second partition(/dev/sda2) of device /dev/sda , which is mounted to "/" bytheway..
------------------------------------------------------------------------------------------
fdisk /dev/sda
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) : p
Disk /dev/sda: 118.1 GB, 118111600640 bytes
255 heads, 63 sectors/track , 14359 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical / physical) : 512 bytes /512 bytes
I/O size (minimum / optimal) : 512 bytes / 512 bytes
Disk identifier : 0x0001b304
Device Boot Start End Blocks Id System
/dev/sda1 1 523 4194304 82 Linux swap /Solaris
Partition 1 does not end on cylinder boundary.
/dev/sda2 * 523 13055 100662272 83 Linux
Command (m for help) : d
Partition number (1-4) : 2
Command (m for help) : p
Disk /dev/sda: 118.1 GB, 118111600640 bytes
255 heads, 63 sectors/track , 14359 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical / physical) : 512 bytes /512 bytes
I/O size (minimum / optimal) : 512 bytes / 512 bytes
Disk identifier : 0x0001b304
Device Boot Start End Blocks Id System
/dev/sda1 1 523 4194304 82 Linux swap /Solaris
Partition 1 does not end on cylinder boundary.
Command (m for help) : n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4) : 2
First cylinder (523-14359, default 523):
Using default value 523
Last cylinder, +cylinders or +size{K,M,G} (523-14359, default 14359) :
Using default value 14359
Command (m for help) : p
Disk /dev/sda: 118.1 GB, 118111600640 bytes
255 heads, 63 sectors/track , 14359 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical / physical) : 512 bytes /512 bytes
I/O size (minimum / optimal) : 512 bytes / 512 bytes
Disk identifier : 0x0001b304
Device Boot Start End Blocks Id System
/dev/sda1 1 523 4194304 82 Linux swap /Solaris
Partition 1 does not end on cylinder boundary.
/dev/sda2 * 523 13055 100662272 83 Linux
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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
------------------------------------------------------------------------------------------
That's all.. We created our new partition with the desired size..
Now we are ready to extend our filesystem to the unallocated portion of the new partition ..
We use resize2fs for this..
But to able to make linux use the new partition table, we need to run partprobe command.. To be able to use partprobe , we need to unmount the relevant mount point.. So It seems, in case of extending a root partition, we need to reboot for this.
When the new partition table comes to play, we use resize2fs to extend our filesystem...
Note that, resize2fs may want you to run e2fsck, if so run it..
Example: resize2fs /dev/sda2...
Note that: This is a defective operation... Any mistake or misfortune can make the filesystem unavailable. Always take your backup before these kind of opearations.
Writings on this site does not guarantee anything... The method may change according to your environment...
No comments :
Post a Comment
If you will ask a question, please don't comment here..
For your questions, please create an issue into my forum.
Forum Link: http://ermanarslan.blogspot.com.tr/p/forum.html
Register and create an issue in the related category.
I will support you from there.