RPi, resize filesystem & static IP and other quick mods

After logging in as root, I need to resize the partition to use the whole 8GB SD card. df tells me:

root@raspberrypi:/etc# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          1.8G  1.4G  339M  80% /
/dev/root       1.8G  1.4G  339M  80% /
tmpfs            19M  200K   19M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            37M     0   37M   0% /tmp
tmpfs            10M     0   10M   0% /dev
tmpfs            37M     0   37M   0% /run/shm
/dev/mmcblk0p1   56M   34M   23M  61% /boot

So, I’ve got the 2GB partition.

The RPi guys have a nice utility to do some of the basic config: raspi-config.


root@raspberrypi:/etc# raspi-config


So, just select the expand_rootfs option. You’ll see the following on the terminal:

Command (m for help):
Disk /dev/mmcblk0: 7822 MB, 7822376960 bytes
4 heads, 16 sectors/track, 238720 cylinders, total 15278080 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: 0x000714e9

 Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880     3788799     1832960   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 (2048-15278079, default 2048): Last sector, +sectors or +size{K,M,G} (122880-15278079, default 15278079): Using default value 15278079

Command (m for help):
Disk /dev/mmcblk0: 7822 MB, 7822376960 bytes
4 heads, 16 sectors/track, 238720 cylinders, total 15278080 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: 0x000714e9

 Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880    15278079     7577600   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: resize2fs_once start runlevel arguments (2 3 4 5) do not match LSB Default-Start values (2 3 4 5 S)
update-rc.d: warning: resize2fs_once stop runlevel arguments (0 1 6) do not match LSB Default-Stop values (none)
update-rc.d: using dependency based boot sequencing

*Important* It takes quite a bit of time on the next reboot to enlarge the FS. just let the RPi do its thing. It took mine about about 3-4 minutes to complete. During this time, you cannot ssh into the box, you’ll get connection refused. Unfortunately, the OK light doesn’t flash or anything to tell you it is doing something, it looks like it has rebooted, when it hasn’t finished. Since I’m running headless, I can’t see what console is printing out.

While, in the setup, also change the timezone (how can there be three entries for North Dakota and no Seattle, having to choose Los Angeles makes me feel kinda dirty). Also, run the update to update the raspi-config (my version went from 20120715 to 20120815 — maybe this version leaves sshd enabled, but i’m not going to chance it) and make sure to enable sshd again.

A long reboot later and df now says:

Filesystem      Size  Used Avail Use% Mounted on
rootfs          7.2G  1.4G  5.5G  20% /
/dev/root       7.2G  1.4G  5.5G  20% /
tmpfs            19M  196K   19M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            37M     0   37M   0% /tmp
tmpfs            10M     0   10M   0% /dev
tmpfs            37M     0   37M   0% /run/shm
/dev/mmcblk0p1   56M   34M   23M  61% /boot

much better.

Setting up a static IP

you need to edit the interfaces file to setup the static IP.

cd /etc/network
cp interfaces interfaces.dhcp // backup your original DHCP enabled file.
vi interfaces

mine shows:

auto lo

iface lo inet loopback
iface eth0 inet dhcp

and I changed it to:

auto lo

iface lo inet loopback
iface eth0 inet static
 address 192.168.1.101
 netmask 255.255.255.0
 network 192.168.1.0
 broadcast 192.168.1.255
 gateway 192.168.1.1

reboot and login via your new static IP.

Lower the number of virtual consoles and disable the serial console

RPi comes with six virtual consoles enabled which is a bit too many for me. I also wanted to disable the serial console so I can use the serial for connecting some peripheral devices. Wish it had two hardware serials on the breakout pins, so I could leave the serial console enabled, but can’t always get what you want.

vi /etc/inittab

comment out a few lines:

#4:23:respawn:/sbin/getty 38400 tty4
#5:23:respawn:/sbin/getty 38400 tty5
#6:23:respawn:/sbin/getty 38400 tty6

To lower the virtual terminals to 3

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

To stop the serial console.

kill -1 1

to restart the consoles.