# Solved: Resizing (shrinking) ext3 partition



## vicke4 (Aug 9, 2012)

Hi all,
I have a laptop with 300GB hard disk space.It contains windows 7 & boss linux in three partitions.The partition containing boss linux has 94GB itself.I can't read and write that partition in windows 7.So,i want to shrink that partition to 10GB and convert the remaining 80GB to NTFS.Is there any way to do this?
Thank you.


----------



## BigTobster (Feb 26, 2011)

Use a LiveCD/LiveUSB.

1. Download a LiveCD (Ubuntu would do but could be anything you are familiar with. I am a Ubuntu user and can confirm that the below facility exists on that LiveCD)

2. Boot into the OS on the LiveCD. Configure BIOS appropriately if you have to

3. You can then open Disk Utility and manage that way, use the terminal to manage it or download another tool (such as GParted) and do it that way. 

3.5. Another option is to continue with the Ubuntu install and it gives you the formatting options before you get to the OS install (obviously ). Can format there and just restart the machine before it starts to install the actual OS

In regards to the shared partition, you might want to consider using FAT32. Windows can address this just as well as NTFS (OK perhaps not quite as well but close enough) but FAT32 is much more compatible with most Linux distros. You can have problems with having to be in root at odd times with NTFS in Linux, sets all txt files as executable etc. That said, I use NTFS shared partition and generally no problems! Also, FAT32 has a 4GB cap on file size so if you would go over that, either use NTFS or become familiar with file compression/splitters.

Hope that helps


----------



## TerryNet (Mar 23, 2005)

If you don't already have a Live CD for the above you may want to just create a bootable partition editor, such as GParted.


----------



## saikee (Jun 11, 2004)

One always download a freeware driver to allow Win7 read/write a Linux partition.


----------



## vicke4 (Aug 9, 2012)

Thanks for all of your reply guys i successfully shrinked the boss linux partition to 15GB(that was a 97GB partition now it has only 15GB remaining 82GB is unallocated),now i'm facing one problem i can't create a new partition using the unallocated 82GB.when i try to create a partition,Gparted reads the following,

"It is not possible to create more than 4 primary partitions
If you want more partitions you should first create an extended partition. Such a partition can contain other partitions. Because an extended partition is also a primary partition it might be necessary to remove a primary partition first."

@saikee Really is there a software/driver to read and write linux partitions in windows os?


----------



## saikee (Jun 11, 2004)

> @saikee Really is there a software/driver to read and write linux partitions in windows os?


Yep. done it with Xp and Vista (different drivers) but haven't tried Win7 yet.

It works as part of the Control Panel. When you click it the software show up all the Ext2/3 partitions and ask you to mount any one you want and assigning a drive letter. Thereafter it works just like any other partition.

Nowadays I use a ntfs partition for my data as it can be read write both both Linux and MS Windows.

Have a look here. This facility has existed for donkey years!


----------



## BigTobster (Feb 26, 2011)

Great find Saikee. WIN for you 

In regards to the primary partition problem, there is no easy way around it except to make an extended partition.

http://helpdeskgeek.com/windows-xp-tips/difference-between-primary-and-logical-partition/

This explains the how, why and what.

In short, put OS onto Primaries (but you can get around that if you need more than 3-4 OS) and put your shared area onto an extended.

You should be able to do that in GParted. If not, see above posts for alternatives.


----------



## vicke4 (Aug 9, 2012)

it's not working in windows 7 so i need an alternate solution see my hard disk's partitions in the image attached.


----------



## BigTobster (Feb 26, 2011)

A simple solution would be to remove some of the partitions and restructure. However, you will lose whatever is on those partitions so you could back that up/image it. Going to be quite a lot of effort though.

The attached photo is the basic gist of what you are looking for. 

It boots into GRUB (Bootstrap for Linux) which you don't see on there but then I can choose the Primary Win7 and the Extended container (which is actually a primary area with logical subdivisions). 

You will have to back up, remove and adjust accordingly - or add another drive?


----------



## vicke4 (Aug 9, 2012)

I think I've to delete sda3 & resize the extended partition correct? i don't know how to back/image up a drive. can you tell me the backing up & restoring process? and tell me which partition should i delete (after backing it up)? and which partition should be extended? note:i need both Linux and windows.


