Discussion:
selectively delete partitions
Stephen Mah
2006-01-31 02:28:50 UTC
Permalink
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?

-thanks
steve
Jason Kohles
2006-01-31 16:40:26 UTC
Permalink
Post by Stephen Mah
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
***@jasonkohles.com - http://www.jasonkohles.com/
"A witty saying proves nothing." -- Voltaire
Stephen Mah
2006-01-31 17:05:59 UTC
Permalink
Post by Jason Kohles
I've used sfdisk to do this in the past, if you want to keep only the
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
(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
%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.)
thank you, I'll try that later. That's exactly what I was looking for.

-steve
Ryan C. Spaulding
2006-01-31 16:47:06 UTC
Permalink
Hi Steve,

Do you want to re-partition the rest of the disk, or do you just want
to reuse the existing partition table? To the best of my knowledge
you can only reuse existing partitions. If you want to repartition
the disk your best bet is to just dump the data and install and then
restore.

Thank you,

Ryan
Post by Stephen Mah
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?
-thanks
steve
_______________________________________________
Kickstart-list mailing list
https://www.redhat.com/mailman/listinfo/kickstart-list
Matt Sturtz
2006-01-31 18:08:06 UTC
Permalink
Hi Steve, et al--
Post by Stephen Mah
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 have a Kickstart that is used for brand new Dell systems -- based on
your issue, I suspect you're doing something similar. The issue I have is
that Dell servers come with a Dell Utility partition (shows in fdisk as
partition type DE, but it's really just a FAT16) that is set as bootable
from the factory. Part of the "un-seal" process when the machine is first
booted is to change the bootable flag to the _next_ partition, which would
fail on servers ordered without an OS if there wasn't a second tiny FAT16
partition immediatly following. When this second partition is booted, it
shows the "NO OS INSTALLED -- please use the Dell CD's to install Linux
the way Dell wants it installed" (who does that?!?!?). You can find more
information on this process (as well as the new "Dell PC Restore" stuff)
at this site: <http://www.goodells.net/dellutility> ... I wanted to keep
only the DE partition, and delete the FAT16 partition.

if [ "`fdisk -l /dev/sda |grep FAT16`" ]
then
partid=`fdisk -l /dev/sda |grep FAT16 |cut -f1 -d' ' |cut -f2 -da`
echo -n "d
$partid
w" |fdisk /dev/sda
fi

This assumes you have a SCSI hard disk, use /dev/hda instead if IDE...
This checks to see if there is a FAT16 partition, and if so it gets the
partition ID (1-4) and pipes commands through the fdisk program to delete
it. This leaves the Dell Utility partition intact.

There may be other ways to do the same thing, but this is what I use...

Note that, for this to work, you must be careful using the "clearpart"
command in your KS.CFG. The "--initlabel" switch creates a brand new
partition table (for brand new hard disks), and the "--all" switch will
clear all partitions (both do the same thing -- remove the partition you
don't want removed).. On my system, I use the "--linux" switch, which
will delete only the Linux partitions, leaving my Dell Utility partition
alone.

Hope this helps,

-Matt-

Continue reading on narkive:
Loading...