Category Archives: partition

Manually Resize SD card on Slackware using Parted

This article is similar to this article, except it use parted to partitioning.

When write image to CD card for installation of Raspberry Pi, the usable size will only be the size of the image. That means the rest of the space will be waste. On some distribution such as Fedora Remix or Raspbian Wheezy, when final configuration begin the distro run some script to automatically resize and fill the SD card. However not all distro does that. Therefore we need to do manual resize.

In this article we will discuss about how to manually resize SD card on Slackware. Alhtough using Slackware, you can also use other Linux, but we won’t cover that. This article describes activities relating partitions. Incorrectly following instruction is likely to corrupt your system, so please be careful.

On this article I use:

  1. Slackware64 14.0
  2. SD card with Raspbian Wheezy (2GB occupied)

Yes, we will resize Raspbian manually even though we know Raspbian can resize SD card automatically on raspi-config.

Preparation

Insert the SD card to our machine. Make sure it is now mounted. We will use partition tool to resize the partition.

Following on from the instructions above, keep the newly-written SD card in the card reader, but unmounted. We’ll use the parted (partition editor) tool to resize the partitions.

Show partition information to find our SD card. Look for a partition that matches the roughly the size of your distribution image. On Debian Wheezy it should be around 2GB. For example, it is detected as /dev/sdc2. Then unmount that partition. Those can be done by invoking:

mount
umount /dev/sdc2

Resizing

Now use parted utility (GNU Parted) with root privileges. You can do sudo if you are on sudoer group or use super user account.

parted /dev/sdc
(parted) unit chs
(parted) print
Disk /dev/sdc: 121535,3,31
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 121536,4,32.  Each cylinder is 65.5kB.
Partition Table: msdos

Number  Start      End         Type     File system     Flags
 1      16,0,0     1215,3,31   primary  fat32           lba
 2      1232,0,0   26671,3,31  primary  ext4
 3      26688,0,0  29743,3,31  primary  linux-swap(v1)

This shows how my SD card was formatted after writing the image. Notice that nothing uses the card from end of ‘cylinder’ 29743 to the card’s maximum at 121535.

Partition 1 is the boot partition. Nothing to do here, let’s leave that alone. Partition 2 is the root partition, which we’ll grow to fill most of the card. Some OS versions will have a Partition 3 for swap space, which needs to be moved to the end of the card. Note that on some other versions of linux partitioning swap before primary filesystem. Well, if that’s the case, our task will be easier.

Move the swap partition if it exists (you’ll have to adjust the numbers so that the end of partition 3 is at the end cylinder/head/sector of the card). To calculate the number to use in the following formula can be used:

Partition 3 New Start = (Maximum - (Partition 3 End - Partition 3 Start) ) - 1

so in this example (121535 - ( 29743 - 26688)) -1 = 118479

Note: Following command will not work if your parted versions later than 2.4. On my machine, parted is at version 3.1

(parted) move 3 118479,0,0

Now grow the root partition. This involves removing the partition, re-creating it, then using resize2fs to grow the filesystem to fill the partition. It won’t destroy any data.

(parted) rm 2
(parted) mkpart primary 1232,0,0 118478,3,31
(parted) quit

Note that the starting address of the new partition is identical to its original value, and the ending address is immediately before the start of the swap partition.
Now clean and resize the root partition.

e2fsck -f /dev/sdc2

That command will allow it to add lost-and-found.

resize2fs /dev/sdc2

Then put the card in the RPi and boot. You end up with a 7Gb partition to use.

pi@raspberrypi:~$ df -h
Filesystem            Size  Used Avail Use% Mounted on
tmpfs                  94M  4.0K   94M   1% /lib/init/rw
udev                   10M  168K  9.9M   2% /dev
tmpfs                  94M     0   94M   0% /dev/shm
rootfs                7.1G  1.3G  5.4G  20% /
/dev/mmcblk0p1         75M   28M   48M  37% /boot

And that’s it, we can enjoy Raspberry again ?

The post Manually Resize SD card on Slackware using Parted appeared first on Xathrya.ID.