Friday, November 14, 2014

Resize root partition on Raspberry Pi

You have 8GB SD card for your Pi, however some images that you install to your Pi is just for 2GB, 4GB SD card. Therefor you could not use the left capacity of you SD card. In my case I have 2GB SD card on 1GB image.

To utilizes this, you must re-size the root partition and this is how to do that.
Log in to your Pi via SSH:
root@raspberry-pi:~# fdisk -l

Disk /dev/mmcblk0: 1967 MB, 1967128576 bytes
4 heads, 16 sectors/track, 60032 cylinders, total 3842048 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00027aa3

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            2048      104447       51200    b  W95 FAT32
/dev/mmcblk0p2          104448     1742847      819200   83  Linux
/dev/mmcblk0p3         1742848     1945599      101376   82  Linux swap / Solaris


You have 3 partitions on SD card. First one for /boot (don't touch this), second one is / and left one for swap. We are going to delete second and third then re-size it:
root@raspberry-pi:~# fdisk /dev/mmcblk0

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

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

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (104448-3842047, default 104448): 
Using default value 104448
Last sector, +sectors or +size{K,M,G} (104448-3842047, default 3842047): 
Using default value 3842047

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 or after you run partprobe(8) or kpartx(8)
Syncing disks.

Then reboot your Pi
root@raspberry-pi:~# reboot

Login again and re-size / partition
root@raspberry-pi:~# resize2fs /dev/mmcblk0p2
resize2fs 1.42.5 (29-Jul-2012)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1

The filesystem on /dev/mmcblk0p2 is now 467200 blocks long.


root@raspberry-pi:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          1.8G  634M  1.2G  36% /
/dev/root       1.8G  634M  1.2G  36% /
devtmpfs        215M     0  215M   0% /dev
tmpfs            44M  188K   44M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            88M     0   88M   0% /run/shm
/dev/mmcblk0p1   50M   19M   31M  38% /boot

No comments:

Post a Comment