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

كيف 215System · Storage

How to partition and format a new disk

A new disk was added to the VM for data — now it must get a partition table, a partition, a file system, a mount point and an entry in /etc/fstab, so it is still there after a reboot. One wrong device name destroys data, so this how-to starts with identifying the disk safely, then uses parted (GPT), mkfs.xfs, and mounts by UUID.

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

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

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

215.1

The quick answer

lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
parted --script /dev/sdb mklabel gpt mkpart data xfs 1MiB 100%
mkfs.xfs -L data /dev/sdb1
mkdir -p /data
echo "UUID=$(blkid -s UUID -o value /dev/sdb1)  /data  xfs  defaults,nofail  0 0" >> /etc/fstab
systemctl daemon-reload && mount -a
findmnt /data

215.2

Step by step

  1. Find the new disk (line 1) — it has the expected size, no partitions, no file system and no mount point. Compare with the cloud console (size, LUN). On NVMe systems the name is like /dev/nvme1n1 and partitions are nvme1n1p1. When in doubt, ls -l /dev/disk/by-id/.
  2. Partition table and one partition (line 2) — GPT works for any size; starting at 1 MiB keeps the partition aligned. For a disk that will only hold one file system you may also format the whole disk without a partition, but a partition makes its use clear to others.
  3. File system (line 3) — XFS is the RHEL default and good for big data; ext4 (mkfs.ext4 -L data /dev/sdb1) can also shrink later. The label helps humans; the UUID is what fstab uses.
  4. Mount point and fstab (lines 4–5) — the UUID stays the same when device names change (sdb can become sdc after a reboot). nofail lets the server boot even if this disk is missing.
  5. Test the fstab line now (line 6) — mount -a mounts everything in fstab. An error here would also stop the next boot, so fix it before you reboot.
  6. Rights — the new file system belongs to root; give the app its folder: chown app:app /data. On SELinux systems set the right context for the app's data (semanage fcontext + restorecon).
  7. Consider LVM — if the data will grow, create an LVM volume instead of a plain partition, so you can add disks later.

215.3

Check that it worked

findmnt /data shows /dev/sdb1 with type xfs; df -h /data shows the full size; after a reboot (systemctl reboot) /data is mounted again.

215.4

Common problems

ProblemCauseFix
mkfs says the device contains a file systemWrong disk, or a disk used before.Stop and check lsblk -f; only wipe (wipefs -a) when you are sure.
New partition not visibleKernel did not re-read the table.partprobe /dev/sdb or udevadm settle.
Server stops at boot in emergency modefstab error or missing disk without nofail.Fix the line from the emergency shell; add nofail; test with mount -a.
mount: wrong fs typefstab type differs from blkid output.Use the type blkid shows.
Disk name changed after reboot/dev/sdX order is not stable.Mount by UUID or label.
App gets Permission deniedFolder owned by root, or wrong SELinux label.chown; restorecon -Rv /data with a proper fcontext rule.

215.5

Go further

1Why mount by UUID and not by /dev/sdb1?

Device names can change between boots; the UUID belongs to the file system and stays the same.

2Why run mount -a after editing fstab?

It tests the new line at once; an error would otherwise only show at the next boot and could stop it.

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