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.
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 hda1, hda2, hda3. 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:
255 heads, 63 sectors/track, 9733 cylinders
0
255 heads, 63 sectors/track, 9733 cylinders
1
255 heads, 63 sectors/track, 9733 cylinders
2
255 heads, 63 sectors/track, 9733 cylinders
3
255 heads, 63 sectors/track, 9733 cylinders
4
255 heads, 63 sectors/track, 9733 cylinders
5
255 heads, 63 sectors/track, 9733 cylinders
6
255 heads, 63 sectors/track, 9733 cylinders
7
255 heads, 63 sectors/track, 9733 cylinders
8
255 heads, 63 sectors/track, 9733 cylinders
9
Units = cylinders of 16065 * 512 = 8225280 bytes
0
Units = cylinders of 16065 * 512 = 8225280 bytes
1
Units = cylinders of 16065 * 512 = 8225280 bytes
2
Units = cylinders of 16065 * 512 = 8225280 bytes
3
Units = cylinders of 16065 * 512 = 8225280 bytes
4
Units = cylinders of 16065 * 512 = 8225280 bytes
5
Units = cylinders of 16065 * 512 = 8225280 bytes
6
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.
Units = cylinders of 16065 * 512 = 8225280 bytes
7
Units = cylinders of 16065 * 512 = 8225280 bytes
8
Units = cylinders of 16065 * 512 = 8225280 bytes
9
Device Boot Start End Blocks Id System
0
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.
Device Boot Start End Blocks Id System
1
Device Boot Start End Blocks Id System
2
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.
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/hda1 1 262 2104483+ 82 Linux swap / Solaris
4
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
/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris
5
/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris
6
/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris
7
/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris
8
/dev/hda1 1 262 2104483+ 82 Linux swap / Solaris
9
/dev/hda2 * 263 2873 20972857+ 83 Linux
0
/dev/hda2 * 263 2873 20972857+ 83 Linux
1
/dev/hda2 * 263 2873 20972857+ 83 Linux
2
/dev/hda2 * 263 2873 20972857+ 83 Linux
3
/dev/hda2 * 263 2873 20972857+ 83 Linux
4
/dev/hda2 * 263 2873 20972857+ 83 Linux
5
/dev/hda2 * 263 2873 20972857+ 83 Linux
6
Tuỳ vào dự định của bạn tạo dạng hệ thống file cho /dev/sda1 là ext2, ext3 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
/dev/hda2 * 263 2873 20972857+ 83 Linux
7
Để 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: