vimwiki

Manage Linux drive

 Be carefull when working on drive  When a storage device is plugged, it appear as its own file in /dev/deviceName

See the device connected and partition with lsblk or sudo fdisk -l.
The device have standard name like so:

Drive: sd(a|b|c…), ex: sde Partition: sd(a|b|c…)(1|2|3…) ex: sde4 Tips: run those cmd before and after connecting a device to easily see which one it is.

sde <- devicedisk ├─sde1 <- partition 1 └─sde2 <- partition 2

Target either a entire drive or a partition with their respective name:


ls -l /dev/sde

ls -l /dev/sde4

Using fdisk

In terminal, enter sudo fdisk /dev/sde

key action
m help
p print drive info
n create new partition

Create a partition with fdisk

  1. sudo fdisk /dev/sde
  2. type p to print info on the disk and see if there is partition already existing
  3. press n to create a new partition
  4. select the number, for example 1 would give sde4
  5. for first sector, press enter unless you have reason to change it
  6. for last sector, either press enter to take the whole disk or specify a last to give it a certain amount of space. (type +100G for a 100gb partition, can be used with K,B,M,G…)
  7. press w to write the change (!! if the change are overwriting data, it take effect once this step is entered)

The partition should be created. But not mounted nor formatted so not usable. (keep reading)

Format partition with mkfs

  1. sudo mkfs.<filesystem> /dev/sde4

    ex for Linux sudo mkfs.ext4 /dev/sde4

Mount a drive or partition manually

Assign a given location to access a drive. Mount either in:

  1. Open a terminal
  2. Make a dir for mounting the drive, for exemple: sudo mkdir /mnt/disk1
  3. Find the disk or partition with lsblk
  4. Mount it: sudo mount /dev/sde4 /mnt/disk1

Unmount a drive or partition

Use umount and the location where the drive/partition is mounted.
it is umount and not unmount, no n after the u.

sudo umount /mnt/disk1

Mount a drive automatically

 Be extra carefull with fstab 

/etc/fstab is a file used by the Linux system to automatically mount drive at startup.
It is best to separate your entry lines from the one already existing with a line break.

To mount a partition add this line: