Avant toute chose : sauvegardez vos données si elles sont sensibles !
Pour agrandir une partition et son système de fichiers, il faut :
- Agrandir la partition
- Agrandir le système de fichier
Pour rétrécir une partition et son système de fichiers, il faut :
- Rétrécir le système de fichier
- Rétrécir la partition
Pour une partition ext3, le plus simple est d’utiliser parted :
parted /dev/sdx print resize N
Parted ne supporte pas (encore ?) ext4. Pour une partition ext4, ou si parted n’arrive pas à redimensionner votre partition ext3 (Error: File system has an incompatible feature enabled.), utilisez resize2fs :
Pour agrandir :
cfdisk /dev/sdx # supprimer la partition puis la recréer de la taille voulue resize2fs /dev/sdxY
Sans préciser de taille, resize2fs agrandit le système de fichier à la taille de la partition.
Pour rétrécir, c’est presque aussi simple :
# exemple si on veut une partition de 10G # on redimensionne avec une taille plus petite que la taille voulue resize2fs /dev/sdxY 9G cfdisk /dev/sdx # supprimer la partition puis la recréer de la taille voulue # (un peu plus grande que le système de fichiers !!) # puis on relance resize2fs resize2fs /dev/sdxY
On obtient ainsi la bonne taille de partition, sans perdre d’espace.
Notes :
- Si votre partition est en LVM, vous pourrez utiliser les commandes
lvresizeoulvextendoulvreducepour redimensionner la partition, à la place de supprimer/recréer la partition avec cfdisk. - La méthode fonctionne aussi pour d’autres systèmes de fichiers tel que le NTFS. Pour NTFS, on utilisera la commande ntfsresize, ou parted s’il fonctionne.
Liens :



Au temps du FAT, avant de redimensionner, on prescrivait de défragmenter pour rassembler les données. Mais sur un système de fichier comme l’ext3 ? Tu as déjà essayé ça avec une partition contenant des données ? Est-ce qu’il y a un avertissement si le redimensionnement supprime des secteurs où figurent des données ?
Le man resize2fs ne dit rien à ce sujet.
Mais il suffit de faire le test :
# dd if=/dev/zero of=/tmp/mondisque count=50000
# ls -lh /tmp/mondisque
-rw-r–r– 1 dooblem users 25M Jan 9 23:47 /tmp/mondisque
# mount -o loop /tmp/mondisque /mnt/test/
# cp fichiers_enormes /mnt/test/ # copier pleins de trucs pour remplir
# umount /mnt/test/
# resize2fs /tmp/mondisque 15M
resize2fs 1.41.9 (22-Aug-2009)
Resizing the filesystem on /tmp/mondisque to 15360 (1k) blocks.
The filesystem on /tmp/mondisque is now 15360 blocks long.
Donc pas de danger avec resize2fs (le contraire m’eut étonné). Par contre attention avec cfdisk.
Do you understand that this is high time to get the <a>business loans</a>, which would help you.
une tres belle facons de voir les choses oui meme si je suis ps convaincu que ca peut parcher :)
Bon fini les liens publicitaires robotisés là :)
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…
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.
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) wouldn’t 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.
Will this LOOSE my data ? I need to resise an ext4 /home partition (/dev/sda9) to make space for something else but I don’t 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 can’t go to the gui with no /home so I can’t use gparted.
to Antonello,
It should not loose your data. Of course, it’s *always* a smart idea to have a current backup before you start! (-;
Rick
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.
Hi Tim,
Yes, you’re right : it’s better to use fdisk to be sure that the partition keeps the same start.
Pingback: Linux boot with broken partition | Question and Answer
Pingback: Unix:How to extend CentOS 5 partition on VMware? – Unix Questions
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
Shrinking ext4 worked exactly as described, using resize2fs, cfdisk, resize2fs again.
Thanks a lot for posting, cheers!