官术网_书友最值得收藏!

Steps to format a hard disk

After we have created our partitions, the next step would be to make the partitions accessible by way of a filesystem. In Linux, when we format a partition(s), the system wipes the partition, and this enables the system to store data on the partition.

We have a number of filesystem types available in a Linux system. We use the mkfs command in combination with the desired filesystem type. To see the available filesystems, we can do this:

From the preceding screenshot, in this Ubuntu distribution, the ext4 type is primarily what the distribution is currently using. We can also use the lsblk command with the -f option to verify this:

root@ubuntu:/home/philip# lsblk -f

The output of the preceding command can be seen in the following screenshot:

From the preceding screenshot, we can see both hard disks: /dev/sda and /dev/sdb. Additionally, we see a column FSTYPE. This identifies which filesystem is currently in use. We can see that the FSTYPE is blank for the entire /dev/sdb(1-4).

We can also use the blkid command to view the filesystems in use by the system:

From the output given, the part that says TYPE= displays the filesystem in use. Please note that the TYPE= is missing for the /dev/sdb(1-4). This simply means that we have not formatted any of the partitions that reside on the /dev/sdb.

Now let's start formatting our partitions. For this, we'll use the ext4 filesystem on the /dev/sdb1:

root@ubuntu:/home/philip# mkfs.ext4 /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: fc51dddf-c23d-4160-8e49-f8a275c9b2f0
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
root@ubuntu:/home/philip#

From the preceding output, the mkfs utility, particularly mkfs.ext4, creates the filesystem on the raw partition; then it assigns a UUID to uniquely identify the /dev/sdb1 partition.

You need to have a root privilege before you can format a partition.

Next, let's use the ext3 filesystem for the /dev/sdb2:

root@ubuntu:/home/philip# mkfs.ext3 /dev/sdb2
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 524288 4k blocks and 131328 inodes
Filesystem UUID: fd6aab0f-0f16-4922-86c1-11fcb54fc466
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
root@ubuntu:/home/philip#

Now we'll use the ext2 for the /dev/sdb3 and the ntfs for the /dev/sdb4:

root@ubuntu:/home/philip# mkfs.ext2 /dev/sdb3
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 1572608 4k blocks and 393216 inodes
Filesystem UUID: b7e075df-541d-468d-ab16-e3ec2e5fb5f8
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
root@ubuntu:/home/philip# mkfs.ntfs /dev/sdb4
Cluster size has been automatically set to 4096 bytes.
Initializing device with zeroes: 100% - Done.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.
root@ubuntu:/home/philip#
You can also use the mk2fs to create an ext2 filesystem.

Great! Now we have just formatted the /dev/sdb1, /dev/sdb2, dev/sdb3 and the /dev/sdb4. If we now rerun the lsblk command with the -f option, we will see the filesystem type (FSTYPE) populated for the two respective partitions:

root@ubuntu:/home/philip# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 ext4 adb5d090-3400-4411-aee2-dd871c39db38 /
├─sda2
└─sda5 swap 025b1992-80ba-46ed-8490-e7aa68271e7b [SWAP]
sdb
├─sdb1 ext4 fc51dddf-c23d-4160-8e49-f8a275c9b2f0
├─sdb2 ext3 fd6aab0f-0f16-4922-86c1-11fcb54fc466
├─sdb3 ext2 b7e075df-541d-468d-ab16-e3ec2e5fb5f8
└─sdb4 ntfs 1D9E4A6D4088D79A
sr0
root@ubuntu:/home/philip#

From the preceding output, we can see that the FSTYPE is reflecting the changes that we made.

We can also rerun the blkid command to view the UUIDs created for the /dev/sdb1 and /dev/sdb2:

root@ubuntu:/home/philip# blkid
/dev/sda1: UUID="adb5d090-3400-4411-aee2-dd871c39db38" TYPE="ext4" PARTUUID="f54f42a0-01"
/dev/sda5: UUID="025b1992-80ba-46ed-8490-e7aa68271e7b" TYPE="swap" PARTUUID="f54f42a0-05"
/dev/sdb1: UUID="fc51dddf-c23d-4160-8e49-f8a275c9b2f0" TYPE="ext4" PARTUUID="7e707ac0-01"
/dev/sdb2: UUID="fd6aab0f-0f16-4922-86c1-11fcb54fc466" SEC_TYPE="ext2" TYPE="ext3" PARTUUID="7e707ac0-02"
/dev/sdb3: UUID="2a8a5768-1a7f-4ab4-8aa1-f45d30df5631" TYPE="ext2" PARTUUID="7e707ac0-03"
/dev/sdb4: UUID="1D9E4A6D4088D79A" TYPE="ntfs" PARTUUID="7e707ac0-04"
root@ubuntu:/home/philip#

As you can see, the system can now store information on the respective partitions.

主站蜘蛛池模板: 苍山县| 康乐县| 饶平县| 石屏县| 册亨县| 若尔盖县| 江口县| 临武县| 吴江市| 马山县| 柏乡县| 洛隆县| 临清市| 奇台县| 建德市| 武鸣县| 红桥区| 上饶市| 芦山县| 柳河县| 永丰县| 罗田县| 都匀市| 宁蒗| 丹阳市| 湘潭市| 海阳市| 宜宾县| 承德市| 怀集县| 潼关县| 宜昌市| 陆川县| 德阳市| 都兰县| 大化| 竹北市| 锡林浩特市| 阿鲁科尔沁旗| 蓝山县| 鹤山市|