Thứ Hai, 12 tháng 4, 2021

Hướng dẫn gắn thêm ổ cứng (HDD) trên Linux Server

Muốn add thêm HDD với Linux bạn có thể làm như hướng dẫn sau :

Trước tiên, có 1 số command mà bạn phải nắm rõ :

  • fdisk để phân chia partition của ổ cứng.
  • mkfs để format.
  • mount để gắn một partition đã format vào một mount point.
  • Chỉnh sửa fstab để Linux có thể tự động mount khi boot.

Khi thêm một ổ cứng với vào hệ thống, cần dùng lệnh fdisk -l để kiểm tra xem Linux gán cho ổ cứng mới device nào.

# fdisk -l
Disk /dev/hda: 80.0 GB, 80060424192 bytes
255 heads, 63 sectors/track, 9733 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
Device Boot Start End Blocks Id System
/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris
/dev/hda2 * 263 2873 20972857+ 83 Linux
/dev/hda3 2874 9733 55102950 83 Linux
 
Disk /dev/sda: 40.0 GB, 40007761920 bytes
64 heads, 32 sectors/track, 38154 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
 

Lấy ví dụ trên máy đang có một harddisk 80GB được gán vào /dev/hda và chia thành 3 partition hda1hda2hda3. Harddisk thứ 2 40GB được gán vào /dev/sda, và harddisk này chưa được định dạng.

Cần chú ý rằng với một số hệ điều hành Linux, sẽ quy định khe IDE0 tương ứng với /dev/hda, khe IDE1 tương ứng với /dev/hdb,…

Các ổ cứng SCSI, hay USB sẽ được gán vào /dev/sda/dev/sdb,… Với /dev/sda mới chưa được định dạng nói trên, trước hết ta dùng lệnh fdisk như sau:

 
# fdisk /dev/sda
The number of cylinders for this disk is set to 38154.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
delete a partition
l list known partition types
print this menu
add a new partition
o create a new empty DOS partition table
print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition"s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
 

Khi dùng lệnh fdisk /dev/sda, sẽ xuất hiện chế độ gõ lệnh của fdisk, ấn m để đưa ra các hướng dẫn về lệnh của fdisk.

Trong ví dụ này, chọn n để thêm một partition mới.

 
Command (for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-38154, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-38154, default 38154): 20480
 

Sau khi chọn n, xuất hiện 1 số lựa chọn như:

  • p để tạo primary partition – phân vùng có thể boot được.
  • e để tạo một phân vùng extended.

Đến đây ta chọn p. Sau khi chọn p, chương trình sẽ hỏi Partition number (1-4), gõ số 1.

Chương trình sẽ cho phép bạn thay đổi First cylinder và Last cylinder.

Chọn First cylinder = 1 và Last cylinder =20480.

Fdisk sẽ quay trở lại chế độ gõ lệnh chính của nó.