----------



## BigTobster (Feb 26, 2011)

Er well it's hard to tell from the image but my best guess...

Sda1 == Boot/Recovery?
Sda2 == Windows/Recovery/Data?
Unallocated == Unallocated (useable but not logically assigned) space
SDa3 == Primary partition that is set to be a extended container
Sda4 == Linux? Seems pretty small reservation but the FS is right
sda5 == Windows/Recovery/Data? - Almost certainly Windows as it is labelled Local Disk - but you want to be sure

As I said, hard to tell. You could find this out more easily by using Partition Manager in Windows and finding out what the labels are and labelling accordingly. You won't get SDAx, SDAy etc but you can work it out from the labels.

Lets assume that sda2 is your Data Drive. Back all the data onto a storage device such as an external hard drive, Flash drive etc. Playing with hard drive partitions is risky, there is every chance that you could irrepairably corrupt all of your data and your operating systems.





The above explains about imaging.

Defragment Windows PLUS any other NTFS/FAT drives that you have. This is REALLY important. If you want to know the science about it - give it a google or ask me if your interested. Otherwise, just take it from me that you should do it.

It may then be worth adding the unallocated space to the extended area to this partition PLUS reduce any other drives that need reducing and add the space to this area. You can do this in GParted. You may also want to bump up the Data drive area with some of the unallocated space.

Set SDA2 to be an extended container which by now should be enourmous.

Then, you should be able to just put your Windows and Linux under an extended partition with your Data Drive on a primary partition.

BUT

This assumes that you have GRUB/Bootstrap lying on a primary partition. BIOS will hand over control to the OS which MUST be on a Primary partition (mostly - ). Seeing as it doesn't seem that it is the case on your machine, it appears that you have got an OS loader lying on a primary partition and the above should be fine. But this is where imaging comes in as a safeguard.

In short:

1. Image your Operating Systems
2. Back up your data
3. Defragment the drive
4. Understand your drive
5. Move your drives around
6. Reboot and rejoice
OR
7. Reboot and spend a lot of time putting your images and data back!

Personally, I prefer to entirely reformat the entire drive from scratch every so often anyway. It improves disk performance, OS performance etc. Now might be a good time for you to do this. You can either just put your images back (not so effective) or install all your Operating Systems from scratch (much more effective but harder and longer work).

http://www.ehow.com/about_5075388_benefits-formatting-hard-drive.html
That link will tell you more about that.

EDIT: Reformatting is also simpler to implement.

1. Back up
2. Image
3. Reformat (Destroy everything you ever had on your drive - ever)(Sort of )
4. Add your own drive allocations
5. Install your OS
6. Put your data back


----------



## vicke4 (Aug 9, 2012)

I wanna make one thing clear i can't format my whole harddisk cause it has an original windows 7 professional.what i want to do is just making the unallocated space to extended partition that's all.i want both Linux and windows.my lap doesn't contain a Dvd drive.


sda1-windows boot partition s(NTFS) 
sda2-local disk c (NTFS) 
sda4-root partition(it contains Linux) (EXT3)
sda5-extended partition for my use(NTFS) 


just take a look at my screenshot
. 
Now please answer the questions below

1.will deleting sda4 give me a chance to resize (extend)the extended partition using the unallocated 82GB? 

2.will Linux work fine,if i make back up(root partition) and restore it back. 

3.really i don't know how to do back up or image and i don't know how to replace it back.please teach me how to do this.


----------



## TerryNet (Mar 23, 2005)

> what i want to do is just making the unallocated space to extended partition that's all


I thought that you wanted to create a primary partition out of the unallocated space? And it looks like you are ready to do that.

But, for what you are saying, have you tried using GParted to resize sda3 to include the unallocated space? Seems to me that should work and result in more free space in the extended partition after sda5.


----------



## vicke4 (Aug 9, 2012)

No i just want to create a NTFS partition using that unallocated 82GB that's all.that vacant space was created by shrinking the ext3 partition.i did that coz i can't read and write ext3 partition in windows7.


----------



## TerryNet (Mar 23, 2005)

