Skip to content

Instantly share code, notes, and snippets.

@moso
Created October 27, 2016 13:47
Show Gist options
  • Save moso/70403e93cb50e06bc9b0a817bec5a2fc to your computer and use it in GitHub Desktop.
Save moso/70403e93cb50e06bc9b0a817bec5a2fc to your computer and use it in GitHub Desktop.

Create partition on empty drive

  • Start fdisk - change /dev/sda2 with your harddrive.
sudo fdisk /dev/sda
  • Select p to view all partitions.
  • Select n to create a new partition.
  • Type p for primary partition.
  • Enter which number partition the partition is on the harddrive. Typically 1.
  • If the partition needs to fill up all the space on the harddrive, just press enter at start sector and end sector.
  • Select w to write changes to the disk.
  • Reboot.
  • Make the filesystem with mkfs
sudo mkfs.ext4 /dev/sda2p1

Automagically mounting the new partition

  • Remember to create a mounting point, eg. /mnt/hdd.
  • Edit /etc/fstab
sudo nano /etc/fstab
  • Add a new mounting point at the bottom (new line)
  • Type in like below - partition, mounting point, partition type, flags, fs_freq, fs_passno
  • /dev/sda2p1 /mnt/hdd ext4 rw,defaults 0 0
  • Save and exit fstab
  • Test if the new mount works by mounting all from fstab
sudo mount -a
  • This shouldn't produce any errors, and this automatically mount the harddrive - even after reboot.

If you need to unmount the partition again:

sudo umount /mnt/hdd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment