LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-26-2008, 12:16 AM   #1
galapogos
Member
 
Registered: May 2008
Posts: 227

Rep: Reputation: 30
Resizing partition of an image file


Hi,

I have an image file that's 16MB with several partitions in it. I wish to use only the 1st partition and delete the rest of the partitions, as well as extend the partition to a larger size. How do I do that?

When I do a fdisk -l on the image file I get the following output(excluding the partition configuration)

Disk image.img: 0 MB, 0 bytes
2 heads, 32 sectors/track, 0 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Disk identifier: 0x5db98c7a

Thanks.
 
Old 11-26-2008, 12:43 AM   #2
FewClues
Member
 
Registered: Jul 2005
Location: Mission TX
Distribution: Ubuntu, Mint
Posts: 122

Rep: Reputation: 20
resizing partition

Removing and resizing a drive is fairly straight forward using the Partition editor (Gparted) Simply delete the unused partitions one at a time and then use the resize command (top row of icons) to resize the current partition to overlap the removed area.
 
Old 11-26-2008, 12:51 AM   #3
galapogos
Member
 
Registered: May 2008
Posts: 227

Original Poster
Rep: Reputation: 30
Thanks Few Clues,

Does this work in KDE as well? I don't have GNOME installed.

Also does it work on image files or must it be a physical drive?

I was hoping fdisk would work but so far I'm only able to delete the partitions. I can't figure out how to resize the remaining partition.

Thanks.
 
Old 11-26-2008, 01:00 AM   #4
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
You would need to write the image file to a disk, like a USB pen drive or hard drive and do the partition modifications, then re-write an image of that drive with dd or similar specifying the size you want to avoid making an image of the entire drive which could be larger than 16MB.
Very simple, would take me about 8 minutes or less.
 
Old 11-26-2008, 01:08 AM   #5
FewClues
Member
 
Registered: Jul 2005
Location: Mission TX
Distribution: Ubuntu, Mint
Posts: 122

Rep: Reputation: 20
Quote:
Originally Posted by Junior Hacker View Post
You would need to write the image file to a disk, like a USB pen drive or hard drive and do the partition modifications, then re-write an image of that drive with dd or similar specifying the size you want to avoid making an image of the entire drive which could be larger than 16MB.
Very simple, would take me about 8 minutes or less.
You don't need to go through all of that. I did a Linux removal from an Dual Boot Windows laptop this afternoon. Used partition editor (available in KDE as well) and simply deleted the undesired partitions one at a time, then using the "resize" command stretched the XP partition to extend the full length of the new unused space.

We do this routinely.
 
Old 11-26-2008, 01:14 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,384

Rep: Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190
I think you are talking at cross purposes guys. Both could be right - but not concurrently ...
 
Old 11-26-2008, 01:33 AM   #7
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
Quote:
Originally Posted by FewClues View Post
We do this routinely.
It don't sound like you're talking "image file", sounds like you're talking about a hard drive partition resize.
I work with images "routinely".
For all intensive purposes, you can dd "just" the partition you want to keep, not the entire image, to a drive and expand it to whatever size you want and dd an image of the single expanded partition.
It's apparent you have "few clues".

Last edited by Junior Hacker; 11-26-2008 at 01:37 AM. Reason: Added "poor sportsman like" comment
 
Old 11-26-2008, 01:47 AM   #8
galapogos
Member
 
Registered: May 2008
Posts: 227

Original Poster
Rep: Reputation: 30
Junior Hacker,
That sounds like the approach I wanted to take, except I don't just also want to retain partition 1, but also the MBR as well. So if the image file is called image.img, I can't just do a "dd -if=image1.img of=newimage.img" right? Since that will only read out the 1st partition without the MBR?

Also, how would I expand it to a new size?
 
