parted -h parted /dev/hda print
parted -h parted /dev/hda print
GNU Parted Can create, resize, copy and delete ext2, fat and linux-swap partitions. It automatically moves blocks and updates the file system and partition table.
It can resize both the start and end of FAT partitions, but only the end of ext2 partitions.
Download: ftp://ftp.gnu.org/gnu/parted/ (25390 hits)
Red Hat Packages: ftp://ftp.freshmeat.net/pub/rpms/parted/[] (7727 hits)
Debian Packages: http://packages.debian.org/unstable/admin/parted.html
Mirror List: http://www.gnu.org/prep/ftp.html (1007 hits)
Homepage: http://www.gnu.org/software/parted/ (45993 hits)
Changelog: ftp://ftp.gnu.org/gnu/parted/ChangeLog (3140 hits)
online tutorial is available at www.luv.asn.au/overheads/parted
rpm -qpiR parted-1.2.9-1rh62.i386.rpm rpm -ivv parted-1.2.9-1rh62.i386.rpm
# parted /dev/hda print Disk geometry for /dev/hda: 0-19547.2 megabytes Minor Start End Type Filesystem Flags 1 0.0 502.0 primary ext2 2 502.0 2502.3 primary ext2 3 2502.3 8291.4 primary FAT boot 4 8291.4 19540.0 extended 5 8291.4 16347.4 logical ext2 6 16347.4 19540.0 logical FAT boot
In the fourth column, we have the partition type. There are three types of partitions: primary, extended and logical. Primary partitions are normal partitions that contain file systems. In an ideal world, there would only be primary partitions. Unfortunately, there can only be up to four primary partitions.
The first column, with the heading "Minor" is the partition number. Since there are up to 4 primary partitions, Primary partitions are numbered 1-4, and logical partitions are numbered 5 onwards.
The second and third column give the start and end of the partitions. The unit is in cylinders (more on this later). The size of each cylinder is given above as
The last column is the flags. There are 2 flags: hidden - useful for hiding partitions from Windows - and boot. Boot is used by the DOS boot code to determine which partition to boot off. More on this later.
Because the boot-loaders don't have hard disk drivers, they have to use the BIOS's drivers. Unfortuantely, the BIOS drivers are seriously broken. The BIOS requires that everyone that speaks about regions on a disk talk in terms of "geometry". This geometry system uses three numbers: cylinder, head, sector (CHS for short), that don't bear any resemblance to reality in any way at all. For example, a disk with geometry 784/255/63 has 784 cylinders, with 255 heads per cylinder, and 63 sectors per head. This means each cylinder has 255*63 sectors
Anyway, this geometry system requires that each disk have a size, given in CHS. There is no (reliable) way for the operating system to find out this size, but the operating system, and the BIOS must agree on what it is, none the less.
There's also another problem that comes out of this BIOS geometry thing. There is a maximum of 1024 cylinders. This means that any partition involved in the boot process must start before cylinder number 1024.
The second half of the boot problem - understanding file systems - is easier to deal with. If you resize a Linux root file system, you need to re-run lilo, by typing /sbin/lilo.
umount /export.old/ # !!
(parted) print Disk geometry for /dev/hda: 0-19547.2 megabytes Minor Start End Type Filesystem Flags 1 0.0 502.0 primary ext2 2 502.0 2502.3 primary ext2 3 2502.3 8291.4 primary FAT boot 4 8291.4 19540.0 extended 5 8291.4 16347.4 logical ext2 6 16347.4 19540.0 logical FAT boot
(parted) mkfs 5 ext2 -- Erhh... no confirming question asked!
(parted) resize 5 8291.4 16347 (parted) print Disk geometry for /dev/hda: 0-19547.2 megabytes Minor Start End Type Filesystem Flags 1 0.0 502.0 primary ext2 2 502.0 2502.3 primary ext2 3 2502.3 8291.4 primary FAT boot 4 8291.4 19540.0 extended 5 8291.4 16347.4 logical ext2 6 16347.4 19540.0 logical FAT boot
Warning: The kernel was unable to re-read your partition table, so you need to reboot before mounting any modified partitions. You also need to reinstall your boot loader before you reboot (which may require mounting modified partitions). It is impossible do both things! So you'll need to boot off a rescue disk, and reinstall your boot loader from the rescue disk. Read section 2.2 of the Parted User documentation for more information.
The following show the info when I resized my ext3 partition. Note that the result is not good though. My resized Linux (RH7.3) was unable to boot any more.
# fdisk -l
Disk /dev/hda: 255 heads, 63 sectors, 3736 cylinders Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System /dev/hda1 1 2550 20482843+ 1c Hidden Win95 FAT32 (LBA) /dev/hda2 2551 2678 1028160 82 Linux swap /dev/hda3 * 2679 3736 8498385 83 Linux
(parted) print Disk geometry for /dev/hda: 0.000-29311.734 megabytes Disk label type: msdos Minor Start End Type Filesystem Flags 1 0.031 20002.807 primary FAT hidden, lba 2 20002.808 21006.870 primary linux-swap 3 21006.870 29306.074 primary ext3 boot
(parted) check 2 (parted) check 3 Information: The ext2 filesystem passed a basic check. For a more comprehensive check, use the e2fsck program.
(parted) resize 3 21006.870 23000
(parted) print Disk geometry for /dev/hda: 0.000-29311.734 megabytes Disk label type: msdos Minor Start End Type Filesystem Flags 1 0.031 20002.807 primary FAT hidden, lba 2 20002.808 21006.870 primary linux-swap 3 21006.870 22999.306 primary ext3 boot
# fdisk -l
Disk /dev/hda: 255 heads, 63 sectors, 3736 cylinders Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System /dev/hda1 1 2550 20482843+ 1c Hidden Win95 FAT32 (LBA) /dev/hda2 2551 2678 1028160 82 Linux swap /dev/hda3 * 2679 2932 2040255 83 Linux
(parted) mkpartfs primary ext3 22999.307 29306.074 No Implementation: Support for creating ext3 file systems is not implemented yet. (parted) mkpart primary 22999.307 29306.074 Error: Unknown file system type. (parted) mkpart primary ext2 22999.307 29306.074 (parted)
# fdisk -l
Disk /dev/hda: 255 heads, 63 sectors, 3736 cylinders Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System /dev/hda1 1 2550 20482843+ 1c Hidden Win95 FAT32 (LBA) /dev/hda2 2551 2678 1028160 82 Linux swap /dev/hda3 * 2679 2932 2040255 83 Linux /dev/hda4 2933 3736 6458130 83 Linux
# lilo Added linux * Added DOS
(parted) h check MINOR do a simple check on the filesystem cp [FROM-DEVICE] FROM-MINOR TO-MINOR copy filesystem to another partition help [COMMAND] prints general help, or help on COMMAND mklabel LABEL-TYPE create a new disklabel (partition table) mkfs MINOR FS-TYPE make a filesystem FS-TYPE on partititon MINOR mkpart PART-TYPE [FS-TYPE] START END make a partition mkpartfs PART-TYPE FS-TYPE START END make a partition with a filesystem move MINOR START [END] move partition MINOR name MINOR NAME name partition MINOR NAME print display the partition table quit exit program resize MINOR START END resize filesystem on partition MINOR rm MINOR delete partition MINOR select DEVICE choose the device to edit set MINOR FLAG STATE change a flag on partition MINOR
Newsgroups: comp.os.linux.misc Date: Thu, 26 Dec 2002 12:26:24 GMT
> I'm told I need to shrink one of my MDK partitions using the parted utility.
You can only shrink a partition if it's not mounted. If you want to shrink your / partition, you have to have a boot disk, a boot disk can be found at http://ftp.gnu.org/gnu/parted/bootdisk/
Newsgroups: comp.os.linux.redhat Date: 2002-04-21 10:09:15 PST
> Is it really possible to juggle the sizes of three ext3 partitions?
You'll need to convert the partitions back to ext2 before PartitionMagic will touch them.
The partitions have to be unmounted for the conversion, so its easiest to boot from a rescue CD/floppy. Then you convert a partition from ext3 to ext2 with:
tune2fs -O ^has_journal /dev/hdax e2fsck -f /dev/hdax
After PartitionMagic does its thing, boot the rescue CD/floppy again and convert the filesystems back to ext3:
tune2fs -j /dev/hdax e2fsck -f /dev/hdax
Ian Pilcher
Newsgroups: comp.os.linux.misc Date: 2001-12-03 18:09:57 PST
> But I wonder if PM can resize an ext2 partition ...
Well, it did it over here…
Enno
>>But I wonder if PM can resize an ext2 partition ... > > Linux Journal did an article on Partition Magic when V6.0 was released, > and their advice on re-sizing ext2 partitions went something like this; > > 1. Don't. > 2. If you insist, back up all of your data to a separate drive first. > 3. Don't complain to us if it doesn't work. See #1.
Weird. I've done dozens of ext2 resizings with PM, and the only time I ever had a problem was with a dead drive. The only reasons why I have discontinued using it are (1) I cannot boot from my Windoze partition for some reason and (2) I now use filesystems that aren't supported by PM (XFS, JFS, and ReiserFS).
Skylar Thompson
Date: Fri, 27 Sep 2002 22:35:23 GMT Newsgroups: comp.os.linux.setup
> My goal is to shrink the partion down that the LVM is > using (you can assume that it is not fully occupied) > so that another partition on the same disk can be > created. I want the PV that the VG is using to be > smaller.
i'll explain what i did just yesterday (i have done this before, but it's now still fresh in my mind). there is a step in this process that is not for the faint of heart :)
situation: a machine with one hard drive with a /boot, /, and /swap which collectively own the whole drive (suse 8) and want to check out the hoopla with mandrake 9 - need to steal about 3 gig from that reiserfs / partition.
where's that knoppix cd? ah, here it is … pop tray open, put knoppix in, slide door shut, and reset box. knoppix comes up and we double-check the existence of tools required: fdisk, reiserfsck, resize_reiserfs: all there. (knoppix is a cd- bootable Linux distro). time to take inventory:
root@ttyp0[sbin]# fdisk /dev/hda u <enter key> Changing display/entry units to sectors u <enter key> Changing display/entry units to cylinders p <enter key> Device Boot Start End Blocks Id System /dev/hda1 * 1 5 40131 83 Linux /dev/hda2 6 1222 9775552+ 5 Extended /dev/hda5 6 22 136521 82 Linux swap /dev/hda6 23 1223 9635994+ 83 Linux
okay, gotta think about this. resize filesystem, then check it out for any problems from resize, then resize the device. i get my notebook out and jot down the starting and ending cylinders for /dev/hda6. THIS IS IMPORTANT.
many people think of the filesystem and the partition device as a single integrated unit, but they arent. think of a bookshelf with adjustable shelves. you can move the leaf up or down and make more room for stuff (say books). think of the books as the filesystem. you can fill the shelf full of books to completely consume the shelf (or not). you can move the leaf to make more room and leave the filesystem alone. visual:
|<-- hda1------>|<-- hda2------>| +---------------+---------------+ |XXXXXXXXXXXXXXX|XXXXXXXXXX| | |XXXXXXXXXXXXXXX|XXXXXXXXXX| | +---------------+---------------+
the filesystem in device /dev/hda1 consumes the whole partition and the filesystem in /dev/hda2 consumes about 2/3 of the partition. okay, on to resizing that reiserfs filesystem in /dev/hda6:
root@ttyp0[sbin]# resize_reiserfs -s 6500M /dev/hda6 <-------------resize_reiserfs, 2002-------------> reiserfsprogs 3.6.3
You are running BETA version of reiserfs shrinker. This version is only for testing or VERY CAREFUL use. Backup of you data is recommended.
Do you want to continue? [y/N]:y Processing the tree: 0%....20%....40%....60%....80%....100%
left 0, 16081 /sec nodes processed (moved): int 524 (0), leaves 77315 (0), unfm 999654 (837), total 1077493 (837).
check for used blocks in truncated region ReiserFS report: blocksize 4096 block count 1664000 (2409742) free blocks 578246 (1323965) bitmap block count 51 (74) Syncing..done
check the filesystem itself and then take inventory again on the devices:
root@ttyp0[sbin]# reiserfsck —check —fix-fixable /dev/hda6 … blah blah blah …
okay, as discussed previously, we have a filesystem that has been shrunk, but the device itself is still the same size as it has always been (we've taken some books off the shelf, but the leaf itself is still in its original place).
now comes the scary part: most people would cringe at the thought, but dont worry, it should go without a hitch. you have to start up fdisk for the drive: here it is /dev/hda
root@ttyp0[sbin]# fdisk /dev/hda u <enter key> Changing display/entry units to sectors u <enter key> Changing display/entry units to cylinders p <enter key> Device Boot Start End Blocks Id System /dev/hda1 * 1 5 40131 83 Linux /dev/hda2 6 1222 9775552+ 5 Extended /dev/hda5 6 22 136521 82 Linux swap /dev/hda6 23 1223 9635994+ 83 Linux
Command (m for help): d <================delete partiton Partition number (1-6): 6 <enter key> Command (m for help): n <enter key> <======new partition (create) Command action l logical (5 or over) p primary partition (1-4) 'l' <enter key> First cylinder (23-1222, default 23): 23 Last cylinder or +size or +sizeM or +sizeK: +6650M <enter key> p <enter key> Device Boot Start End Blocks Id System /dev/hda1 * 1 5 40131 83 Linux /dev/hda2 6 1222 9775552+ 5 Extended /dev/hda5 6 22 136521 82 Linux swap /dev/hda6 23 851 6656000+ 83 Linux w <enter key> <=======================write table out root@ttyp0[sbin]#
okay, now my partition device has been reduced to the size of the filesystem (with a little bit of extra room - calculated on paper :). i shutdown knoppix and reboot back into suse …. everything is just fine and dandy. eventually, the disk looks like this after i've installed mandrake 9:
Device Boot Start End Blocks Id System /dev/hda1 * 1 5 40131 83 Linux /dev/hda2 6 1223 9775552+ 5 Extended /dev/hda5 6 22 136521 82 Linux swap /dev/hda6 23 851 6656000+ 83 Linux /dev/hda7 852 854 24066 83 Linux /dev/hda8 855 1222 2955928+ 83 Linux
enjoy!
Michael J. Tobler
Newsgroups: linux.redhat.install Date: 2001-12-20 23:39:02 PST
> > I was recently using Partition Magic 7.0 on a site, when I noticed > > that after an EXT2 partition was converted to EXT3, Partition Magic 7.0 > > now reports the partition as "full" even though it is not!?! Any ideas on > > this? > > > > This made it impossible to resize / move the partition, after we > > EXT3ed it. I am wondering if putting back to EXT2 (somehow? I dont know > > how though), would allow us to resize / move, and then we could re-EXT3 > > it, no? > > > debugfs will restore it to ext2
You need e2fsprogs-1.17 or later. /dev/hda5 is the ext3 partition we want to convert back to ext2
root# debugfs debugfs 1.23, 15-Aug-2001 for EXT2 FS 0.5b, 95/08/09 debugfs: open -f -w /dev/hda5 debugfs: features Filesystem features: has_journal filetype sparse_super debugfs: features -has_journal -needs_recovery Filesystem features: filetype sparse_super debugfs: quit root#
You'll probably get a warning the first time you reboot.
Dennis
> > You need e2fsprogs-1.17 or later. > > Does this package come with RH 7.2?
e2fsprogs-1.23-2.i386.rpm comes with 7.2
tune2fs -v will you tell which version is installed
> After doing this, your saying it will make the partition appear as EXT2 to > PM7.0 so I can resize it?
Should be able to, but I don't use PM7.0
> Dont I need to also remove the journal somehow?
I still have the journal because I only changed 2 partitions, which I use in both 7.2 and 6.1.