Resize an ext3/ext4 partition

 

2010-01-06 23:41 


Before doing anything: backup your sensible data!

To extend a partition and its filesystem, you have to:


(一)Extend the partition

(二)Extend the filesystem


To shrink a partition and its filesystem, you have to:


(一)Shrink the filesystem

(二)Shrink the partition


For an ext3 partition, simply use parted:
parted /dev/sdx
print
resize N

Parted doesnt support ext4 (yet?). For an ext4 partition or if parted refuses to resize your ext3 partition (Error: File system has an incompatible feature enabled.), use resize2fs:

To extend:
cfdisk /dev/sdx
# delete the partition and create it again with the desired size
resize2fs /dev/sdxY

Without giving any size, resize2fs extends the filesystem to the partitions size.

To shrink, its almost as simple:
# example if you want a 10G partition
# resize filesystem with a size smaller than the desired size
resize2fs /dev/sdxY 9G
cfdisk /dev/sdx
# delete the partition and create it again with the desired size
# (a little bigger than the filesystem!!)
# then launch resize2fs again
resize2fs /dev/sdxY

Doing so we get the good partition size without loosing any space.

Notes:


If your partition is over LVM, you can use the lvresizeorlvextendorlvreduce commands to resize the partition, instead of deleting/creating the partition with cfdisk.

The method also works for other filesystems like NTFS. For NTFS, you will use the ntfsresize command, or parted if it works.


Links :


man resize2fs

http://www.gnu.org/software/parted/manual/parted.html

http://ext4.wiki.kernel.org/

http://ext4.wiki.kernel.org/index.php/Frequently_Asked_Questions#How_to_online_resize_the_Ext4_filesystem.3F

 

2010-01-06 23:41 · Tags: , , , , , , , ,  

11 Comments










mic 
 


Thanks for the article, it shed some light much better than other posts I found on the net. I was able to resize my partition with no error ! I will be back for more


Reply 




david su 
 


dear sir,

in ubuntu server, to reduce the ext4 filesytem size from 1T, i run the resize2fs /dev/mapper/ispconfig-root 500G and got the below output to the console:

Filesystem at /dev/mapper/ispconfig-root is mounted on /; on-line resizing required
On-line shrinking from 267809792 to 131072000 not supported.

it is much appreciated if you can help to email the resolution to my email address qiubosu@gmail.com.

thanks.


Reply 




Kcswalter 
 


Dear David su, asking for a PM just means leaving others with your same problem in the dark. Since this is not a private matter (nothing confidential is passed on) wouldnt it be better to let everyone know?

What the system is saying is that you have to do the resize on an unmounted partition. Filesystem operations like resizing, checking and so on should always be done offline.

You just have to keep a live cd at hand.


Reply 




Antonello 
 


Will this LOOSE my data ? I need to resise an ext4 /home partition (/dev/sda9) to make space for something else but I dont want to loose the data I have inside it.
I can boot and go directly to console as root so I can unmount /home, but then how can I resize it without loosing data inside? For some reasons I cant go to the gui with no /home so I cant use gparted.


Reply 




Rick 
 


to Antonello,

It should not loose your data. Of course, its *always* a smart idea to have a current backup before you start! (-;

Rick


Reply 




Tim Miller Dyck 
 


Hi, a note to check the starting sector before recreating the partition and ensure the new partition starts at the same sector. When I used cfdisk, it created the partition starting at sector 34. I had used fdisk to create the original partition and it created the partition starting at sector 2048. Starting the partition at a different disk location than before, of course, resulted in a partition with no valid file system. I used fdisk again to create the new (larger) partition and all was fine.


Reply 




Marc 
 


Hi Tim,
Yes, youre right : its better to use fdisk to be sure that the partition keeps the same start.


Reply 


Pingback: Linux boot with broken partition | Question and Answer 



Pingback: Unix:How to extend CentOS 5 partition on VMware?  Unix Questions 





Oludario 
 


I just added additional 100gb to /dev/sda on vSphere client. How would you suggest I add the new space to /dev/sda2 shown below?

# fdisk -l /dev/sda

Disk /dev/sda: 221.2 GB, 113816633344 bytes
255 heads, 63 sectors/track, 13837 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: 0x0009c915

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 5690 45493248 83 Linux
/dev/sda3 5690 9229 28432384 83 Linux
/dev/sda4 9229 13838 37017600 5 Extended
/dev/sda5 9230 10645 11372544 83 Linux
/dev/sda6 10646 11495 6823936 83 Linux
/dev/sda7 11495 12203 5686272 83 Linux
/dev/sda8 12203 13272 8584192 82 Linux swap / Solaris
/dev/sda9 13272 13555 2274304 83 Linux
/dev/sda10 13555 13838 2270208 83 Linux


Reply 




DrTebi 
 


Shrinking ext4 worked exactly as described, using resize2fs, cfdisk, resize2fs again.

Thanks a lot for posting, cheers!


Reply 







Leave a Reply 

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>






My Projects

Bsync

Bizou (french KISS php image gallery)

Portquiz.net Outgoing Port Tester

See also !

marcmaurice.fr

Les recettes de Mathilde

Miximum

Palsambleu !

Objectif Libre

sysadmin.smile.fr

Notes du Petitchevalroux

Tags

Arch Linux backup bash BIOS Brasero bsync Cdrdao cdrom CheckInstall Debian email Exim find git GitHub gparted Grub inotify Karmic Linux Lucid MPD Nautilus Raspberry Pi rsync SFTP Spam SSH Thinkpad Ubuntu umask USB USplash XFCE XSplash


Logo LinuxFr
Spreadfirefox Affiliate Button

Support La Quadrature du Net!



© 2024 Libre Things. All rights reserved.

Design by picomol. Powered by WordPress.