View previous topic :: View next topic |
Author |
Message |
arnvidr l33t
Joined: 19 Aug 2004 Posts: 629 Location: Oslo, Norway
|
Posted: Fri Aug 17, 2007 5:27 pm Post subject: Converting primary partition to extended? |
|
|
Is it possible to convert a primary partition to an extended without any data loss? The partition in question is my main root partition, so I can't screw it up without having to reinstall my system... _________________
|
|
Back to top |
|
|
opopanax Apprentice
Joined: 30 Aug 2004 Posts: 244
|
Posted: Sat Aug 18, 2007 4:01 am Post subject: |
|
|
It depends on where it's located on the drive, but either way it's possible. If it's floating around in the middle of the drive somewhere, you can use fdisk to just reallocate the partition table, leaving your data in place. (If practical or mission critical, back up your data).
For instance, suppose when you do ``fdisk /dev/sda'' it looks like this:
Code: |
Disk /dev/sda: 20.0 GB, 20003880960 bytes
255 heads, 63 sectors/track, 2432 cylinders[
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 2325 18675531 83 Linux
/dev/sda2 2326 2432 859477 83 Linux
|
what we're going to do is rewrite the partition table so that sda2 is on an extended partition, without touching the actual data. First, make sure the filesystem is unmounted. If this is a live filesystem, you're going to want to use a livecd, so boot that first. any distribution will do.
Then, run ``fdisk /dev/sda'' (replacing sda with your drive designation).
hit p, and you should get the output above. Do this just to make sure you've got the right drive.
hit d, and choose partition 2. This deletes the partition table entry for the 2nd partition.
hit n (for new), and choose 4 (for convention purposes.) choose 'e' for extended, making sure that the start block for the partition (in my case, 2326) is the same as the deleted partition's. the end should be the end of the drive.
hit n again to create your new logical partition, probably #5. Again, make sure the start block for the new partition is exactly the same as the start for the old partition, and the new ending block is the same as well. Start in this example is 2326, and end is 2432.
Once that's done, hit p to make sure you've done it right, and the new logical partition has exactly the same characteristics as the old one, as below.
Code: |
Disk /dev/sda: 20.0 GB, 20003880960 bytes
255 heads, 63 sectors/track, 2432 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 2325 18675531 83 Linux
/dev/sda4 2326 2432 859477+ 5 Extended
/dev/sda5 2326 2432 859446 83 Linux
|
If you think you've got it wrong, hit 'q' to quit without saving changes. If you've got it correct, hit 'w' to write your new, improved partition table. fdisk will exit.
Use fsck to make sure that your new drive is in good shape still. Mount the drive somewhere, preferably /mnt/gentoo or some such, and change any drive designations in /mnt/gentoo/etc/fstab that have changed, (assuming this is your root partition) and in your boot partitions grub.conf, as well. umount the drive and reboot. Congratulations; you should have successfully changed your drive designation!
Keep in mind that this solution doesn't shift any data whatsoever. the other solution, if you actually have to move the data to make room for something else, would probably be best accomplished using parted, or one of its gui frontends, like qtparted or gparted, or a third party utility like BootIT-NG, of which I'm personally a fan.
Good luck! |
|
Back to top |
|
|
arnvidr l33t
Joined: 19 Aug 2004 Posts: 629 Location: Oslo, Norway
|
Posted: Sun Aug 19, 2007 11:12 am Post subject: |
|
|
It's the last partition on the drive, so I guess it'll work just fine then. I was thinking I just use gparted from a livecd. Doesn't it have a convert feature? _________________
|
|
Back to top |
|
|
Genone Retired Dev
Joined: 14 Mar 2003 Posts: 9539 Location: beyond the rim
|
Posted: Sun Aug 19, 2007 11:32 am Post subject: |
|
|
Better make a backup: An extended partition needs some space at the beginning (before any logical partitions) to store the information about the logical partitions, so the first logical partition won't start at the exact same address as the old primary partition. |
|
Back to top |
|
|
arnvidr l33t
Joined: 19 Aug 2004 Posts: 629 Location: Oslo, Norway
|
Posted: Sun Aug 19, 2007 11:51 am Post subject: |
|
|
So you're saying what opopanax said above might loose me some data? _________________
|
|
Back to top |
|
|
Genone Retired Dev
Joined: 14 Mar 2003 Posts: 9539 Location: beyond the rim
|
Posted: Sun Aug 19, 2007 12:03 pm Post subject: |
|
|
AFAIK that procedure will corrupt your filesystem (likely won't change your actual data, but overwrite critical filesystem structures so your data becomes inaccessible). |
|
Back to top |
|
|
arnvidr l33t
Joined: 19 Aug 2004 Posts: 629 Location: Oslo, Norway
|
Posted: Sun Aug 19, 2007 12:23 pm Post subject: |
|
|
Okay, I have enough space on a different drive to back it up, so I'll do that just in case then _________________
|
|
Back to top |
|
|
opopanax Apprentice
Joined: 30 Aug 2004 Posts: 244
|
Posted: Sun Aug 19, 2007 5:06 pm Post subject: |
|
|
interesting; i've never had problems with it. But, then again, maybe i've never done it quite this way.
Definitely make a backup.
Steve K. |
|
Back to top |
|
|
arnvidr l33t
Joined: 19 Aug 2004 Posts: 629 Location: Oslo, Norway
|
Posted: Sun Aug 19, 2007 9:04 pm Post subject: |
|
|
Well, I'm back from gparted, and it didn't seem to have any option of converting the partition. Now, in hopes of not having to restore a backup, I made it so between my 3rd and 4th primary partition there is now some empty space. I was thinking of 2 different approaches:
1. Do almost as opopanax first suggested, deleting the partition, creating the extended and logical partition at the first cylinder after the 3rd partition.
2. Do the same, only creating the extended partition at the first cylinder after the 3rd partition, and the logical partition where the 4th primary partition now starts.
I'm pretty sure method #2 would work just fine, and I could move the partitions around in gparted afterwards, what if I chose method #1, would my file system be preserved? I'm a little unsure of exactly how that works. Would the logical partition have to be the exact same size as the original primary partition to preserve its file system? _________________
|
|
Back to top |
|
|
arnvidr l33t
Joined: 19 Aug 2004 Posts: 629 Location: Oslo, Norway
|
Posted: Mon Aug 20, 2007 8:06 pm Post subject: |
|
|
Well, I chose method #2 from my post above. fdisk output seems fine:
Code: | Disk /dev/hda: 20.0 GB, 20020396032 bytes
240 heads, 63 sectors/track, 2586 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System
/dev/hda1 1 277 2094088+ 83 Linux
/dev/hda2 278 279 15120 83 Linux
/dev/hda3 280 327 362880 82 Linux swap / Solaris
/dev/hda4 328 2586 17078040 5 Extended
/dev/hda5 328 1367 7862368+ 83 Linux
/dev/hda6 1368 1977 4611568+ 83 Linux
/dev/hda7 1978 2586 4604008+ 83 Linux |
I changed my fstab to what seems reasonable (note I haven't decided what to use hda6 and 7 for yet):
Code: | /dev/hda5 / ext3 defaults,errors=remount-ro 0 1
/dev/hda2 /boot ext2 defaults 0 2
/dev/hda3 none swap sw 0 0
/dev/hda1 /home ext3 defaults,errors=remount-ro 0 |
I removed lines about other devices, since nothing has changed with anything else
And then I updated my grub menu.lst:
Code: | # kopt=root=/dev/hda5 ro
...
title Debian GNU/Linux, kernel 2.6.20-1-686
root (hd0,1)
kernel /vmlinuz-2.6.20-1-686 root=/dev/hda5 ro
initrd /initrd.img-2.6.20-1-686
savedefault |
You'll notice this old workhorse runs Debian, but I hope you can help me anyway. There must be somewhere else that still points to /dev/hda4, it seems I'm trying to mount the extended partition directly on bootup instead of the logical partition. This is what shows on my screen before the bootup process crashes:
Code: | hda: cache flushes not supported
hda: hda1 hda2 hda3 hda4 < hda5 hda6 hda7 >
hdb: max request size: 512KiB
hdb: 390721968 sectors (200049 MB) w/8192KiB Cache, CHS=24321/255/63<6>hdb: hw_config=6d00
, UDMA(66)
hdb: cache flushes supported
hdb: hdb1
attempt to access beyond end of device
hda4: rw=0, want=4, limit=2
EXT3-fs: unable to read superblock
mount: wrong fs type, bad option, bad superblock on /dev/hda4,
missing codepage or other error
*aren't you trying to mount an extended partition,
instead of some logical partition inside?)
In some cases useful info is found in syslog - try
dmesg | tail or so
Switching root ...
/usr/lib/yaird/exec/run_init: current directory on the same filesystem as the root: Success
Kernel panic - not syncing: Attempted to kill init! |
Since it's obviously not managing to mount /dev/hda5 at all (which works just fine from a livecd) but instead trying for /dev/hda4 the only thing in dmesg is from the last successful boot, which doesn't help much. Any ideas on what I might have missed? _________________
|
|
Back to top |
|
|
arnvidr l33t
Joined: 19 Aug 2004 Posts: 629 Location: Oslo, Norway
|
Posted: Tue Aug 21, 2007 8:03 am Post subject: |
|
|
Okay, it seems like update-grub only touches the menu.lst file, and that the main partition is hardcoded in one of the binary files on the grub directory on the boot partition. Some investigation gives me hope that everything will work alright if I issue the following commands in a grub console:
Code: | root (hd0,4)
setup (hd0) |
Will try that as soon as I get home from work. _________________
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|