🌑

Linhost.info

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.

1
2
3
4
5
6
7
8
9
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.

1
wget -O /boot/raspi-expand-rootfs.sh http://dl.linhost.info/file1/raspi-expand-rootfs.sh

Now we make the script executable.

1
chmod +x /boot/raspi-expand-rootfs.sh

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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.

1
reboot

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

1
2
3
4
5
6
7
8
9
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.

1
rm /boot/raspi-expand-rootfs.sh

— May 4, 2015