متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 75System · Storage

How to mount a disk at boot with fstab

A new data disk must be mounted at /data — now and after every reboot. One wrong line in /etc/fstab can stop the server from booting, so the safe way is: use the UUID (not /dev/sdb, which can change), test the line before you reboot, and use nofail for disks that may be missing. This how-to formats a new disk, writes the fstab line and proves it works.

  • 5 الدروس
  • 13 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

75.1

The quick answer

mkfs.xfs /dev/sdb
mkdir -p /data
blkid -s UUID -o value /dev/sdb
3f1c9e2b-7a4d-4b6e-9a51-0f3e5c2d8a10
echo 'UUID=3f1c9e2b-7a4d-4b6e-9a51-0f3e5c2d8a10 /data xfs defaults,nofail 0 0' >> /etc/fstab
systemctl daemon-reload
findmnt --verify
mount -a
df -h /data

75.2

Step by step

  1. Find the new disk — check it is really empty:
lsblk -f
NAME   FSTYPE FSVER LABEL UUID                                 MOUNTPOINTS
sda
├─sda1 xfs                 1d2c...                              /boot
└─sda2 LVM2_member         ...
sdb

sdb has no file system and no mount — that is the new one. Never format a disk that shows a file system you do not know.

  1. Create the file system (XFS on RHEL, ext4 is fine too):
mkfs.xfs -L data /dev/sdb
mkfs.ext4 -L data /dev/sdb

(Use one of them.) For a disk you may want to split later, use LVM or a partition first.

  1. Write the fstab line with the UUID:
FieldExampleMeans
1 deviceUUID=3f1c…Stable ID (blkid).
2 mount point/dataMust exist (mkdir).
3 typexfsFile system.
4 optionsdefaults,nofailnofail = boot continues if the disk is missing.
5 dump0Not used.
6 fsck order00 for XFS; 2 for ext4 data disks.

Network shares: add _netdev (wait for the network), for example nfs1:/export /mnt/share nfs4 defaults,_netdev,nofail 0 0.

  1. Test before you reboot — this is the important step:
systemctl daemon-reload
findmnt --verify
mount -a
findmnt /data
TARGET SOURCE   FSTYPE OPTIONS
/data  /dev/sdb xfs    rw,relatime,...

findmnt --verify finds typos; mount -a mounts everything in fstab — an error here means the line is wrong (fix it now, not at the next boot).

  1. Rights for the app:
chown app:app /data
restorecon -Rv /data

75.3

Check that it worked

Reboot in a maintenance window: the server comes up, df -h /data shows the disk, and the app can write to it.

الأوامر في هذا الدرس

75.4

Common problems

ProblemCauseFix
Server boots into emergency modeWrong fstab line, or the disk is missing (no nofail).Log in on the console, fix or comment the line, systemctl daemon-reload, reboot.
mount: /data: mount point does not existFolder not created.mkdir -p /data.
Mounted the wrong disk after a reboot/dev/sdX names changed.Use UUID= (or LABEL=).
wrong fs type, bad option, bad superblockWrong type or no file system on it.lsblk -f; correct field 3 or create the file system.
NFS line hangs the bootNetwork not ready._netdev,nofail (or autofs / a systemd automount).
App gets Permission denied on /dataOwner root, or SELinux label.chown; restorecon -Rv /data (or a proper semanage fcontext).

75.5

Go further

1Why use UUID= instead of /dev/sdb in fstab?

Device names can change between boots; the UUID stays the same.

2How do you test an fstab line without rebooting?

كل الأوامر في هذا الفصل