Resizing Linux Partitions

From KoshWiki

Jump to: navigation, search

Origin

This is an extension of the article Resizing ext3 Drives as it is mostly standalone and is fairly large.

This assumes you have just resized the volume using resize2fs, but you can read around that.

Resizing the Partition

Here comes the dangerous part, The usual "backup" yada here.

debian:~# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda1             35581024    390732  33720916   2% /
tmpfs                   242144         0    242144   0% /dev/shm

The Partition is still full size though.

debian:~# fdisk /dev/hda

Command (m for help): p

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1        9553    76734441   83  Linux
/dev/hda2            9554        9729     1413720    f  W95 Ext'd (LBA)
/dev/hda5            9554        9729     1413688+  82  Linux swap / Solaris

Here comes the fun part.

Install a nice tool called "disktype"

debian:~# apt-get install disktype
Reading Package Lists... Done
Building Dependency Tree... Done
The following NEW packages will be installed:
  disktype
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 33.9kB of archives.
After unpacking 90.1kB of additional disk space will be used.
Get:1 http://ftp.au.debian.org stable/main disktype 7-2 [33.9kB]
Fetched 33.9kB in 0s (39.5kB/s)
Selecting previously deselected package disktype.
(Reading database ... 20105 files and directories currently installed.)
Unpacking disktype (from .../archives/disktype_7-2_i386.deb) ...
Setting up disktype (7-2) ...

and run it

debian:~# disktype /dev/hda

--- /dev/hda
Block device, size 74.53 GiB (80026361856 bytes)
GRUB boot code, compat version 3.2, boot drive 0xff
DOS partition map
Partition 1: 73.18 GiB (78576067584 bytes, 153468882 sectors from 63, bootable)
  Type 0x83 (Linux)
  Ext3 file system
    Volume name "/"
    UUID F8AAFD5B-70D8-429E-8C93-76E9D2FEF016 (DCE, v4)
    Volume size 35.03 GiB (37616066560 bytes, 9183610 blocks of 4 KiB)
Partition 2: 1.348 GiB (1447649280 bytes, 2827440 sectors from 153468945)
  Type 0x0F (Win95 Ext'd (LBA))
  Partition 5: 1.348 GiB (1447617024 bytes, 2827377 sectors from 153468945+63)
    Type 0x82 (Linux swap / Solaris)
    Linux swap, version 2, subversion 1, 4 KiB pages, little-endian
      Swap size 1.348 GiB (1447608320 bytes, 353420 pages of 4 KiB)

Here is where my math gets bad.

Volume is 37616066560 bytes Partition is 78576067584 bytes

So in fdisk 76734441 blocks = ( <volume size> 78576067584 / <1 kb> 1024) In theory then, (37616066560 / 1024) = block size so +36734440K should be right.

I'll find out after reboot.

debian:~# fdisk /dev/hda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1        9553    76734441   83  Linux
/dev/hda2            9554        9729     1413720    f  W95 Ext'd (LBA)
/dev/hda5            9554        9729     1413688+  82  Linux swap / Solaris

Command (m for help): d
Partition number (1-5): 1

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-9729, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-9553, default 9553): +36734440K

Command (m for help): p

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1        4574    36740623+  83  Linux
/dev/hda2            9554        9729     1413720    f  W95 Ext'd (LBA)
/dev/hda5            9554        9729     1413688+  82  Linux swap / Solaris

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.
debian:~#

And because we are asked to nicely

debian:~# shutdown -r now

Broadcast message from root (pts/0) (Thu Jun  8 08:34:45 2006):

The system is going down for reboot NOW!
debian:~#

Rebooted fine, (Removed fdisk warning for slight breverity)

debian:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1              34G  382M   33G   2% /
tmpfs                 237M     0  237M   0% /dev/shm
debian:~# fdisk /dev/hda

Command (m for help): p

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1        4574    36740623+  83  Linux
/dev/hda2            9554        9729     1413720    f  W95 Ext'd (LBA)
/dev/hda5            9554        9729     1413688+  82  Linux swap / Solaris

Command (m for help): q

debian:~# e2fsck /dev/hda1
e2fsck 1.37 (21-Mar-2005)
/dev/hda1 is mounted.

WARNING!!!  Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.

Do you really want to continue (y/n)? yes

/: recovering journal
/: clean, 26606/9207808 files, 386096/9183610 blocks
debian:~# e2fsck /dev/hda1
e2fsck 1.37 (21-Mar-2005)
/dev/hda1 is mounted.

WARNING!!!  Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.

Do you really want to continue (y/n)? yes

/: clean, 26606/9207808 files, 386096/9183610 blocks
debian:~#

References

Personal tools