Skip to content

Manage disks and partitions under Linux

Display existing partitions and identify existing disks.

sudo fdisk -l

or you can use

lsblk -o NAME,FSTYPE,UUID

You can also use mount directly

mount # if you have a lot of devices you can use: mount | grep /dev/

How-to create a partition

You need to identify attach device (using fdisk)

sudo fdisk /dev/sdX
  • Press O and press Enter (creates a new table)
  • Press N and press Enter (creates a new partition)
  • Press P and press Enter (makes a primary partition)
  • Then press 1 and press Enter (creates it as the 1st partition)
  • Finally, press W (this will write any changes to disk)

Check result and identify the new partition id, it should be /dev/sdX1

sudo fdisk -l

Okay now you have a partition, now you need a filesystem.

Let say we want to use ext4

sudo mkfs.ext4 /dev/sdX1

Now you can add it to fstab

How-to make partitions mount at startup

You need to add it to /etc/fstab, before you probably want to backup your current file.

sudo cp /etc/fstab /etc/fstab.old

Get the UUID of the partition you want to auto-mount.

blkid # With old version you might need to use: sudo blkid

Typical result is

/dev/sda1: UUID="4a00874d-aaca-4712-80dd-0ba4aa0db401" TYPE="ext4" PARTUUID="2ec0b083-01"
/dev/sdb1: UUID="a0d6d979-8dd1-4443-80d4-2aa6a46eb99b" TYPE="ext2" PARTUUID="1e932d0e-01"
/dev/sdb5: UUID="jfZqhq-OMgo-Abx8-QgES-65XD-wj2w-labjeF" TYPE="LVM2_member" PARTUUID="1e932d0e-05"
/dev/mapper/mint--vg-root: UUID="9f6df998-4521-829f-9404-138cb12efccd" TYPE="ext4"

Copy the following line to the end of the file /etc/fstab save it and reboot afterwards to check if it worked.

sudo nano /etc/fstab # if you prefer xed or gedit use: xed admin:///etc/fstab

Typical fstab content

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/mint--vg-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda1 during installation
UUID=a0d6d979-8dd1-4443-80d4-2aa6a46eb99b /boot           ext2    defaults        0       2
/dev/mapper/mint--vg-swap_1 none            swap    sw              0       0

Then you need to add an entry to handle new partition

Sample

UUID=4a70084d-aaca-4712-80dd-0ba4aa0db401   /mnt/data  ext4    errors=remount-ro 0       2

Customize with your UUID and your mount point.

Save, create an empty folder corresponding to the mount point.

sudo mkdir /mnt/data

You can test using

sudo mount -a

Then verify content of your mount point

ls -lF /mnt/data/

You should have a lost+found folder there:

drwx------ 2 root root 16384 Jun 14 13:38 lost+found/

If you plan to use this disk for your users homes have a look to User management section.

References