Re: conversion primary->extended partition possible?
From: Dirk (Dirk_at_DirkDiggler.Net)
Date: 01/27/04
- Next message: Jess: "Dual Boot - Remotely changing"
- Previous message: Bob: "Re: Root on NFS with separate filesystems for /bin, /sbin,..."
- In reply to: Philipp Zehnder: "conversion primary->extended partition possible?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 27 Jan 2004 20:41:28 +1100
"Philipp Zehnder" <pzspam@yahoo.com> wrote in message
news:40162660$1@pfaff2.ethz.ch...
> Hi
>
> Is it possible to convert a primary partition to an extended partition
without
> losing data? I have four primary partitions now but I'd like to shrink one
and
> create an additional one. Therefore I'd like to keep just the first one as
> primary and make the rest extended partitions. Are there any issues with
that
> (e.g. bootloader)?
>
> Thanx,
> Philipp
I know of no utility that will do this for you automatically.
bootloader has no trouble with loading from partitions in extended
partitions.
Perhaps the easiest way to proceed is simply move the files off the one you
want to shrink, delete that, create the extended partition and two sub
partitions,
and then move the files back. Of course you may have trouble with disk space
LVM wouldnt simplify anything at this stage, so lets ignore . (it might make
your life easier if you find you need to do this sort of thing a lot )
And then there is MY unique solution, which doesnt require having the
storage space to move the files OFF the partition.
First some facts.
Suppose you create an extended partition (type "extended") at cylinder 4123,
5000 cylinders long.
The first sector of that cylinder would be the partition table for the
extended partition.
Then you create a logical partition type 'e2fs' or other filesystem type,
in the first 3000 cylinders.
Then you would notice that this partition started at cylinder 4123, but it
started at the 2nd SECTOR (same head). this is because the 1st sector was
used for the extended partition table.
If you add more logical partitions, then actually they get nested in the
spare space inside the first EXTENDED partition, ie in this example, from
cylinder 7123 to 9123.
In each extended partition there are up to TWO partitions defined, one for a
filesystem, and the other for another EXTENDED partition, with its own
partition table...
And so, this gives me an a procedure to do what you want.
0. note that this procedure only works for where the new size of the current
partition is less than half the size of the old partition.
1. given the size of size of a cylinder, calculate a new size that is N
cylinders... minus 4 kilobytes
2. shrink the filesystem back to that size ( there is an e2fs resizer ! )
3. preserve the first sector
dd if=/dev/hda4 of=/root/hda4firstsector count=1
4. using fdisk, delete the partition, and create the two logical partitions
inside an extended partition.
before writing make sure that one logical partition correctly covers the
current location of the filesystem data you want to preserve
probably have to take the filesystem out of /etc/fstab, and reboot...
5. Now you can move the partition...
dd if=/root/hda4firstsector of=/dev/hda6
dd if=/dev/hda5 of=/dev/hda6 skip=1
skip=1 leaves room for first sector we preserved
Notes.
preserving first sector isnt required for e2fs, but is for xfs.
If the size of the filesystem you want to preserve is larger than half the
original size, then you need to move the filesystem back 1 sector.
dd cant do that, and I dont know if there is a util to do it.
you could code it up with perl or C,
or a shell script and dd....
The trick is that you start with the end, and work backward... OR start
playing around with single sectors
OR read sectors one at a time like this,
Read 2, ... read 1, write 1 to 2, read 3, write 2 to 3 , read 4 , write 3
to 4... etc
Or to make that more efficient,
define the buffer to be N + 1 sectors.
read the first N+1 sectors, write N sectors moved along 1 sector, move the
remaining sector to the start of the buffer,fill the buffer,
write N sectors from the buffer translated along a bit, move the remaining
sector in the buffer to the start, read N more sectors..
etc
- Next message: Jess: "Dual Boot - Remotely changing"
- Previous message: Bob: "Re: Root on NFS with separate filesystems for /bin, /sbin,..."
- In reply to: Philipp Zehnder: "conversion primary->extended partition possible?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|