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