Sorry, I did not read your post # 8 screen shot correctly, and was also confused about the primary.

Where is sda4? Is that the partition between sda5 and the large unallocated area? If so, I think (no guarantees) that you can use GParted to move sda4 to the right of the unallocated. That will leave the unallocated just adjacent to the extended partition, and you can resize the extended partition (sda3) to gobble up the unallocated. You can then use the space to create another partition and format it NTFS.


----------



## saikee (Jun 11, 2004)

Please be informed that 99.99% hard disks are formatted to have a MSDOS partition table (the other alternative is GPT which is new and not yet accepted by everyone).

Inside the MBR or the first 512 bytes of a hard disk there are 4x16 bytes reserved for the MSDOS partition table. The 16 bytes are the data describing each partition. These 4 positions are called the primary partitions.

If one wants more partitions one must give up one primary to form an extended partition which still uses the 16 bytes of data for describing the "border" of the extended partition. An extended partition does not have storage of its own but only contain the description of the hard disk address (which cylinder, head, and sector) of the first logical partition and the termination point of the last logical partition. Traditionally Linux by default uses the whole cylinder for defining the boundary of a partition.

Essentially every logical partition carries the hard disk address of next logical partition down the line and so the numbering must be consecutive. .Any space not used in between is dead. If one deletes a logical partition in the middle of a chain the space is dead or absorbed by the adjacent logical partition. However the numbering system will be immediately rearranged resulting the last logical partition device name dropped. If one does partitioning in a Linux terminal one can see how this system works in front of the eyes.

Also there is no possibility to have more than 3 primaries and one extended partition in any MSDOS disk because that is the PC standard. Needless to say there can only be one extended partition in any hard disk in this arrangement.

A good scheme is to use the first 3 primaries and the crated the extended partition on the last part of the hard disk. In that way a user can have up to 128 logical partitions all recognised by MS Windows and Linux.

The OP current has used up the 4 allocations of partition so any unallocated space is dead! unless it follows the end of an extended partition which can be bottomless. Linux never declares the maximum limit of logical partitions but I have managed to boot Ubuntu at about 150th logical partition. I have cloned an Xp into all 128 logical partitions once and found everyone could be booted to work normally.

Thus one can have as many logical partition as one wants but do it with an extended partition at the end of a hard disk and not in any other position.

The solution of OP's problem is to remove the sda4 a primary at the back of the extended partition which is sda3 inside which containing the first logical partition sda5. This will destroy the Linux and require a re-installation but is possibly the easiest. Any valuable data can be transferred to sda5 temporarily and restored after an re-installation.

A more complicated way is to resize sda5 which I suggest using Win7 as it is a lot quicker than Linux Gparted and also guaranteed by M$. Once sda5 is shrunk then one can create a sda6 and clone sda4 into it. This can be done in minutes but sda6 will need to be edited so that it can be booted from sda6, a logical partition, and not sda4 which is a primary. I can offer advice on how this is done but a Linux installation CD will be needed, preferably the from the original Linux installation so that the same boot loader is available.

Once sda4 disappears all the remaining unallocated space can be absorbed into sda3 the extended partition the border of which can be adjusted indefinitely. In fact if one uses cfdisk in a Linux terminal it never mentions extended partition and all space behind it can be used for logical partitions creation.

In Linux if one creates a logical partition the first unused primary partition will be used to form the extended partition. Therefore is one does this with a new disk the first workable partition is sda5 and sda1 becomes reserved for its border.

Hope this explains it.


----------



## DVOM (Jun 21, 2002)

I would first image the linux partition to a folder on sda5.

Then I'd delete the linux partition.

Then I'd expand the extended partition to the end of the drive.

Then I'd create a logical partition of 15 Gigs or more at the right end for linux. Linux will boot from a logical partition.

Then I'd expand sda5 to take up the rest of the space in the extended partition.

Finally, use your imaging program to put your linux image on the last partition.


----------



## vicke4 (Aug 9, 2012)

TerryNet said:


