Open Source Library (UK)

Sunday, April 30, 2006

repartitioning your system live / adding new partitions

thanks to http://www.namesys.com/shrink_reiserfs.html and http://www.redhat.com/docs/manuals/linux/RHL-8.0-Manual/custom-guide/s1-swap-adding.html

well, after my hard drive finished acting weird and made me re-install linux, in my haste to get the job done I somehow managed to overlook swap space (i don't know how) and for some reason the debian installer didn't warn me (every other distro i have used has gone "hold up dude, yer screwing up here")!

anyways, i looked into making the necessary changes on the live install with minimal disruption to the service provided by the server (it's the sole gateway to the internet for all my users) and after I made the changes I thought it would make a really good section for this blog, just in case i need it again.

this will just be a copy and paste exercise from the websites mentioned:

Shrinking reiserfs partition HOW-TO

(live example)

Preliminaries

The reiserfs filesystem has a tool for changing its size. Extending of a reiserfs volume can be done if the fs is mounted as well as for not mounted fs. Fs shrinking is supported only when fs is unmounted.

0. Before any change of the disk partition table

First of all you need to backup partition table into a file. If you make a mistake you can re-create partitions at their initial correct places.

[root@haron root]# fdisk -l -u /dev/hda > hda.table.save
[root@haron root]# cat hda.table.save


Disk /dev/hda: 80.0 GB, 80032038912 bytes
255 heads, 63 sectors/track, 9730 cylinders, total 156312576 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System
Device Boot Start End Blocks Id System
/dev/hda1 * 63 122881184 61440561 83 Linux
/dev/hda2 122881185 151557209 14338012+ 83 Linux
/dev/hda4 151557210 156312449 2377620 82 Linux swap
[root@haron root]#

1. Here we start

[root@haron root]# df -T /mnt/testfs/
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/hda2 reiserfs 14337568 2143672 12193896 15% /mnt/testfs
[root@haron root]#

2. umount the fs and shrink it by 10G (for dirs like /opt, reboot into recovery mode)

further, -s-10G = "shrink by 10GB (100GB - 10GB = 90GB)" and -s+10G = "grow by 10GB (100GB + 10GB = 110GB)"

[root@haron root]# umount /mnt/testfs/

[root@haron root]# resize_reiserfs -s-10G -f /dev/hda2
resize_reiserfs 3.6.11 (2003 www.namesys.com)

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, 65963 /sec

nodes processed (moved):
int 100 (0),
leaves 15493 (0),
unfm 512116 (0),
total 527709 (0).

check for used blocks in truncated region

ReiserFS report:
blocksize 4096
block count 963063 (3584503)
free blocks 427114 (3048474)
bitmap block count 30 (110)

Syncing..done


resize_reiserfs: Resizing finished successfully.

3. find the fs new size

The new fs size is in resize_reiserfs final report: it said that block count now is 963063. Another way to determine fs size is to run debugreiserfs(8)
[root@haron root]# debugreiserfs /dev/hda2
debugreiserfs 3.6.11 (2003 www.namesys.com)


Filesystem state: consistent

Reiserfs super block in block 16 on 0x302 of format 3.6 with standard journal
Count of blocks on the device: 963063
Number of bitmaps: 30
Blocksize: 4096
Free blocks (count of blocks - used [journal, bitmaps, data, reserved] blocks): 427114
Root block: 8674
Filesystem is cleanly umounted
Tree height: 4
Hash function used to sort names: "r5"
Objectid map size 2, max 972
Journal parameters:
Device [0x0]
Magic [0x60aa06b]
Size 8193 blocks (including 1 for journal header) (first block 18)
Max transaction length 1024 blocks
Max batch size 900 blocks
Max commit age 30
Blocks reserved by journal: 0
Fs state field: 0x0:
sb_version: 2
inode generation number: 0
UUID: 467aea6f-16a8-445c-9f3b-7c8ef590894e
LABEL:
Set flags in SB:
ATTRIBUTES CLEAN
The number "Count of blocks on the device" indeed is number of blocks in the fs.

4. resizing underlying disk partition by fdisk(8) (size info is step 5)

for this section, precision is essential so if the original start sector is diff to the new one fdisk provides, use the original instead of the new

[root@haron root]# fdisk /dev/hda
First, we ask fdisk to show partition boundaries in sectors, not in blocks, because we need maximum precision there.
Command (m for help): u
Changing display/entry units to sectors

Command (m for help): p

Disk /dev/hda: 80.0 GB, 80032038912 bytes
255 heads, 63 sectors/track, 9730 cylinders, total 156312576 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 63 122881184 61440561 83 Linux
/dev/hda2 122881185 151557209 14338012+ 83 Linux
/dev/hda4 151557210 156312449 2377620 82 Linux swap
Then we delete partition #2 ...
Command (m for help):d
Partition number (1-4): 2
Command (m for help): p

Disk /dev/hda: 80.0 GB, 80032038912 bytes
255 heads, 63 sectors/track, 9730 cylinders, total 156312576 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 63 122881184 61440561 83 Linux
/dev/hda4 151557210 156312449 2377620 82 Linux swap
... and create new one with same start offset and the new size.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First sector (122881185-156312575, default 122881185):
Using default value 122881185
Last sector or +size or +sizeM or +sizeK (122881185-151557209, default 151557209): 130585688

number 130585688 is calculated as ( 122881185 (hda2 start) + 963063 (fs size in 4k blocks) * 8 (sectors per 4k block) - 1) by bc -l:
$ bc -l
bc 1.06
122881185 + 963063 * 8 - 1
130585688

add free space for another one partition
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 3
First sector (130585689-156312575, default 130585689):
Using default value 130585689
Last sector or +size or +sizeM or +sizeK (130585689-151557209, default 151557209):
Using default value 151557209

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@haron root]# reboot

Broadcast message from root (pts/0) (Mon Dec 8 21:11:03 2003):

The system is going down for reboot NOW!

5. Check result fs by reiserfsck(8)

[root@haron root]# echo Yes | reiserfsck /dev/hda2
reiserfsck 3.6.11 (2003 www.namesys.com)

*************************************************************
** If you are using the latest reiserfsprogs and it fails **
** please email bug reports to reiserfs-list@namesys.com, **
** providing as much information as possible -- your **
** hardware, kernel, patches, settings, all reiserfsck **
** messages (including version), the reiserfsck logfile, **
** check the syslog file for any related information. **
** If you would like advice on using this program, support **
** is available for $25 at www.namesys.com/support.html. **
*************************************************************

Will read-only check consistency of the filesystem on /dev/hda2
Will put log info to 'stdout'

Do you want to run this program?[N/Yes] (note need to type Yes if you do):###########
reiserfsck --check started at Mon Dec 8 21:14:56 2003
###########
Replaying journal..
0 transactions replayed
Checking internal tree..finished
Comparing bitmaps..finished
Checking Semantic tree:
finished
No corruptions found
There are on the filesystem:
Leaves 15493
Internal nodes 100
Directories 5733
Other files 67471
Data block pointers 512124 (8 of them are zero)
Safe links 0
###########
reiserfsck finished at Mon Dec 8 21:15:16 2003
###########
Reiserfsck reports that everything is OK.


Adding Swap Space
with the partition shrunk, create a new swap partition as follows:

fdisk /dev/hda

n (new partition)

p (primary partition

+1000M (1GB sized swap)

t

82

w


all done!
mkswap /dev/hdb2
To enable the swap partition immediately, type the following command:

swapon /dev/hdb2
To enable it at boot time, edit /etc/fstab to include:

/dev/hdb2 swap swap defaults 0 0
The next time the system boots, it will enable the new swap partition.

After adding the new swap partition and enabling it, make sure it is enabled by using the command free.

0 Comments:

Post a Comment

<< Home