|
| 1 | +# Mounting external drives |
| 2 | + |
| 3 | +To list all drives run: |
| 4 | + |
| 5 | +``` |
| 6 | +$ lsblk |
| 7 | +``` |
| 8 | + |
| 9 | +## Mount and unmount external drives |
| 10 | + |
| 11 | +One common need is to mount an external drive, be it an external hard drive, USB stick, or an external SSD. |
| 12 | + |
| 13 | +Create a new mount point, and mount the drive there: |
| 14 | + |
| 15 | +``` |
| 16 | +$ sudo mkdir /mnt/externaldrive |
| 17 | +$ sudo mount /dev/sda1 /mnt/externaldrive |
| 18 | +``` |
| 19 | + |
| 20 | +To unmount: |
| 21 | + |
| 22 | +``` |
| 23 | +$ sudo umount /mnt/externaldrive |
| 24 | +``` |
| 25 | + |
| 26 | + |
| 27 | +## Add a new internal drive |
| 28 | + |
| 29 | +### 1) List all drives: |
| 30 | + |
| 31 | +``` |
| 32 | +$ lsblk |
| 33 | +``` |
| 34 | + |
| 35 | +This will output something like this: |
| 36 | + |
| 37 | +``` |
| 38 | +nvme0n1 259:0 0 953.9G 0 disk |
| 39 | +nvme1n1 259:1 0 931.5G 0 disk |
| 40 | +├─nvme1n1p1 259:2 0 1G 0 part /boot/efi |
| 41 | +├─nvme1n1p2 259:3 0 2G 0 part /boot |
| 42 | +└─nvme1n1p3 259:4 0 928.5G 0 part |
| 43 | + └─ubuntu--vg-ubuntu--lv 252:0 0 928.5G 0 lvm / |
| 44 | +``` |
| 45 | + |
| 46 | +In the above we can see `nvme1n1` is partition and mounted at `/`. Another new drive has been added but is still unpartitioned and unmounted. |
| 47 | + |
| 48 | +### 2) If the disk is raw/unpartitioned, we need to partition the new drive: |
| 49 | + |
| 50 | +``` |
| 51 | +$ sudo fdisk /dev/nvme0n1 |
| 52 | +``` |
| 53 | + |
| 54 | +Inside fdisk: |
| 55 | + - `n` to create new partition |
| 56 | + - `p` to set as primary |
| 57 | + - Accept defaults for full disk |
| 58 | + - `w` to write changes |
| 59 | + |
| 60 | +After this, you should see `/dev/nvme0n1p1`. |
| 61 | + |
| 62 | +### 3) Format the partition for `ext4` (most common case): |
| 63 | + |
| 64 | +``` |
| 65 | +$ sudo mkfs.ext4 /dev/nvme0n1p1 |
| 66 | +``` |
| 67 | + |
| 68 | +Take note of the UUID. We will need it later. |
| 69 | + |
| 70 | +### 4) Create a mount point for the new drive: |
| 71 | + |
| 72 | +``` |
| 73 | +$ sudo mkdir -p /mnt/newssd |
| 74 | +``` |
| 75 | + |
| 76 | +### 5) Mount the drive (temporarily): |
| 77 | + |
| 78 | +``` |
| 79 | +$ sudo mount /dev/nvme0n1p1 /mnt/newssd |
| 80 | +``` |
| 81 | + |
| 82 | +You can verify with: |
| 83 | + |
| 84 | +``` |
| 85 | +$ df -h |
| 86 | +``` |
| 87 | + |
| 88 | +### 6) Get the UUID (required for permanent mount): |
| 89 | + |
| 90 | +``` |
| 91 | +$ blkid /dev/nvme0n1p1 |
| 92 | +``` |
| 93 | + |
| 94 | +It will be something like `UUID="e3b1c9a4-8c5d-4b8d-a9b2-123456789abc"`. |
| 95 | + |
| 96 | + |
| 97 | +### 7) Mount automatically at boot using `fstab`: |
| 98 | + |
| 99 | +``` |
| 100 | +$ sudo nano /etc/fstab |
| 101 | +``` |
| 102 | + |
| 103 | +Add this line and replace UUID and path: |
| 104 | + |
| 105 | +``` |
| 106 | +UUID=e3b1c9a4-8c5d-4b8d-a9b2-123456789abc /mnt/ssd2 ext4 defaults,nofail 0 2 |
| 107 | +``` |
| 108 | + |
| 109 | +To test `fstab`: |
| 110 | + |
| 111 | +``` |
| 112 | +$ sudo umount /mnt/newssd |
| 113 | +$ sudo mount -a |
| 114 | +``` |
| 115 | + |
| 116 | +If no errors, it will mount correctly at boot. |
| 117 | + |
| 118 | + |
| 119 | +### 8) Set permissions so your user can write to it: |
| 120 | + |
| 121 | +``` |
| 122 | +$ sudo chown -R $USER:$USER /mnt/newssd |
| 123 | +``` |
0 commit comments