Tại chế đô gõ lệnh chính, dùng w để ghi lại các thông tin nói trên.

 
Command (for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
 

Sau khi chọn w, các thông tin sẽ được fdisk ghi lại trên hard-disk và fdisk tự động thoát, quay trở lại chế độ gõ lệnh của Linux.

Tại đây, gõ lệnh fdisk -l để kiểm tra các thay đổi.

 
# fdisk -l
Disk /dev/hda: 80.0 GB, 80060424192 bytes
255 heads, 63 sectors/track, 9733 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris
/dev/hda2 * 263 2873 20972857+ 83 Linux
/dev/hda3 2874 9733 55102950 83 Linux
Disk /dev/sda: 40.0 GB, 40007761920 bytes
64 heads, 32 sectors/track, 38154 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 20480 20971504 83 Linux
 

Sau khi gõ lệnh fdisk -l, có thể nhận thấy một partition /dev/sda1 mới được tạo.

Và để format partition này, sử dụng lệnh mkfs

 
# mkfs.ext3 /dev/sda1
mke2fs 1.38 (30-Jun-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2621440 inodes, 5242876 blocks
262143 blocks (5.00%) reserved for the super user
First data block=0
160 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -or -i to override.
 

Tuỳ vào dự định của bạn tạo dạng hệ thống file cho /dev/sda1 là ext2ext3 hay một định dạng khác mà tao sẽ dùng tham số thích hợp.

Trong ví dụ trên, ta format /dev/sda1 với ext3. Sau khi format, để sử dụng được /dev/sda1, cần phải mount nó vào một mount point, giả sử mount vào /media/data

# mount /dev/sda1 /media/data

Để Linux tự động mount /dev/sda1 vào mount point nói trên, cần phải thêm vào file /etc/fstab dòng sau:

/dev/sda1 /media/data ext3 defaults 0 0.

 
# vi /etc/fstab
/dev/hda2 / reiserfs acl,golden 1 1
/dev/hda3 /home reiserfs acl,golden 1 2
/dev/hda1 swap swap defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs noauto 0 0
debugfs /sys/kernel/debug debugfs noauto 0 0
usbfs /proc/bus/usb usbfs noauto 0 0
devpts /dev/pts devpts mode=0620,gid=5 0 0
192.168.1.100:/home/goldenbook /home/goldenbook nfs defaults 0 0
/dev/sda1 /media/data ext3 defaults 0 0
 
Để kiểm tra partition nào được mount vào mount point nào dùng lênh df hoặc lệnh mount để xem :
 
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda2 20972152 8155616 12816536 39% /
udev 517332 164 517168 1% /dev
/dev/hda3 55101224 33054028 22047196 60% /home
/dev/sda1 20642412 131232 19462608 1% /media/data
=============================
* KHOÁ HỌC ORACLE DATABASE A-Z ENTERPRISE trực tiếp từ tôi giúp bạn bước đầu trở thành những chuyên gia DBA, đủ kinh nghiệm đi thi chứng chỉ OA/OCP, đặc biệt là rất nhiều kinh nghiệm, bí kíp thực chiến trên các hệ thống Core tại VN chỉ sau 1 khoá học.
* CÁCH ĐĂNG KÝ: Gõ (.) hoặc để lại số điện thoại hoặc inbox https://m.me/tranvanbinh.vn hoặc Hotline/Zalo 090.29.12.888
* Chi tiết tham khảo:
https://bit.ly/oaz_w
hoặc
https://bit.ly/oaz_fp
=============================
KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH:
📧 Mail: binhoracle@gmail.com
☎️ Mobile: 0902912888
⚡️ Skype: tranbinh48ca
👨 Facebook: https://www.facebook.com/BinhOracleMaster
👨 Inbox Messenger: https://m.me/101036604657441 (profile)
👨 Fanpage: https://www.facebook.com/tranvanbinh.vn
👨 Inbox Fanpage: https://m.me/tranvanbinh.vn
👨👩 Group FB: https://www.facebook.com/groups/DBAVietNam
👨 Website: https://www.tranvanbinh.vn
👨 Blogger: https://tranvanbinhmaster.blogspot.com
🎬 Youtube: http://bit.ly/ytb_binhoraclemaster
👨 Tiktok: https://www.tiktok.com/@binhoraclemaster?lang=vi
👨 Linkin: https://www.linkedin.com/in/binhoracle
👨 Twitter: https://twitter.com/binhoracle
👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội

=============================
học oracle database, Tự học Oracle, Tài liệu Oracle 12c tiếng Việt, Hướng dẫn sử dụng Oracle Database, Oracle SQL cơ bản, Oracle SQL là gì, Khóa học Oracle Hà Nội, Học chứng chỉ Oracle ở đầu, Khóa học Oracle online,khóa học pl/sql, học dba, học dba ở việt nam, khóa học dba, khóa học dba sql, tài liệu học dba oracle, Khóa học Oracle online, học oracle sql, học oracle ở đâu tphcm, học oracle bắt đầu từ đâu, học oracle ở hà nội, oracle database tutorial, oracle database 12c, oracle database là gì, oracle database 11g, oracle download, oracle database 19c, oracle dba tutorial, oracle tunning, sql tunning , oracle 12c, oracle dataguard, oracle goldengate, oracle weblogic, oracle exadata, hoc solaris, hoc linux, hoc aix

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master