> Sorry, I did not read your post # 8 screen shot correctly, and was also confused about the primary.
> 
> Where is sda4? Is that the partition between sda5 and the large unallocated area? If so, I think (no guarantees) that you can use GParted to move sda4 to the right of the unallocated. That will leave the unallocated just adjacent to the extended partition, and you can resize the extended partition (sda3) to gobble up the unallocated. You can then use the space to create another partition and format it NTFS.


how to do that i mean how to move that sda4 to right of the unallocated space?i tried i can't do that using GParted.

@Saikee please wait i did not read your reply i am busy now.surely i'll read it later and reply you.

@DVOM i already did that i mean i took an image of the linux partition using clonezilla and put that in sda5.i can do what you said but i have a doubt is all things reversible?i have some important files in linux.if i restore the image after doing all things you said will windows be bootable?


----------



## TerryNet (Mar 23, 2005)

> how to do that i mean how to move that sda4 to right of the unallocated space?i tried i can't do that using GParted.


Perhaps I'm doing nothing in this thread but sowing confusion.  I assumed that you can just resize/move sda4 and put all the unallocated space before it. I have a similar situation on my hard drive and in my attachment show how I would move a partition to the right of unallocated space using a different partition manager.


----------



## vicke4 (Aug 9, 2012)

TerryNet said:


> Perhaps I'm doing nothing in this thread but sowing confusion.I assumed that you can just resize/move sda4 and put all the unallocated space before it. I have a similar situation on my hard drive and in my attachment show how I would move a partition to the right of unallocated space using a different partition manager.


Please understand my problem.i don't want to add that unallocated 82GB to sda4.i wanna create a new NTFS partition or to extend the existed one(sda5).


----------



## TerryNet (Mar 23, 2005)

I do understand that part.  To add the unallocated space to sda5 I think that you have to first add it to the enclosing sda3 extended partition. If you want to create a new partition w/o deleting a current primary I think that you need to get that unallocated space into the sda3 extended partition.

To add unallocated space to any partition you need to have it adjacent to the partition. My suggestion to move sda4 to the right of the unallocated space is for the purpose of getting the unallocated space adjacent to sda3/sda5.

Others, who know much more about partitioning than I do, have explained some ways to get rid of a current primary partition so that you can simply create a new one in the current unallocated space. I am sorry if I am just making things harder with my ideas.


----------



## saikee (Jun 11, 2004)

Actually TerryNet got an excellent point here one which I have overlooked.

While the the sda1 (reserved by Windows), sda2 (for Windows), sda3 (extended partition with sda5 inside) and sda4 (not shown what kind) have been used up that no more extra partition can be formed that is because sda4 is wedging the end of sda3.

It is quite acceptable to shift the sda4 "bodily" to the extreme right and so the unallocated space is arranged in between sda3 (only sda5 visible) and sda4. This scheme will work as long as sda4 does not require booting. Even if it does a Linux can be adjusted because all it take is to tell the boot loader the new hard disk address of new position of sda4. Gparted can move sda4 for you. Done this loads of time even with an extended partition with some 60 logical partitions inside that required adjustment to boot.

Once sda4 has been shifedt to the extreme right then you can create new sda6, sda7.... or just expand sda5 to use up the new allocated space. Remember you don't have to use up all the unallocated space as you current hard disk proves this point.

*TerryNet gave the best advice so far!*


----------



## saikee (Jun 11, 2004)

*Advice to make Linux bootable in the new position of sda4 (after it has been moved to the end of the hard disk)*

*Reason why it will not booted*

Grub (both Grub1 & Grub2) has two stages. Stage1 always in MBR and the stage2 in sda4. Stage1 finds the stage2 by the hard disk address hardcoded into stage1 whenever Grub is installed. After you move sda4 to a new location the existing Grub in MBR just go back to the old location to find stage2 so it breaks down.

*A cure*

Boot up a Linux Live CD that has the same Grub (assume it is Ubuntu that uses Grub2 below).
mount device /dev/sda4
bind /dev with the mounted sda4 (so that the device names can be found properly)
tell Grub to install itself again in MBR using the mounted partition address
the commands in a Ubuntu terminal are

```
sudo su
mkdir /mnt/here /mnt/dev
mount /dev/sda4 /mnt/here
mount --bind /dev /mnt/dev
grub-install --root-directory=/mnt/here /dev/sda
reboot
```


