Rob's web

Drives

Preface

Is this page when I talk about drives I mean:

Floppies, CD/DVD, USB sticks and memory-cards are considered removable media.

Filesystem

In computing, a file system or filesystem (often abbreviated to fs) controls how data is stored and retrieved. Without a file system, data placed in a storage medium would be one large body of data with no way to tell where one piece of data stops and the next begins. By separating the data into pieces and giving each piece a name, the data is easily isolated and identified. Taking its name from the way paper-based data management system is named, each group of data is called a "file." The structure and logic rules used to manage the groups of data and their names is called a "file system."

There are many different kinds of file systems. Each one has different structure and logic, properties of speed, flexibility, security, size and more. Some file systems have been designed to be used for specific applications. For example, the ISO 9660 file system is designed specifically for optical discs.

File systems can be used on numerous different types of storage devices that use different kinds of media. As of 2019, hard disk drives have been key storage devices and are projected to remain so for the foreseeable future. Other kinds of media that are used include SSDs, magnetic tapes, and optical discs. In some cases, such as with tmpfs, the computer's main memory (random-access memory, RAM) is used to create a temporary file system for short-term use.

Mount points

All partitions are attached to the system via a mount point. The mount point defines the place of a particular data set in the file system. Usually, all partitions are connected through the root partition. On this partition, which is indicated with the slash (/), directories are created. These empty directories will be the starting point of the partitions that are attached to them. An example: given a partition that holds the following directories:

# findmnt --fstab --evaluate
TARGET SOURCE    FSTYPE OPTIONS
/      /dev/sdg3 xfs    defaults
/boot  /dev/sdg1 xfs    defaults
/home  /dev/sda1 xfs    defaults
/srv   /dev/sdf1 xfs    defaults
swap   /dev/sdg2 swap   defaults

The system uses /etc/fstab to keep record of the mountpoints.

# cat /etc/fstab

# /etc/fstab
# Created by anaconda on Wed Nov  4 18:12:49 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
# <UUID>                                  <mount point>           <type>  <options>  <dump> <pass>
UUID=082b1907-4c29-413f-96b6-6fd5136a2d01 /                       xfs     defaults   0      0
UUID=80b02956-3142-4b3e-ba7e-85bdba60334b /boot                   xfs     defaults   0      0
UUID=4b5cef53-03df-4782-8dcc-e5951db49721 /home                   xfs     defaults   0      0
UUID=a47e4336-e6ed-4f2e-b8f9-57cbb86d8b80 /srv                    xfs     defaults   0      0
UUID=b3c8398c-a93a-477c-87ef-bb009763791f swap                    swap    defaults   0      0

CentOs 7 uses UUID's. It replaced /dev/sda types. To know wich device has what UUID type:

# blkid -s UUID
/dev/sda1: UUID="4b5cef53-03df-4782-8dcc-e5951db49721"
/dev/sdf1: UUID="a47e4336-e6ed-4f2e-b8f9-57cbb86d8b80"
/dev/sdg1: UUID="80b02956-3142-4b3e-ba7e-85bdba60334b"
/dev/sdg2: UUID="b3c8398c-a93a-477c-87ef-bb009763791f"
/dev/sdg3: UUID="082b1907-4c29-413f-96b6-6fd5136a2d01"

When we want to know how much space is used enter:

# df -h
Bestandssysteem Grootte Gebruikt Besch Geb% Aangekoppeld op
devtmpfs           877M        0  877M   0% /dev
tmpfs              887M        0  887M   0% /dev/shm
tmpfs              887M      73M  815M   9% /run
tmpfs              887M        0  887M   0% /sys/fs/cgroup
/dev/sdg3           33G     3,4G   29G  11% /
/dev/sdf1          466G     4,6G  462G   1% /srv
/dev/sda1          3,7T     190G  3,5T   6% /home
/dev/sdg1         1014M     304M  711M  30% /boot
tmpfs              178M        0  178M   0% /run/user/0

If you need a quick view of your drives and usb sticks use:

# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   3,7T  0 disk
└─sda1   8:1    0   3,7T  0 part /home
sdf      8:80   0 465,8G  0 disk
└─sdf1   8:81   0 465,8G  0 part /srv
sdg      8:96   0  37,3G  0 disk
├─sdg1   8:97   0     1G  0 part /boot
├─sdg2   8:98   0     4G  0 part [SWAP]
└─sdg3   8:99   0  32,3G  0 part /
sr0     11:0    1  1024M  0 rom

Setting up a new server

Best practice is to buy new drives for a server - that is data server use - and not reusing old server drives which have already run for a long time. You can reuse desktop drives when they haven't run continual.

A year has 8766 hour.

HDD v.s. SSD

When we choose to use a SSD we need at least one HDD beside it to protect de SSD from over writing (It has limited write times). Reading from it is no problem.

DirectoryHDDSSD
swapYesNo
/YesYes
/boot/YesYes
/tmp/YesNo
/home/YesNo
/srv/YesNo
/var/YesNo
otherYesYes

Swap size

Amount of RAM
in the system
Recommended swap spaceRecommended swap space
if allowing for hibernation
≤ 2GB2 times the amount of RAM3 times the amount of RAM
2GB - 8GBEqual to the amount of RAM2 times the amount of RAM
8GB - 64GBAt least 4 GB1.5 times the amount of RAM
> 64GBAt least 4 GBHibernation not recommended

A server doesn't hibernate. HDD should run continu.

My system uses with 2 GB RAM:

# free
              total        used        free      shared  buff/cache   available
Mem:        1816504      651792      282988       72448      881724      922312
Swap:       4194300       68864     4125436

Setting up

When you start your install you will be asked how to partition your drives. I use standard partioning so you are limited to the phisical size of the drives.

