16

I have seen instructions for resizing the partition here, but how do I create a whole new partition using the remaining space, and then mount it?

David Sykes
  • 1,395
  • 3
  • 18
  • 28

1 Answers1

14

Using fdisk:

fdisk /dev/sda

Type n to create a new partition.

Type p to make a primary partition.

Next press enter when prompted for a partition number to choose the next available.

Press enter again to pick the next available sector to start the partition. Press enter again to use all of the remaining disk space.

Type w to save the changes.

Fdisk will now exit. You am need to reboot in order for the partition to be available.

You can now make a file system for the new partition using the mkfs command.

mkfs.ext4 /dev/sdax

Where x is the partition number.

Note: sometimes when creating a new partition for the sd card there has been a small amount of logical space that takes up the rest of the image. You'll need to use the method in the question you linked to in order to extend that space, or do as I do and just create another partition after it.

To mount you use the mount command like this:

mount /dev/sdax /path/to/mount/point

If you want the partition to mount automatically at boot then you need to add an entry in the /etc/fstab file.

/dev/sdax      /path/to/mount    defaults      1 0
Jivings
  • 22,208
  • 11
  • 88
  • 138
  • 2
    On my Pi (Debian squeeze) /dev/sda was /dev/mmcblk0 and x was px, e.g. /dev/mmcblk0p4 – David Sykes Jun 24 '12 at 17:55
  • That seems to be standard for the RPi distributions for some reason. – Jivings Jun 24 '12 at 18:09
  • 1
    Ok, the default partitions are created with 16 cylinder gaps. If I accept the first default it creates a 1mb partition in one of the gaps. If I specify the end plus 16 (assuming the gaps are for a reason) then the second default is the end of the unused 2gb. Success, thx – David Sykes Jun 24 '12 at 19:59
  • I would mount with "defaults,noatime" since it's on an SD card – Paolo Jul 07 '12 at 20:27
  • I found the following entry in fstab file worked for me: /dev/mmcblk0p4 /mnt/data auto defaults 0 0 http://wiki.debian.org/fstab – David Sykes Jul 08 '12 at 12:30
  • 1
    @DavidSykes You should mount with `noatime` as well. [This question](http://raspberrypi.stackexchange.com/questions/169/how-can-i-extend-the-life-of-my-sd-card) will explain why. – Jivings Jul 08 '12 at 15:41
  • `fdisk: cannot open /dev/sda: No such file or directory` – user2924019 May 28 '18 at 12:37
  • @user2924019 see the first comment – Jivings May 30 '18 at 10:25