----------



## vicke4 (Aug 9, 2012)

Saikee,i read your previous solution also.now,i'm going to try terrynet's solution.


----------



## vicke4 (Aug 9, 2012)

saikee said:


> *Advice to make Linux bootable in the new position of sda4 (after it has been moved to the end of the hard disk)*
> *A cure*
> 
> Boot up a Linux Live CD that has the same Grub (assume it is Ubuntu that uses Grub2 below).
> ...


okay so system will become unbootable if i move sda4 to extreme right.i am a begginer in putting commands in command prompt.so please help me.
is bind /dev a code?
i have linux mint 10 live cd.


```
sudo su
mkdir /mnt/here /mnt/dev
mount /dev/sda4 /mnt/here
mount --bind /dev /mnt/dev
grub-install --root-directory=/mnt/here /dev/sda
reboot
```
should i enter the above commands as such?i think i should replace something.eg:--root-directory=
so also tell me which should i replace with what.


----------



## saikee (Jun 11, 2004)

Once boot up LInux Mint (which is another variant of Debian as the Ubuntu family) just select a terminal from the desktop.

You can cut and paste my commands into it and execute.

I explain each line as follow

"sudo su" is permitted in Mint and Ubuntu for a user to claim root user status, like Admin in Windows. For a CD no password is asked.

"mkdir /mnt/here /mnt/dev" is to make directory mounting points /mnt/here and /mnt/dev. These names can be any one a users chooses but /mnt is the standard mounting place in Linux. The other is /media.

"mount /dev/sda4 /mnt/here" is to mount a hardware device called /dev/sda4 on the mounting point of /mnt/here. This is the joy of Linux that a user can specify a hard ware on the Linux filing tree so that one can read/write the hardware's content. No other operating system other than Unix and Linux gives you this thrill!

"mount --bind /dev /mnt/dev" is to bind the /dev directory of the boot-up Mint (in the memory) with the similar /dev directory inside sda4. /dev hold the devices names and may disappear after the Linux is powered down so /devsda4 may be unavailable in the original sda4 partition and only become available only after Linux has been booted up. You need the device names during booting so this statement is recommended. You probably do not need it is da4 was created by the Linux Live CD but it is a good practice to include it.

"grub-install --root-directory=/mnt/here /dev/sda" is the standard Grub command to install Grub in the device /dev/sda which has no partition number meaning it is for the whole disk. In Linux this means the MBR. The --root-directory= is for pointing to the root directory of the Linux because you can put Ubuntu in sda6, Opensuse in sda7, Fedora in sda8 etc but tell Grub which one you want to occupy the MBR.

"reboot" is to trigger a reboot from a terminal which is the fastest way you test the result.

If you do not use a Linux terminal you haven't touched the lion's share of the power available in Linux.

Had you used a Linux terminal to do partitioning you wouldn't have got into your current situation because I have found the best teacher in Linux is its terminal. This is particularly true with partitioning.


----------



## vicke4 (Aug 9, 2012)

yay,my problem solved.i moved the linux partition to right and extended the sda3.system booted as usual i didn't reinstall the grub(i think grub was installed in sda4).Anyway thanks for your notation terrynet .Special thanks to you saikee.

Nice forum for asking technical problem.now i am going to spread this forum among my friends.


----------



## TerryNet (Mar 23, 2005)

You're welcome.  Glad we could help. *saikee* really, really, really knows his partitioning and booting! Just about everything I have learned about those I got from his advice and guides.


----------



## saikee (Jun 11, 2004)

*TerryNe*t,

I am here to learn from you guys too.

You hit the nail on the head and offered the real solution while we went off like a tangent.

*vicke4*,

I noted you say there was no need to restore Grub but there is a reason for it.

When you move the border the binary files of sda4 are still in exactly the same location but no long be read. However the stage2 can still be loaded according to the hard disk address.

One day if you find Grub suddenly fails to boot the it would be because its stage2 has been overwritten when you start using that area.

I mention this so that in future you are prepared for it. I reported this being possible in 2010 by this thread.


----------



## vicke4 (Aug 9, 2012)

Thanks for the info saikee I'll be ready for that(restoring grub)


----------