On a system with one HDD

System with one HDD
1/boot1024 MB
2swapSee above
3/Rest

On a system with two HDD

System with two HDDs
HDD 1
1/boot1024 MB
2swapSee above
3/Rest
HDD 2
1/homeAll

On an system with one SSD

This is not recommended for file and webservers. For database servers it depands on howmuch the database is changed.

For systems that have little write activity like non-CMS webservers it might be OK. The SWAP partitoin is problaby the biggest problem if you need one.

On a system with one SSD and one HDD

For the SSD we need at least 40 GB and for the HDD we need ≥1 TB.

System with one SSD and one HDD
SSD
1/boot2048 MB
2/Rest
HDD
1swapSee above
2/tmp16 GB
3/var16 GB
4/srv32 GB
5/homeRest

On a system with one SSD and two HDDs

For the SSD we need ±40 GB and for HDD1 we need ≥80 GB and for HDD2 as much as you need.

System with one SSD and two HDDs
SSD
1/boot1024 MB
2/Rest
HDD 1
1swapSee above
2/tmp24 GB
3/var24 GB
4/srvRest
HDD 2
5/homeAll

We can consider to store the html-code on the SSD. Make a mountpoint on the SSD for /srv/www. Reserve at least 25 GB for it.

Remarks

The home dir is used for all users data. If you want to store videos you might consider to use a 4 TB disk.

In de srv dir we store all data for webpages and databases. A 25 GB partition wil be fine.

Replacing or adding a drive

When a disk gets to small or begins to fail you need to replace de disk.

Before we start we need to know which drive has the home or srv partition. Replacing the bootdisk is tricky.

The command # blkid -s UUID show all active devices and the UUID. Note which are show.

Switch of the server and add the new drive on a free SATA port.

Start the server and check with blkid which device is new. Thats our new disk.

Partioning

First we list the drives.

# parted -l
Model: ATA WDC WD40EFAX-68J (scsi)
Schijf /dev/sda: 4001GB
Sectorgrootte (logisch/fysiek): 512B/4096B
Partitietabel: gpt
Schijfvlaggen:

Nummer  Begin   Einde   Grootte  Bestandssysteem  Naam  Vlaggen
 1      1049kB  4001GB  4001GB   xfs              home


Model: ATA ST3500630AS (scsi)
Schijf /dev/sdf: 500GB
Sectorgrootte (logisch/fysiek): 512B/512B
Partitietabel: msdos
Schijfvlaggen:

Nummer  Begin   Einde  Grootte  Type     Bestandssysteem  Vlaggen
 1      1049kB  500GB  500GB    primary  xfs


Model: ATA ST340012A (scsi)
Schijf /dev/sdg: 40,0GB
Sectorgrootte (logisch/fysiek): 512B/512B
Partitietabel: msdos
Schijfvlaggen:

Nummer  Begin   Einde   Grootte  Type     Bestandssysteem  Vlaggen
 1      1049kB  1075MB  1074MB   primary  xfs              opstart
 2      1075MB  5370MB  4295MB   primary  linux-swap(v1)
 3      5370MB  40,0GB  34,7GB   primary  xfs

Whit this command we can also see what brand and type each disk is.

For partion up to 2 TB you can use msdos. For larger dan 2 TB you need gpt.

X is the new drive. Label is the MBR type.

# parted /dev/sdX
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdX will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? y
(parted) print free
(parted) mkpart storage xfs 0% 100%
(parted) print free
(parted) quit
Information: You may need to update /etc/fstab.

Format the partition

Next, format the new Linux partition with the xfs filesystem using mkfs.xfs.

# mkfs.xfs /dev/sdX1

After all partitions have been formatted you can use the new drive.

Copy the files to the new drive.

Copy the files

# blkid -s UUID

/dev/sdX1: UUID="d98abe0a-f641-4331-a3dc-b89ebc60bfb5"

The new drive is formatted and ready to be mounted into the system. But the process of replacing another drive with this one isn't quite that simple. First, both drives must be mounted simultaneously to copy files from the old drive to the new one.

To do this, mount the new drive on a temporary mount point, copy the files, and then unmount both drives. Why? So you can mount the new drive at the same mount point where the old drive was mounted in order to preserve the path. In case there are applications with that path configured, it's just simpler this way.

# mount UUID="d98abe0a-f641-4331-a3dc-b89ebc60bfb5" /mnt
# cp -Ra /home/* /mnt/

Use diff to verify the copy's success.

diff -rqy /home/ /mnt/

Remove the old HDD

Now that the new drive contains all of the old files, remount it in place of the old drive. First, unmount both drives. sdb2 is the old drive with the home partion.

# umount /dev/sdX1
# umount /dev/sdb2

Turn off swap

If the old drive will no longer be used as a swap device, disable it with the swapoff command.

# swapoff /dev/sdb1
If you repeat the cat /proc/swaps command, it will no longer list this partition.

Update the fstab file

Go back to the /etc/fstab file; there are a few changes that you need to make. I advise making a backup of the file before editing it.

cp -a /etc/fstab /etc/fstab.backup

In the line for the /home mount point, replace the UUID with that of the new drive; replace the filesystem, ext4, with xfs; and add discard to the options. It should appear like this:

UUID=d98abe0a-f641-4331-a3dc-b89ebc60bfb5 /home xfs defaults,noatime,discard 0 2

After saving the fstab file, run mount to re-mount based on the changes.

# mount -av
/                : ignored
/boot/efi        : already mounted
/home            : successfully mounted

Finally, shut down the computer and remove the HDD that will no longer be used and connect the new HDD to the SATA port of the old one. Then power up and check that the system has booted correctly and that all drives are mounted as expected.

Add a new drive

If you want to add the new drive you only need to add it to fstab.

Links