[Top][All Lists]

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

Creating partitions relative to the end of the disk

From: Timshel Knoll
Subject: Creating partitions relative to the end of the disk
Date: Thu, 14 Mar 2002 00:28:35 +1100
User-agent: Mutt/1.3.27i


I've hacked command_line_get_sector to allow specifing partitions
relative to the end of the disk. If a value has a '-' sign in front of
it, it is treated as as being a distance from the end of the disk. (ie.
on a 3000MB disk, -60 will yield 2940 in real terms). The patch is
trivial, there shouldn't be anything wrong with it (although I haven't
tested it extensively, there shouldn't be anything that _can_ go wrong,
as the consistency checks happen after this modification is done ...)

An alternative syntax for this could be to implement an expression
parser in parted's code, and allow for pseudo-variables like "disk.end".
This way the user could specify things like:
"mkpart primary linux-swap disk.end - 128 disk.end"
to create a linux swap partition in the last 128MB of the disk. Hrm,
maybe this is a reason to write "tmsh" and integrate it as an embedded
scripting language within parted (variables, arithmetic, conditionals,
loops et al ...) ;-)

<begin parted "etmsh" (embedded tmsh) syntax>
# geometry is a "struct" with 2 fields, start and end
geometry root = { 0 128 }

if disk.size < 1000 {
   # disk too small to make lots of separate partitions, put /var on /
   root.end += disk.size / 8
   need_var = false

# Root/boot partition - root expands to "root.start root.end"
mkpartfs primary ext3 root

# Main extended partition takes up rest of disk
mkpartfs extended root.end disk.end

# Create swap partition with same size as machine memory
memsize = [sh 'awk '/^Mem:/ {print $2}' < /proc/meminfo]

# Swap - at end of extended partition
mkpartfs logical linux-swap (disk_end - memsize) disk_end

# Use half the remaining disk space for /usr (2/3 if no /var needed)
geometry usr var home
freespace = disk.blocks.free[1].size

usr.start = disk.blocks.free[1].start
if need_var {
   usr.end = usr.start + freespace / 2
   var = { usr.end (usr.end + freespace / 4) }
   home = { var.end disk.blocks.free[1].end }
} else {
   usr.end = usr.start + freespace / 2
   home.start = usr.end
   home.end = disk.blocks.free[1].end

mkpartfs logical ext3 usr
if need_var { mkpartfs logical ext3 var }
mkpartfs logical ext3 home

<end parted "etmsh" syntax> :-)

Maybe I need to start honing my lex/yacc skills :-)

Patch attached for the first feature, anyway.



   Timshel Knoll <address@hidden>  for Debian email: <address@hidden>
      Debian GNU/Linux developer, see http://people.debian.org/~timshel/
                For GnuPG public key: finger address@hidden

Attachment: parted-1.6.0-pre4-partitions-relative-to-end-of-disk.diff
Description: Text document

Attachment: pgpQ_uqA4zACJ.pgp
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]