[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: selectively delete partitions



On 1/30/06, Stephen Mah <smah vmware com> wrote:
> Is there a way to tell anaconda to remove all partitions except for the
> first partition?
> Or does anyone have a %pre script that can kill all the partitions
> except for a partition of a certain type?
>
I've used sfdisk to do this in the past, if you want to keep only the
first partition, you can do something like this in a %pre:

sfdisk -d /dev/sda > /tmp/sfdisk.sda
egrep '^(unit|/dev/sda1 )' /tmp/sfdisk.sda | sfdisk

Note that in this example there is a space after sda1, which may be
important if you have a lot of partitions and don't want it to keep
sda10 or sda11 for example.  You can also replace the egrep with
whatever you want to do to keep the correct partitions.  For example,
if you want to just keep the Linux partitions (type 83), you could do
this:

(egrep '^units' /tmp/sfdisk.sda; egrep 'ID=( 5|83)' /tmp/sfdisk.sda) | sfdisk

You may or may not need the 5 (the extended partition) depending on
your requirements.

I've also setup systems to keep the first linux partition and the
first swap partition like this:

%pre
sfdisk -d /dev/sda > /tmp/sfdisk.sda
(
    head -3 /tmp/sfdisk.sda
    (
        grep Id=82 /tmp/sfdisk.sda | head -1
        grep Id=83 /tmp/sfdisk.sda | head -1
    ) | sort
) | sfdisk

(These systems didn't have anything I wanted to keep on the extended
partition, so keep that in mind.)

--
Jason Kohles
email jasonkohles com - http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]