Shrink a Partition:
Here i will explain how a single partition 80G disk has been broken into 50 / 1 / 29
$ sudo fdisk /dev/sda
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/sda: 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/sda1 1 9729 78148161 83 Linux
$ sudo fdisk /dev/sda
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/sda: 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/sda1 1 9729 78148161 83 Linux
$ sudo resize2fs /dev/sda1 49G
resize2fs 1.41.4 (27-Jan-2009)
Resizing the filesystem on /dev/sda1 to 12845056 (4k) blocks.
The filesystem on /dev/sda1 is now 12845056 blocks long.
Use CFDISK to
- delete the partition (with size 80G)
- re-create a new partition with sizes 52G
$ sudo cfdisk /dev/sda
Use resize2fs on the new partition
$ sudo resize2fs /dev/sda1
resize2fs 1.41.4 (27-Jan-2009)
Resizing the filesystem on /dev/sda1 to 12695358 (4k) blocks.
The filesystem on /dev/sda1 is now 12695358 blocks long.
NOTE: If partition size is lesser than filesystem size then you will see an error as shown below. Use cfdisk and recreate the partition.
$ sudo resize2fs /dev/sda1
resize2fs 1.41.4 (27-Jan-2009)
Resizing the filesystem on /dev/sda1 to 12450367 (4k) blocks.
resize2fs: Can't read an block bitmap while trying to resize /dev/sda1
mount and the new partition to confirm data exists
$ sudo mount /dev/sda1 /media/
$ cd /media/
$ ls
lost+found www
$ ls -alrt
total 16
drwxr-xr-x 4 root root 4096 Dec 26 08:28 .
drwxrwxrwx 3 www-data www-data 4096 Dec 26 08:33 www
drwxrwxr-x 21 root root 4096 Dec 26 08:38 ..
drwx------ 2 root root 4096 Dec 26 11:52 lost+found
$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mmcblk0p1 1889792 894844 898952 50% /
tmpfs 256648 0 256648 0% /lib/init/rw
varrun 256648 284 256364 1% /var/run
varlock 256648 0 256648 0% /var/lock
udev 256648 120 256528 1% /dev
tmpfs 256648 0 256648 0% /dev/shm
tmpfs 256648 26592 230056 11% /var/cache/apt
/dev/sda1 49983444 240488 47203888 1% /media
No comments:
Post a Comment