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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-26-2008, 12:16 AM
|
#1
|
Member
Registered: May 2008
Posts: 227
Rep:
|
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.
|
|
|
11-26-2008, 12:43 AM
|
#2
|
Member
Registered: Jul 2005
Location: Mission TX
Distribution: Ubuntu, Mint
Posts: 122
Rep:
|
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.
|
|
|
11-26-2008, 12:51 AM
|
#3
|
Member
Registered: May 2008
Posts: 227
Original Poster
Rep:
|
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.
|
|
|
11-26-2008, 01:00 AM
|
#4
|
Senior Member
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687
Rep:
|
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.
|
|
|
11-26-2008, 01:08 AM
|
#5
|
Member
Registered: Jul 2005
Location: Mission TX
Distribution: Ubuntu, Mint
Posts: 122
Rep:
|
Quote:
Originally Posted by Junior Hacker
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.
|
|
|
11-26-2008, 01:14 AM
|
#6
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,384
|
I think you are talking at cross purposes guys. Both could be right - but not concurrently ... 
|
|
|
11-26-2008, 01:33 AM
|
#7
|
Senior Member
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687
Rep:
|
Quote:
Originally Posted by FewClues
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
|
|
|
11-26-2008, 01:47 AM
|
#8
|
Member
Registered: May 2008
Posts: 227
Original Poster
Rep:
|
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?
|
|
|
11-26-2008, 02:19 AM
|
#9
|
Senior Member
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687
Rep:
|
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.
|
|
|
11-26-2008, 02:41 AM
|
#10
|
Member
Registered: May 2008
Posts: 227
Original Poster
Rep:
|
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?
|
|
|
11-26-2008, 02:34 PM
|
#11
|
Senior Member
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687
Rep:
|
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.
|
|
|
11-26-2008, 03:12 PM
|
#12
|
Member
Registered: Oct 2003
Location: Chico, CA, USA
Distribution: Linux Mint
Posts: 881
Rep: 
|
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
|
|
|
11-26-2008, 07:40 PM
|
#13
|
Member
Registered: May 2008
Posts: 227
Original Poster
Rep:
|
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!
|
|
|
All times are GMT -5. The time now is 03:13 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|