Main Content

Expand the Root Partition in Kali Linux for the Raspberry Pi

By default when Kali Linux for the Rapsberry Pi is installed the file system will only expand to occupy 3GB of storage, in my case I have a 16GB Micro SD card in my Raspberry Pi 2 with most of its capacity unused. One can easily expand the file system by making use of a script that automatically does the job for you.

File system after install.

root@kali:~# df -h

Filesystem      Size  Used Avail Use% Mounted on
rootfs          2.9G  1.5G  1.2G  56% /
/dev/root       2.9G  1.5G  1.2G  56% /
devtmpfs        460M     0  460M   0% /dev
tmpfs            93M  468K   93M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           186M     0  186M   0% /run/shm

I should note I did not create the script and found it at the following address http://www.raspberryvi.org/wiki/doku.php/raspi-expand-rootfs but it has proven useful.

Download the script into the boot directory. Locally hosted.

root@kali:~# wget -O /boot/raspi-expand-rootfs.sh http://dl.linhost.info/file1/raspi-expand-rootfs.sh

Now we make the script executable.

root@kali:~# chmod +x /boot/raspi-expand-rootfs.sh

And execute the script. Don’t be scared by the output.

root@kali:~# sh /boot/raspi-expand-rootfs.sh
Command (m for help):
Disk /dev/mmcblk0: 15.9 GB, 15931539456 bytes
4 heads, 16 sectors/track, 486192 cylinders, total 31116288 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: 0x000697c0

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1               1      125000       62500    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          125001     6143999     3009499+  83  Linux

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

Command (m for help):
Disk /dev/mmcblk0: 15.9 GB, 15931539456 bytes
4 heads, 16 sectors/track, 486192 cylinders, total 31116288 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: 0x000697c0

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1               1      125000       62500    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          125001    31116287    15495643+  83  Linux

Command (m for help): 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.
update-rc.d: using dependency based boot sequencing
update-rc.d: warning: default start runlevel arguments (2 3 4 5) do not match resize2fs_once Default-Start values (2 3 4 5 S)
update-rc.d: warning: default stop runlevel arguments (0 1 6) do not match resize2fs_once Default-Stop values (none)
Root partition has been resized. The filesystem will be enlarged upon the next reboot

It is necessary to reboot the OS for the changes to take effect.

root@kali:~# reboot

Once again us the df command to verify the file system successfully expanded.

root@kali:~# df -h

Filesystem      Size  Used Avail Use% Mounted on
rootfs           15G  1.5G   13G  11% /
/dev/root        15G  1.5G   13G  11% /
devtmpfs        460M     0  460M   0% /dev
tmpfs            93M  468K   93M   1% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           186M     0  186M   0% /run/shm

If you like you can remove the script from the /boot directory.

root@kali:~# rm /boot/raspi-expand-rootfs.sh

Comments

  1. Commented on
    Comment by Mike

    Followed the instructions exactly…everything does as it should, then when I reboot the partition sizes are still the same.

    1. Commented on
      Comment by Tommy

      me too,I got “error value out of range”

      1. Commented on
        Comment by Gunter Pietzsch

        Hi,
        I’ve got the same error message but I found a workaround:
        Step 1: use fdisk – l to identify the start sector of partition 2 – in my case it was 125001
        Step 2: I’ve updated the script :

        n
        p
        2
        $PART_START

        p

        to

        n
        p
        2
        125001

        p

        Step 3: after saving my modification I’ve started the script and rebooted the system.

        1. Commented on
          Comment by frank

          Ty worked perfectly.

        2. Commented on
          Comment by John Freier

          Thanks @gunterpietzsch:disqus

  2. Commented on
    Comment by Paul

    It does work, you need to do a reboot and it should work!

  3. Commented on
    Comment by Erik Roest

    The host seems down: http://www.raspberryvi.org/wiki/doku.php/raspi-expand-rootfs

    However with special thanx to Lars Gierth, he has forked the the code on GitHub: https://raw.githubusercontent.com/lgierth/pimesh/master/files/raspi-expand-rootfs.sh

    Executed it and worked as charm!

    Thanks Luis!

  4. Commented on
    Comment by Gags

    Thank you very much. Worked perfectly for me!

  5. Commented on
    Comment by Tommy

    Value Out of Range Error:
    =========================================================
    root@kali:/boot# sh raspi-expand-rootfs.sh

    Welcome to fdisk (util-linux 2.25.2).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.

    Command (m for help): Disk /dev/mmcblk0: 14.9 GiB, 16021192704 bytes, 31291392 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
    Disklabel type: dos
    Disk identifier: 0x000ddd94

    Device Boot Start End Sectors Size Id Type
    /dev/mmcblk0p1 1 125000 125000 61M c W95 FAT32 (LBA)
    /dev/mmcblk0p2 125001 14335999 14210999 6.8G 83 Linux

    Command (m for help): Partition number (1,2, default 2):
    Partition 2 has been deleted.

    Command (m for help): Partition type
    p primary (1 primary, 0 extended, 3 free)
    e extended (container for logical partitions)
    Select (default p): Partition number (2-4, default 2): First sector (125001-31291391, default 126976): Value out of range.
    First
    sector (125001-31291391, default 126976): Last sector, +sectors or
    +size{K,M,G,T,P} (126976-31291391, default 31291391): Last sector,
    +sectors or +size{K,M,G,T,P} (126976-31291391, default 31291391): Last
    sector, +sectors or +size{K,M,G,T,P} (126976-31291391, default
    31291391):
    Do you really want to quit? Root partition has been resized. The filesystem will be enlarged upon the next reboot

    =========================================================

    What should I do to change the script and make it works? Please help

  6. Commented on
    Comment by asdffadsadfsfasd

    This script has to be run as root, not sudo. Or parted won’t run and you get out of range

  7. Commented on
    Comment by DedSecShadow

    i have the exact same issue but im running kali, how would i go about achieving the same result as i noticed the script specifies “raspi”

  8. Commented on
    Comment by H4x03D

    Dont works, value out of range

Comments are closed.