Ubuntu Server – Neue Festplatte einbinden

Um etwas mehr Speicherplatz  auf meinem Heimserver zu haben auf dem diverse Applikationen laufen, hab ich diesen mit einer zweiten Festplatte bestückt. Um diese nutzen zu können gibt es auf meinem Ubuntu Server (LTS 20.04) ein paar Kleinigkeiten zu erledigen. Nachdem du die Festplatte eingebaut hast, prüfst du mit dem Kommando “fdsik” ob das Betriebssystem die Disk erkannt hat.

sudo fdisk -l

Die Ausgabe sieht bei mir folgendermaßen aus:

Disk /dev/loop0: 55,45 MiB, 58130432 bytes, 113536 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop1: 32,3 MiB, 33865728 bytes, 66144 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop2: 70,32 MiB, 73728000 bytes, 144000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop3: 43,28 MiB, 45371392 bytes, 88616 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop4: 55,5 MiB, 58183680 bytes, 113640 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop5: 61,93 MiB, 64913408 bytes, 126784 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop6: 67,25 MiB, 70508544 bytes, 137712 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sdb: 1,84 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: WDC WD20EFRX-68A
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/sda: 1,84 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: ST2000DM001-1CH1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 1389351B-149D-494C-87B9-6C01841932BF

Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 3907026943 3905976320 1,8T Linux filesystem

Mit dem Kommando “df” kannst du gegenprüfen, welches die neue Festplatte ist, solltest du nicht sicher sein, In meinem Fall ist die neue Disk: /dev/sdb.

Filesystem 1K-blocks Used Available Use% Mounted on
udev 3964716 0 3964716 0% /dev
tmpfs 801980 1272 800708 1% /run
/dev/sda2 1921285344 6956568 1816662984 1% /
tmpfs 4009884 0 4009884 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
tmpfs 4009884 0 4009884 0% /sys/fs/cgroup
/dev/loop0 56832 56832 0 100% /snap/core18/2128
/dev/loop1 33152 33152 0 100% /snap/snapd/12704
/dev/loop2 72064 72064 0 100% /snap/lxd/21029
/dev/sda1 523248 5356 517892 2% /boot/efi
/dev/loop3 44416 44416 0 100% /snap/snapd/14295
/dev/loop4 56832 56832 0 100% /snap/core18/2253
/dev/loop5 63488 63488 0 100% /snap/core20/1270
/dev/loop6 68864 68864 0 100% /snap/lxd/21835
tmpfs 801976 0 801976 0% /run/user/1000

Partition erstellen

Als nächstes musst du eine neue Partition erstellen. Das machst du mit dem Kommando “fdisk”. Mit dem dem Kommando “m” bekommst du eine Befehlsübersicht angezeigt

sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x51a99a44.

Command (m for help): m

Help:

DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag

Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition

Misc
m print this menu
u change display/entry units
x extra functionality (experts only)

Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file

Save & Exit
w write table to disk and exit
q quit without saving changes

Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table

Mit dem Kommando “p” kannst du dir die Partitionstabelle der neuen ausgewählten Festplatte (/dev/sdb) anzeigen lassen:

Command (m for help): p
Disk /dev/sdb: 1,84 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: WDC WD20EFRX-68A
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x51a99a44

Im nächsten Schritt erstellst du mit dem Kommando “n” eine neue Partition:

Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)

Danach machst du mit dem Kommando “p” die Partition zu einer primären Partition. Für die Partitionsnummer, den ersten, sowie den letzten Sektor der Festplatte verwendest du jeweils die  Standardwerte:

Select (default p): p
Partition number (1-4, default 1):
First sector (2048-3907029167, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-3907029167, default 3907029167):

Created a new partition 1 of type 'Linux' and of size 1,8 TiB.

Damit ist die neue Partition erstellt, was wir nochmal mit dem Kommando “fdsik” überprüfen:

sudo fdisk -l
Disk /dev/loop0: 55,45 MiB, 58130432 bytes, 113536 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop1: 32,3 MiB, 33865728 bytes, 66144 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop2: 70,32 MiB, 73728000 bytes, 144000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop3: 43,28 MiB, 45371392 bytes, 88616 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop4: 55,5 MiB, 58183680 bytes, 113640 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop5: 61,93 MiB, 64913408 bytes, 126784 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop6: 67,25 MiB, 70508544 bytes, 137712 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sdb: 1,84 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: WDC WD20EFRX-68A
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x51a99a44

Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 3907029167 3907027120 1,8T 83 Linux

Disk /dev/sda: 1,84 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: ST2000DM001-1CH1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 1389351B-149D-494C-87B9-6C01841932BF

Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 3907026943 3905976320 1,8T Linux filesystem

Partition formatieren

Anschließend muss die neu erstellte Partition noch formatiert werden. Wir verwenden dafür das ext4 Filesystem. Das Kommando und der Output dafür sieht folgendermaßen aus:

sudo mkfs.ext4 /dev/sdb
mke2fs 1.45.5 (07-Jan-2020)
Found a dos partition table in /dev/sdb
Proceed anyway? (y,N) y
Creating filesystem with 488378646 4k blocks and 122101760 inodes
Filesystem UUID: 5e18237d-3f1c-4277-81a6-593de8c47216
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

Partition mounten

Um die neu formatierte Partition verwenden zu können muss diese gemounted werden. Bei mir wird diese als reine Daten-Disk verwendet weshalb ich diese auf /data mounte. Die Kommandos dafür sind folgende:

sudo mkdir /data
sudo mount -v -o rw /dev/sdb /data
mount: /dev/sdb mounted on /data.

Damit die Partition bei einem Reboot ebenfalls wieder eingebunden wird, ist eine Anpassung in der Datei /etc/fstab notwendig. Diese kannst du mit dem Editor “vi” anpassen.

sudo vi /etc/fstab

Folgende Zeile musst du dafür einfügen:

/dev/sdb /data ext4 defaults 0 0

Das war’s.