Difference between revisions of "Adding a new drive from the command line"
(Created page with "[https://www.tecmint.com/add-new-disk-to-an-existing-linux/ Tecmint tutorial] = Connect the drive = Either plug the drive into the machine with the power off or hot-swap it in if possible... = Determine the device = * <code>sudo fdisk -l</code> '''fdisk''' is a dialog-driven program for creation and manipulation of partition tables. * <code>man fdisk</code> ** for details... You'll see a fair bit of output. * Blocks starting with '''Disk /dev/sd_:''' indicate drives a...") |
|||
(27 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[https://www. | {{{!}} class="wikitable" style="float: right; width: 322px;" border="2" | ||
{{!}}+ Proven on: | |||
{{!}}- <!-- Debian --> | |||
{{!}} style="text-align: center; width: 60px;" {{!}} [[File:Logo Debian.png{{!}}60px{{!}}link=https://www.debian.org/{{!}}center{{!}}middle{{!}}frameless]] | |||
{{!}} style="text-align: center; width: 40px;" {{!}} 11 (bullseye) | |||
{{!}} (This includes LMDE5, Proxmox, OMV...) | |||
{{!}}- | |||
{{!}} style="text-align: center; width: 60px;" colspan="3" {{!}} [[typographic conventions{{!}}A little note about typographic conventions you'll see here]] | |||
{{!}}} | |||
= Connect the drive = | = Connect the drive = | ||
Either plug the drive into the machine with the power off or hot-swap it in if possible... | Either plug the drive into the machine with the power off or hot-swap it in if possible... | ||
(Yes... Adding a new drive to an ESXi or Proxmox VM is just like hot-swapping.) | |||
= Determine the device = | = Determine the device = | ||
* <code>sudo fdisk -l</code> | * <code>sudo fdisk -l</code> | ||
[[image:Fdisk example 0.png{{!}}300px{{!}}thumb{{!}}'''fdisk -l''' example]] | |||
'''fdisk''' is a dialog-driven program for creation and manipulation of partition tables. | '''fdisk''' is a dialog-driven program for creation and manipulation of partition tables. | ||
* <code>man fdisk</code> | * <code>man fdisk</code> | ||
Line 12: | Line 24: | ||
You'll see a fair bit of output. | You'll see a fair bit of output. | ||
* Blocks starting with '''Disk /dev/sd_:''' indicate drives and provide details about them. | * Blocks starting with '''Disk /dev/sd_:''' indicate drives and provide details about them. | ||
* Blocks starting with '''Device Boot Start...' indicate partitions on those drives. | * Blocks starting with '''Device Boot Start...''' indicate partitions on those drives. | ||
* In the case of an unformatted new drive, you'll see a '''Disk''' block that's not followed by a '''Device''' block. Make note of it's name (/dev/sd_) | * In the case of an unformatted new drive, you'll see a '''Disk''' block that's not followed by a '''Device''' block. Make note of it's name (/dev/sd_) | ||
* | * In our example, it's '''/dev/sdb''' | ||
= If your drive is previously used = | |||
* <code>sudo fdisk /dev/'''sdb'''</code> | |||
** <code>g</code> | |||
*** To create a new empty GPT partition table | |||
** <code>w</code> | |||
*** To write the partition table to the drive. | |||
= Partition the drive = | = Partition the drive = | ||
For now, we'll just make the new drive one partition. | For now, we'll just make the new drive one partition. | ||
[[File:Fdisk example 1.png{{!}}300px{{!}}thumb]] | |||
* <code>sudo fdisk /dev/'''sdb'''</code> | * <code>sudo fdisk /dev/'''sdb'''</code> | ||
** <code>n</code> | ** <code>n</code> | ||
Line 31: | Line 51: | ||
= Format the drive = | = Format the drive = | ||
Of course, the drive needs to be formatted before you can use it. | Of course, the drive needs to be formatted before you can use it. | ||
[[File:Mkfs example 0.png{{!}}300px{{!}}thumb]] | |||
We'll go with Ext4 for now. | We'll go with Ext4 for now. | ||
* <code>sudo mkfs.ext4 /dev/'''sdb1'''</code> | * <code>sudo mkfs.ext4 /dev/'''sdb1'''</code> | ||
<span style="color: rgb(132, 63, 161);" >'''A Little Note:''' You can actually format the whole drive without partitioning it.</span> | |||
= Label the drive = | |||
In order to make handling drives a little easier, it is often useful to give partitions human-readable names. | |||
* <code>sudo e2label /dev/sdb1 '''VOLUME-LABEL'''</code> | |||
Will label the partition we've been working with as '''VOLUME-LABEL'''. Now, any time you want to work with it using utilities that support labels, it'll be easier to keep track of which drive you're referring to. | |||
= Mount the drive = | = Mount the drive = | ||
Line 41: | Line 71: | ||
& mount it for use: | & mount it for use: | ||
* <code>sudo mount /dev/'''sdb1''' /'''MOUNTPOINT'''</code> | * <code>sudo mount /dev/'''sdb1''' /'''MOUNTPOINT'''</code> | ||
If you labelled it, you can mount by label: | |||
* <code>sudo mount -L '''VOLUME-LABEL''' /'''MOUNTPOINT'''</code> | |||
= Make the mounting automatic = | = Make the mounting automatic = | ||
Line 46: | Line 79: | ||
& add the line: | & add the line: | ||
/dev/sdb1 /MOUNTPOINT ext4 defaults 0 0 | /dev/'''sdb1''' '''/MOUNTPOINT''' ext4 defaults 0 0 | ||
or, by label: | |||
LABEL='''VOLUME-LABEL''' '''/MOUNTPOINT''' ext4 defaults 0 0 | |||
= Some Links = | |||
[[Category:Linux]] | |||
* [https://www.tecmint.com/add-new-disk-to-an-existing-linux/ Tecmint tutorial: How to Add a New Disk to an Existing Linux Server] | |||
* [https://linuxconfig.org/how-to-name-label-a-partition-or-volume-on-linux LinuxConfig: How to label a partition or volume on Linux with e2label] | |||
* [https://www.tecmint.com/change-modify-linux-disk-partition-label-names/ How to Change Linux Partition Label Names on EXT4 / EXT3 / EXT2 and Swap] | |||
* [https://www.cyberciti.biz/faq/linux-remove-all-partitions-data-empty-disk/ Linux Remove All Partitions / Data And Create Empty Disk] |
Latest revision as of 14:50, 29 July 2024
11 (bullseye) | (This includes LMDE5, Proxmox, OMV...) | |
A little note about typographic conventions you'll see here |
Connect the drive
Either plug the drive into the machine with the power off or hot-swap it in if possible...
(Yes... Adding a new drive to an ESXi or Proxmox VM is just like hot-swapping.)
Determine the device
sudo fdisk -l
fdisk is a dialog-driven program for creation and manipulation of partition tables.
man fdisk
- for details...
You'll see a fair bit of output.
- Blocks starting with Disk /dev/sd_: indicate drives and provide details about them.
- Blocks starting with Device Boot Start... indicate partitions on those drives.
- In the case of an unformatted new drive, you'll see a Disk block that's not followed by a Device block. Make note of it's name (/dev/sd_)
- In our example, it's /dev/sdb
If your drive is previously used
sudo fdisk /dev/sdb
g
- To create a new empty GPT partition table
w
- To write the partition table to the drive.
Partition the drive
For now, we'll just make the new drive one partition.
sudo fdisk /dev/sdb
n
- To create a new partition
p
- To make it a primary partition
- Hit
Enter
- 3 times to pick the default values.
w
- To write the partition table to the drive.
Format the drive
Of course, the drive needs to be formatted before you can use it.
We'll go with Ext4 for now.
sudo mkfs.ext4 /dev/sdb1
A Little Note: You can actually format the whole drive without partitioning it.
Label the drive
In order to make handling drives a little easier, it is often useful to give partitions human-readable names.
sudo e2label /dev/sdb1 VOLUME-LABEL
Will label the partition we've been working with as VOLUME-LABEL. Now, any time you want to work with it using utilities that support labels, it'll be easier to keep track of which drive you're referring to.
Mount the drive
Create a mount point for the drive:
sudo mkdir /MOUNTPOINT
& mount it for use:
sudo mount /dev/sdb1 /MOUNTPOINT
If you labelled it, you can mount by label:
sudo mount -L VOLUME-LABEL /MOUNTPOINT
Make the mounting automatic
sudo vi /etc/fstab
& add the line:
/dev/sdb1 /MOUNTPOINT ext4 defaults 0 0
or, by label:
LABEL=VOLUME-LABEL /MOUNTPOINT ext4 defaults 0 0