Old 11-26-2008, 02:19 AM   #9
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
Normally, if the image is of a drive, you will have the MBR in sector 1, then there is 62 reserved sectors. Your first partition usually starts at offset 63.
If I had a pen drive plugged in and it is seen as /dev/sdb. I would wipe it clean with command: dd if=/dev/zero of=/dev/sdb.
Then to write the image I would: dd if=/path/to/image.img of=/dev/sdb conv=notrunc
Then I use my boot manager/partitioning tool Bootitng to delete un-wanted partitions and expand (and slide if it was anything other than the first partition) the partition I want to keep to the size I want.
Then I would: dd if=/dev/sdb of=/path/to/destination/image.img bs=512 count=sizeIwantinmultiplesof512 conv=notrunc
You can also use a bite size equal to block/cluster size instead of just single sector size. The command: sfdisk -l -uS /dev/sdb will tell exactly how many sectors you have to the end of the partition.
To resize/slide partitions using Linux, use Gparted or parted (command line), or whatever partitioning tool you have installed. I rarely use anything other than Bootitng and the resize2fs command.

Last edited by Junior Hacker; 11-26-2008 at 02:21 AM.
 
Old 11-26-2008, 02:41 AM   #10
galapogos
Member
 
Registered: May 2008
Posts: 227

Original Poster
Rep: Reputation: 30
A few questions...

Can I just use fdisk to delete unwanted partitions?
Why do I need to dd the image file over to a UFD? Can't I work directly on the image file itself to delete the partitions/resize the image file?
 
Old 11-26-2008, 02:34 PM   #11
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
I have little experience with fdisk as I am not bound to Linux and use other tools for partitioning.
You cannot alter partitions while they are mounted in Linux, you can however, alter the space the file system occupies within the partition while it is mounted. When partitions are altered, the offsets have to be written to the MBR of that image which is just a file, not an actual drive.
 
Old 11-26-2008, 03:12 PM   #12
DaneM
Member
 
Registered: Oct 2003
Location: Chico, CA, USA
Distribution: Linux Mint
Posts: 881

Rep: Reputation: 130Reputation: 130
Hello, everybody.

I think I see what the problem may be. The original poster has made an image of his hard drive PARTITION, not the entire drive. That means that he simply cannot use fdisk or any other partitioning tool to edit that image; it would be just like doing "gparted /dev/sda1". It simply wouldn't work right.

One solution, which Junior Hacker mentioned, is to re-image the DRIVE, and then re-partition the new image in such a fashion as "gparted image.img". Also, it's possible (as previously mentioned) to make an image of JUST the partition you want, like this:

Code:
dd if=/dev/sdxy of=image.img conv=notrunc    #/dev/sdx is the drive.  The "y" denotes the partition number.
Once completed, you will have JUST the partition in the image. Note: this partition WILL NOT BOOT if you write it to a drive.

Another possible solution is to put an MBR and partition table in the front of the original image, so that it would then become an image of the whole drive. Something like this might work (back-up the image before trying this!):

First, make an image of the original drive's partition table and MBR:

Code:
dd if=/dev/sdx of=newimg.img count=1 conv=notrunc     #where sdx is your drive - NOT the partition
dd if=oldimg.img of=newimg.img conv=notrunc oflag=append      # oldimg.img is the original image file.  newimg.img is the one you just made/
The drive (/dev/sdx) that you're taking the data from to form the first block of newimg.img MUST have exactly the same partition structure as the original image file does. If your original image is that of only 1 partition, I'm not sure whether it would be seen properly without the other partitions present in the image. Mileage may vary in the partition editor. :-D

Finally, it may be possible to use a tool like testdisk to recover the MBR and partition information from the original image of only the partition. Not sure how that would work.


Generally speaking, you can use any tool that's meant to be used on a drive or partition on a drive or partition image, respectively.

I hope that helps.

--Dane
 
Old 11-26-2008, 07:40 PM   #13
galapogos
Member
 
Registered: May 2008
Posts: 227

Original Poster
Rep: Reputation: 30
Hi,

I manged to fix the problem. Turns out my image file was corrupted, and I was prompted to fix it with e2fsk and 1 other command which I can't remember. After fixing it I also had to disable the dir_index feature before I was able to resize the image with qtparted.

Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
image resizing coolb General 4 04-17-2007 12:55 PM
make complete image file from partition file for qemu lbdgwgt Linux - Newbie 2 11-16-2006 08:04 AM
Resizing a loopback image Jehuty Linux - Hardware 5 08-29-2005 10:52 AM
Image resizing algorithms R00ts Programming 1 07-05-2004 12:56 PM
How to grub install to a partition on an image file via a loopback Owen LaGarde Linux - Software 2 12-26-2003 09:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration