1
00:00:00,300 --> 00:00:02,009
In this lesson, we're going to learn

2
00:00:02,009 --> 00:00:03,600
about partitions and their use

3
00:00:03,600 --> 00:00:05,880
in the Linux operating system.

4
00:00:05,880 --> 00:00:08,910
Aside from managing user access to your Linux systems,

5
00:00:08,910 --> 00:00:10,710
one of the most foundational tasks

6
00:00:10,710 --> 00:00:13,020
is the management of data storage.

7
00:00:13,020 --> 00:00:15,570
There are many different ways to divide, format,

8
00:00:15,570 --> 00:00:17,250
or otherwise organize the data

9
00:00:17,250 --> 00:00:18,990
that's going to be stored on your systems.

10
00:00:18,990 --> 00:00:22,050
And Linux gives you many different tools for doing this.

11
00:00:22,050 --> 00:00:24,750
Using these tools, you'll ultimately make it easier

12
00:00:24,750 --> 00:00:27,720
for authorized users to work with data.

13
00:00:27,720 --> 00:00:30,030
There are many different types of storage devices

14
00:00:30,030 --> 00:00:32,670
that are supported by the Linux operating system.

15
00:00:32,670 --> 00:00:34,770
Common types include hard disk drives,

16
00:00:34,770 --> 00:00:37,470
they use magnetic storage technology to store your data.

17
00:00:37,470 --> 00:00:38,760
Solid-state drives,

18
00:00:38,760 --> 00:00:40,950
they use non-mechanical, solid-state technology

19
00:00:40,950 --> 00:00:42,300
to store your data.

20
00:00:42,300 --> 00:00:45,120
USB thumb drives, they use flash memory technology

21
00:00:45,120 --> 00:00:46,290
to store your data.

22
00:00:46,290 --> 00:00:47,880
And external storage drives,

23
00:00:47,880 --> 00:00:50,010
they use several different types of technologies,

24
00:00:50,010 --> 00:00:51,540
and usually connect to the computer

25
00:00:51,540 --> 00:00:52,860
through a peripheral interface

26
00:00:52,860 --> 00:00:55,410
rather than being internally connected.

27
00:00:55,410 --> 00:00:57,060
In Linux, devices are referred to

28
00:00:57,060 --> 00:00:59,790
as either block or character devices.

29
00:00:59,790 --> 00:01:02,580
Block devices are things like storage devices,

30
00:01:02,580 --> 00:01:04,230
these are things like hard drives,

31
00:01:04,230 --> 00:01:06,720
solid-state drives, and USB drives.

32
00:01:06,720 --> 00:01:08,520
And all of these can be read from

33
00:01:08,520 --> 00:01:11,130
or written to in blocks of data.

34
00:01:11,130 --> 00:01:13,410
Character devices on the other hand are devices

35
00:01:13,410 --> 00:01:16,200
like keyboards, mice, serial ports,

36
00:01:16,200 --> 00:01:18,630
and other things like that that can read from

37
00:01:18,630 --> 00:01:21,993
or write to streams of data one character at a time.

38
00:01:22,860 --> 00:01:24,900
A file system is a data structure

39
00:01:24,900 --> 00:01:26,940
that's going to be used by an operating system

40
00:01:26,940 --> 00:01:30,240
to store, retrieve, organize, and manage files

41
00:01:30,240 --> 00:01:32,910
and directories on a given storage device.

42
00:01:32,910 --> 00:01:35,670
It also maintains information about the data

43
00:01:35,670 --> 00:01:37,020
such as the date of creation

44
00:01:37,020 --> 00:01:39,330
and the modification of individual files,

45
00:01:39,330 --> 00:01:41,820
the size of the files on that storage device,

46
00:01:41,820 --> 00:01:42,960
the type of files,

47
00:01:42,960 --> 00:01:45,540
and the permissions associated with those files.

48
00:01:45,540 --> 00:01:48,060
But the operating system does not interpret

49
00:01:48,060 --> 00:01:50,310
the data contained in the files itself

50
00:01:50,310 --> 00:01:54,090
because this task is handled by specific applications.

51
00:01:54,090 --> 00:01:57,240
The file systems vary depending on several different things,

52
00:01:57,240 --> 00:01:59,130
such as the purpose of the file systems,

53
00:01:59,130 --> 00:02:01,740
the information they store about the individual files,

54
00:02:01,740 --> 00:02:03,210
and the way they store data

55
00:02:03,210 --> 00:02:05,100
as well as the data security mechanisms

56
00:02:05,100 --> 00:02:06,930
that are going to be implemented.

57
00:02:06,930 --> 00:02:09,870
Linux systems support several different types of systems,

58
00:02:09,870 --> 00:02:14,870
including FAT, ext2, ext3, ext4, XFS, and BTRFS.

59
00:02:17,340 --> 00:02:20,220
These file systems can be used for varying situations

60
00:02:20,220 --> 00:02:22,590
depending on your specific user needs.

61
00:02:22,590 --> 00:02:24,960
FAT or the File Allocation Table

62
00:02:24,960 --> 00:02:27,120
is an older file system that is compatible

63
00:02:27,120 --> 00:02:29,070
with many different operating systems,

64
00:02:29,070 --> 00:02:33,600
including all versions of Unix, Windows, and Mac OS X.

65
00:02:33,600 --> 00:02:35,580
It does not provide the same capabilities

66
00:02:35,580 --> 00:02:37,350
as more modern file systems,

67
00:02:37,350 --> 00:02:38,550
and it's typically going to be used

68
00:02:38,550 --> 00:02:40,380
when you need to maintain compatibility

69
00:02:40,380 --> 00:02:43,200
between all these different operating systems.

70
00:02:43,200 --> 00:02:46,257
Ext2 on the other hand is a native Linux file system,

71
00:02:46,257 --> 00:02:48,180
and it's using some older releases

72
00:02:48,180 --> 00:02:51,150
and it's still supported in your current Linux releases.

73
00:02:51,150 --> 00:02:55,470
Ext3 is a more modern version of a native Linux file system.

74
00:02:55,470 --> 00:02:58,260
Ext3 is much faster in recovering data,

75
00:02:58,260 --> 00:03:01,170
and it does a better job of ensuring data integrity

76
00:03:01,170 --> 00:03:05,040
in the case of abrupt system shutdowns than ext2 did.

77
00:03:05,040 --> 00:03:09,000
Another default file system in Linux distributions is ext4,

78
00:03:09,000 --> 00:03:11,280
and this supports really large volumes,

79
00:03:11,280 --> 00:03:13,440
up to one exabytes of data,

80
00:03:13,440 --> 00:03:14,970
and it also supports file sizes

81
00:03:14,970 --> 00:03:18,570
of up to 16 terabytes in one file.

82
00:03:18,570 --> 00:03:22,710
XFS is a 64-bit, high-performance journaling file system

83
00:03:22,710 --> 00:03:24,240
that provides fast recovery

84
00:03:24,240 --> 00:03:27,390
and can handle really large files efficiently as well.

85
00:03:27,390 --> 00:03:31,110
The last type of file system we have is known as BTRFS.

86
00:03:31,110 --> 00:03:34,860
BTRFS is a modern, copy-on-right file system for Linux

87
00:03:34,860 --> 00:03:36,360
that's designed with advanced features

88
00:03:36,360 --> 00:03:38,760
in order to provide fault tolerance, repair,

89
00:03:38,760 --> 00:03:41,490
and easy administration of your file system.

90
00:03:41,490 --> 00:03:45,630
BTRFS supports volumes of up to 16 exabytes in size,

91
00:03:45,630 --> 00:03:48,150
files of up to 16 exabytes in size,

92
00:03:48,150 --> 00:03:49,590
and it supports a maximum

93
00:03:49,590 --> 00:03:52,323
of 18 quintillion files on each volume.

94
00:03:53,160 --> 00:03:56,430
Some file systems function as network protocols as well,

95
00:03:56,430 --> 00:03:59,310
and this enables the sharing of data over a network.

96
00:03:59,310 --> 00:04:01,740
For example, the SMB protocol,

97
00:04:01,740 --> 00:04:03,690
also known as Server Message Block,

98
00:04:03,690 --> 00:04:06,270
is going to allow users to share access to files

99
00:04:06,270 --> 00:04:09,090
and other resources over a local area network

100
00:04:09,090 --> 00:04:10,920
which is known as a LAN.

101
00:04:10,920 --> 00:04:14,700
SMB clients make requests for resources to SMB servers,

102
00:04:14,700 --> 00:04:16,290
and these servers will respond

103
00:04:16,290 --> 00:04:18,930
and provide the appropriate level of access.

104
00:04:18,930 --> 00:04:23,490
In addition to SMB, we also have something known as CIFS.

105
00:04:23,490 --> 00:04:26,457
CIFS is the Common Internet File System

106
00:04:26,457 --> 00:04:28,410
and it's a specific implementation

107
00:04:28,410 --> 00:04:31,290
of SMB that is rarely in use today.

108
00:04:31,290 --> 00:04:33,090
Instead, Microsoft designed it

109
00:04:33,090 --> 00:04:35,670
as a successor to SMB version 1,

110
00:04:35,670 --> 00:04:39,270
but SMB version two and three have long since replaced

111
00:04:39,270 --> 00:04:42,240
version one and CIFS.

112
00:04:42,240 --> 00:04:44,970
However, some Linux distributions will still use

113
00:04:44,970 --> 00:04:47,760
the name CIFS in some of the tools

114
00:04:47,760 --> 00:04:50,400
when they're referring to tools that support SMB,

115
00:04:50,400 --> 00:04:52,860
so it is something you need to be aware of.

116
00:04:52,860 --> 00:04:56,340
Another protocol you need to be aware of is NFS,

117
00:04:56,340 --> 00:04:59,220
NFS stands for the Network File System.

118
00:04:59,220 --> 00:05:03,060
The Network File System offers similar functionality to SMB,

119
00:05:03,060 --> 00:05:07,650
but NFS and SMB are not compatible with each other.

120
00:05:07,650 --> 00:05:09,720
If you're going to be using all Linux clients

121
00:05:09,720 --> 00:05:11,130
and servers in an environment,

122
00:05:11,130 --> 00:05:13,110
then you'll probably want to use NFS

123
00:05:13,110 --> 00:05:15,870
because it actually has some better features than SMB.

124
00:05:15,870 --> 00:05:17,520
But if you're going to use a mixture

125
00:05:17,520 --> 00:05:19,230
of Windows and Linux systems,

126
00:05:19,230 --> 00:05:21,060
you want to rely on SMB

127
00:05:21,060 --> 00:05:24,150
because SMB is the default inside of Windows

128
00:05:24,150 --> 00:05:25,980
and is supported right out the bat,

129
00:05:25,980 --> 00:05:28,983
where NFS is not supported by Windows by default.

130
00:05:29,850 --> 00:05:31,080
Another thing we need to talk about

131
00:05:31,080 --> 00:05:33,120
is something known as an index node,

132
00:05:33,120 --> 00:05:35,821
this is also abbreviate as an Inode.

133
00:05:35,821 --> 00:05:38,430
An index node is an object that stores metadata

134
00:05:38,430 --> 00:05:41,850
about a file or directory on a given file system.

135
00:05:41,850 --> 00:05:44,460
This metadata can include time-based values

136
00:05:44,460 --> 00:05:47,100
like when the file was created and last modified,

137
00:05:47,100 --> 00:05:49,350
it can have permission and ownership information.

138
00:05:49,350 --> 00:05:50,730
It can have the block locations

139
00:05:50,730 --> 00:05:52,860
of the files data on a storage device

140
00:05:52,860 --> 00:05:55,650
and other pieces of miscellaneous information.

141
00:05:55,650 --> 00:05:58,440
In instances where there is an unexpected interruption,

142
00:05:58,440 --> 00:06:01,110
the file system can actually quickly recover itself

143
00:06:01,110 --> 00:06:03,300
through journaling because it records changes

144
00:06:03,300 --> 00:06:04,980
to those files that have not been made

145
00:06:04,980 --> 00:06:08,370
to the file system yet inside of this Inode.

146
00:06:08,370 --> 00:06:10,410
The journaling process involves describing

147
00:06:10,410 --> 00:06:12,900
all the changes that must be made to the drive,

148
00:06:12,900 --> 00:06:14,220
the background processing,

149
00:06:14,220 --> 00:06:16,350
performing pending changes when rebooting,

150
00:06:16,350 --> 00:06:18,990
and discarding incomplete entries.

151
00:06:18,990 --> 00:06:21,060
Another type of file system you need to be aware of

152
00:06:21,060 --> 00:06:24,960
is known as a Virtual File System or VFS.

153
00:06:24,960 --> 00:06:27,240
A Virtual File System is going to be created

154
00:06:27,240 --> 00:06:29,490
as a common software interface that sits

155
00:06:29,490 --> 00:06:32,250
between the kernel and the real file system.

156
00:06:32,250 --> 00:06:34,740
In effect, the VFS is going to translate

157
00:06:34,740 --> 00:06:37,890
a real file systems details over to the kernel.

158
00:06:37,890 --> 00:06:40,560
That way, the file system appears to be identical

159
00:06:40,560 --> 00:06:42,360
to any other file system.

160
00:06:42,360 --> 00:06:44,940
With VFS, you can mount many different types

161
00:06:44,940 --> 00:06:47,550
of file systems on the same Linux installation,

162
00:06:47,550 --> 00:06:49,950
and they're all going to appear uniform to the user

163
00:06:49,950 --> 00:06:52,350
and all the applications on that system.

164
00:06:52,350 --> 00:06:54,180
File system labels are going to be assigned

165
00:06:54,180 --> 00:06:57,810
to those file systems for easy identification by VFS.

166
00:06:57,810 --> 00:07:00,780
These labels may be up to 16 characters long,

167
00:07:00,780 --> 00:07:02,580
and they can be displayed or changed

168
00:07:02,580 --> 00:07:06,210
using the e2label command for ext-based file systems,

169
00:07:06,210 --> 00:07:11,210
and the xfs_admin command for XFS-based file systems.

170
00:07:11,280 --> 00:07:13,140
The first task in managing storage

171
00:07:13,140 --> 00:07:14,820
is to partition a storage device

172
00:07:14,820 --> 00:07:18,000
and format the partition with one of these file systems.

173
00:07:18,000 --> 00:07:19,560
This will make the section of the device

174
00:07:19,560 --> 00:07:21,930
available for reading and writing of the data

175
00:07:21,930 --> 00:07:23,820
once you've formatted it.

176
00:07:23,820 --> 00:07:25,350
When I use the term, partition,

177
00:07:25,350 --> 00:07:28,110
this simply means it's a section of the storage drive

178
00:07:28,110 --> 00:07:30,840
that is logically acting as a separate drive.

179
00:07:30,840 --> 00:07:32,760
It enables you to convert a large drive

180
00:07:32,760 --> 00:07:34,980
into smaller, more manageable chunks

181
00:07:34,980 --> 00:07:37,920
leading to a better organization of your data.

182
00:07:37,920 --> 00:07:40,140
There are three types of partitions you can use

183
00:07:40,140 --> 00:07:42,390
and each one has specific features.

184
00:07:42,390 --> 00:07:43,980
We have primary partitions,

185
00:07:43,980 --> 00:07:47,160
extended partitions, and logical partitions.

186
00:07:47,160 --> 00:07:50,850
Primary partitions contain one file system or logical drive,

187
00:07:50,850 --> 00:07:53,460
and it's sometimes referred to as a volume.

188
00:07:53,460 --> 00:07:55,800
The swap file system and the boot partition

189
00:07:55,800 --> 00:07:58,620
are normally created in the primary partition.

190
00:07:58,620 --> 00:08:01,380
Linux likes to push some of its unused files from RAM

191
00:08:01,380 --> 00:08:04,680
to the swap space to free up actual physical memory,

192
00:08:04,680 --> 00:08:06,990
this goes to what we call the swap space.

193
00:08:06,990 --> 00:08:10,290
This swap space is simply a partition on the storage device

194
00:08:10,290 --> 00:08:12,000
that's going to be used when the system runs out

195
00:08:12,000 --> 00:08:14,700
of physical RAM or physical memory.

196
00:08:14,700 --> 00:08:16,530
An extended partition can contain

197
00:08:16,530 --> 00:08:18,450
several file systems as well,

198
00:08:18,450 --> 00:08:21,180
these are referred to as logical drives.

199
00:08:21,180 --> 00:08:23,910
This partition type does not contain any data,

200
00:08:23,910 --> 00:08:26,280
and it has a separate partition table.

201
00:08:26,280 --> 00:08:29,280
The logical partition is a part of the physical drive

202
00:08:29,280 --> 00:08:30,510
that's been partitioned off

203
00:08:30,510 --> 00:08:32,610
and allocated as an independent unit

204
00:08:32,610 --> 00:08:35,010
and functions as a separate drive.

205
00:08:35,010 --> 00:08:36,210
There's also going to be times

206
00:08:36,210 --> 00:08:38,400
when you need to create a new partition table

207
00:08:38,400 --> 00:08:41,610
or modify existing entries on the partition table,

208
00:08:41,610 --> 00:08:44,820
to do this, you're going to use the fdisk utility.

209
00:08:44,820 --> 00:08:47,370
This is a text-based, menu-driven program

210
00:08:47,370 --> 00:08:49,050
that's used to create, modify,

211
00:08:49,050 --> 00:08:52,200
or delete partitions on a given storage drive.

212
00:08:52,200 --> 00:08:54,180
Fdisk will also enable you to specify

213
00:08:54,180 --> 00:08:56,580
the size of those partitions.

214
00:08:56,580 --> 00:08:59,940
The fdisk utility supports a number of command line options

215
00:08:59,940 --> 00:09:02,430
including things like option -b.

216
00:09:02,430 --> 00:09:05,550
If you use option -b and then the sector size,

217
00:09:05,550 --> 00:09:08,730
you're going to be able to specify the number of drive sectors.

218
00:09:08,730 --> 00:09:11,400
If you use option -H, heads,

219
00:09:11,400 --> 00:09:14,490
this will be used to specify the number of drive heads.

220
00:09:14,490 --> 00:09:17,010
If you use option -S, sectors,

221
00:09:17,010 --> 00:09:18,450
this is going to be used to specify

222
00:09:18,450 --> 00:09:20,430
the number of sectors per track.

223
00:09:20,430 --> 00:09:23,400
If you use option -s, with a lowercase s,

224
00:09:23,400 --> 00:09:25,350
and then the partition, this will be used

225
00:09:25,350 --> 00:09:28,410
to print out the partition size in blocks.

226
00:09:28,410 --> 00:09:30,870
The option -l is going to be used to list

227
00:09:30,870 --> 00:09:33,870
all the partition tables for a given device.

228
00:09:33,870 --> 00:09:36,360
Aside from supplying different command line options,

229
00:09:36,360 --> 00:09:38,220
you can also choose various options

230
00:09:38,220 --> 00:09:40,770
when you're working in the fdisk menu itself

231
00:09:40,770 --> 00:09:45,770
including the options of N, D, P, W, and Q.

232
00:09:46,110 --> 00:09:49,380
Option N is going to be used to create new partitions.

233
00:09:49,380 --> 00:09:50,970
Option D is going to be used

234
00:09:50,970 --> 00:09:53,130
to delete or remove a partition.

235
00:09:53,130 --> 00:09:56,400
Option P is used to list out the existing partitions,

236
00:09:56,400 --> 00:09:58,920
almost like a print-to-screen function.

237
00:09:58,920 --> 00:10:01,650
Option W is going to be used to write the changes

238
00:10:01,650 --> 00:10:04,140
to the drive and exit the utility.

239
00:10:04,140 --> 00:10:07,350
Option Q is going to be used to cancel the changes made

240
00:10:07,350 --> 00:10:09,480
and exit the utility as well.

241
00:10:09,480 --> 00:10:10,980
Now, in addition to fdisk,

242
00:10:10,980 --> 00:10:14,250
there's another utility we can use to manage our partitions,

243
00:10:14,250 --> 00:10:17,697
this is known as the GNU Parted command.

244
00:10:17,697 --> 00:10:20,820
The GNU Parted command is going to be particularly useful

245
00:10:20,820 --> 00:10:23,700
when you're creating partitions on new storage drives.

246
00:10:23,700 --> 00:10:25,350
This tool can be used to create,

247
00:10:25,350 --> 00:10:27,900
destroy, and resize partitions.

248
00:10:27,900 --> 00:10:31,290
The Parted command runs the GNU Parted utility,

249
00:10:31,290 --> 00:10:32,790
and just like fdisk,

250
00:10:32,790 --> 00:10:35,490
Parted includes a menu-driven interactive mode

251
00:10:35,490 --> 00:10:37,590
where you can input various options.

252
00:10:37,590 --> 00:10:39,360
The option, select, is going to be used

253
00:10:39,360 --> 00:10:42,540
to choose which device or partition you want to modify.

254
00:10:42,540 --> 00:10:45,810
The option, mkpart, is going to be used to create a partition

255
00:10:45,810 --> 00:10:49,560
or make a partition with a specific file system type.

256
00:10:49,560 --> 00:10:51,240
Option, print, is going to be used

257
00:10:51,240 --> 00:10:53,910
to list out the partition table to the screen.

258
00:10:53,910 --> 00:10:56,730
Option, resizepart, is going to be used to resize

259
00:10:56,730 --> 00:10:59,910
or modify the end position of a given partition.

260
00:10:59,910 --> 00:11:02,850
Option, rm, is going to be used to delete a partition.

261
00:11:02,850 --> 00:11:04,650
And option, quit, is going to be used

262
00:11:04,650 --> 00:11:07,560
to exit the GNU Parted utility.

263
00:11:07,560 --> 00:11:09,090
After you create a partition,

264
00:11:09,090 --> 00:11:11,550
you can't add a file system to that partition

265
00:11:11,550 --> 00:11:14,790
unless the kernel can read it from the partition table.

266
00:11:14,790 --> 00:11:16,980
So, instead of rebooting the system,

267
00:11:16,980 --> 00:11:19,650
it's better to run the command, partprobe,

268
00:11:19,650 --> 00:11:23,100
after you run fdisk or the Parted command.

269
00:11:23,100 --> 00:11:25,140
If you do this, it makes the kernel aware

270
00:11:25,140 --> 00:11:28,320
of your new partition configurations that you just made.

271
00:11:28,320 --> 00:11:30,150
The partprobe command is going to be used

272
00:11:30,150 --> 00:11:31,920
to update the kernel with the changes

273
00:11:31,920 --> 00:11:34,650
that now exist within the given partition table.

274
00:11:34,650 --> 00:11:36,810
The command first checks the partition table,

275
00:11:36,810 --> 00:11:38,040
and if there's any changes,

276
00:11:38,040 --> 00:11:41,490
it automatically updates the kernel with those changes.

277
00:11:41,490 --> 00:11:43,140
Another important command to know

278
00:11:43,140 --> 00:11:47,970
is the make file system command which is written as mkfs.

279
00:11:47,970 --> 00:11:51,630
The mkfs command is used to build a Linux file system

280
00:11:51,630 --> 00:11:55,650
on a device which is normally going to be a drive partition.

281
00:11:55,650 --> 00:11:57,270
We're going to talk about some of the options

282
00:11:57,270 --> 00:11:59,160
of the mkfs command here,

283
00:11:59,160 --> 00:12:01,110
and give you some of their basic descriptions.

284
00:12:01,110 --> 00:12:04,740
If you want to learn more, you can always type, man mkfs,

285
00:12:04,740 --> 00:12:07,470
at your command prompt and learn more about it.

286
00:12:07,470 --> 00:12:10,560
First, we have option -v,

287
00:12:10,560 --> 00:12:12,810
this is used to produce verbose output

288
00:12:12,810 --> 00:12:14,820
where the output message is going to keep updating

289
00:12:14,820 --> 00:12:17,460
constantly as the program is processing.

290
00:12:17,460 --> 00:12:20,580
If instead you use option -V,

291
00:12:20,580 --> 00:12:22,680
this will produce verbose output as well,

292
00:12:22,680 --> 00:12:25,860
but it'll also include all the file system specific commands

293
00:12:25,860 --> 00:12:27,750
that are being executed.

294
00:12:27,750 --> 00:12:31,470
If you use option -t and the file system type,

295
00:12:31,470 --> 00:12:33,630
you're going to be specifying the type of file system

296
00:12:33,630 --> 00:12:35,760
you want built on this computer.

297
00:12:35,760 --> 00:12:39,630
If you use option, fs -options, it's going to be used to pass

298
00:12:39,630 --> 00:12:43,560
the file system specific options to the file system builder.

299
00:12:43,560 --> 00:12:46,980
If you use option -c, it's going to be used to check the device

300
00:12:46,980 --> 00:12:50,460
for any bad blocks before it builds the file system.

301
00:12:50,460 --> 00:12:53,250
If you use option -l and the file name,

302
00:12:53,250 --> 00:12:54,690
it's going to actually read the list

303
00:12:54,690 --> 00:12:56,940
of bad blocks from a specified file

304
00:12:56,940 --> 00:12:59,220
that you've already run this command against.

305
00:12:59,220 --> 00:13:01,950
So, when it comes down to the make file system command,

306
00:13:01,950 --> 00:13:03,780
there's really two ways to run it.

307
00:13:03,780 --> 00:13:07,770
The first is to type mkfs, set up your options,

308
00:13:07,770 --> 00:13:09,480
and then enter your device name.

309
00:13:09,480 --> 00:13:14,160
The second way is to use mkfs putting your file system type,

310
00:13:14,160 --> 00:13:16,113
your options, and the device name.

311
00:13:17,220 --> 00:13:20,940
Another thing we need to cover is the fstab file.

312
00:13:20,940 --> 00:13:23,850
The fstab file is a configuration file

313
00:13:23,850 --> 00:13:27,120
that stores information about storage devices and partitions

314
00:13:27,120 --> 00:13:30,150
and where and how those partitions should be mounted.

315
00:13:30,150 --> 00:13:34,740
The fstab file is going to be located in the /etc directory.

316
00:13:34,740 --> 00:13:37,620
It's going to be read by the system during the boot up process

317
00:13:37,620 --> 00:13:40,560
and it can be edited only by your root user.

318
00:13:40,560 --> 00:13:43,620
The fstab file consists of a number of lines,

319
00:13:43,620 --> 00:13:46,710
one for each file system that the system knows about.

320
00:13:46,710 --> 00:13:48,360
Each line has six fields

321
00:13:48,360 --> 00:13:51,360
that are going to be separated by spaces or tabs.

322
00:13:51,360 --> 00:13:54,150
The first field is the Device or Partition Name,

323
00:13:54,150 --> 00:13:55,770
and it specifies the name of the device

324
00:13:55,770 --> 00:13:57,900
or file system that you want to mount.

325
00:13:57,900 --> 00:13:59,550
The Default Mount Point indicates

326
00:13:59,550 --> 00:14:01,890
where the file system is going to be mounted,

327
00:14:01,890 --> 00:14:03,480
so it might be, slash,

328
00:14:03,480 --> 00:14:05,970
for the root file system as an example.

329
00:14:05,970 --> 00:14:08,160
The File System Type will also specify

330
00:14:08,160 --> 00:14:11,760
the type of file system used by that device or partition.

331
00:14:11,760 --> 00:14:14,070
The Mount Options field specifies a set

332
00:14:14,070 --> 00:14:16,890
of comma-separated options that will be activated

333
00:14:16,890 --> 00:14:18,990
when the file system is mounted.

334
00:14:18,990 --> 00:14:20,820
The Dump Options field indicates

335
00:14:20,820 --> 00:14:23,970
if the Dump utility should back up the file system.

336
00:14:23,970 --> 00:14:26,910
The fsck Options field will specify the order

337
00:14:26,910 --> 00:14:30,840
in which the fsck utility or the File System Checker utility

338
00:14:30,840 --> 00:14:32,970
should check the file system.

339
00:14:32,970 --> 00:14:34,620
Another file we need to talk about

340
00:14:34,620 --> 00:14:36,810
is located in the /etc directory

341
00:14:36,810 --> 00:14:41,493
and it's known as C-R-Y-P-T-T-A-B, or crypttab.

342
00:14:42,749 --> 00:14:45,330
The /etc/crypttab file performs

343
00:14:45,330 --> 00:14:47,850
a similar function to the fstab file,

344
00:14:47,850 --> 00:14:50,220
but its purpose is to store information

345
00:14:50,220 --> 00:14:52,380
about encrypted devices and partitions

346
00:14:52,380 --> 00:14:55,530
that have to be unlocked and mounted on system boot.

347
00:14:55,530 --> 00:14:58,470
Its format is going to be similar to the fstab file,

348
00:14:58,470 --> 00:15:00,690
but it includes an optional password field

349
00:15:00,690 --> 00:15:03,540
for unlocking encrypted devices.

350
00:15:03,540 --> 00:15:05,910
As we've talked about all these different utilities,

351
00:15:05,910 --> 00:15:07,680
the overall process of setting up

352
00:15:07,680 --> 00:15:10,020
storage devices for use on Linux machines

353
00:15:10,020 --> 00:15:12,960
includes just a few key things you need to do.

354
00:15:12,960 --> 00:15:15,570
First, you need to partition the storage device

355
00:15:15,570 --> 00:15:18,240
using a tool like fdisk or Parted.

356
00:15:18,240 --> 00:15:21,840
Then, you need to format the partition using a file system,

357
00:15:21,840 --> 00:15:23,040
and this will be done using something

358
00:15:23,040 --> 00:15:26,760
like mkfs or the Make File System tool.

359
00:15:26,760 --> 00:15:29,460
Then, you need to add the format of partition

360
00:15:29,460 --> 00:15:31,890
to the fstab file so it can be configured

361
00:15:31,890 --> 00:15:34,320
by the system to run at boot up.

362
00:15:34,320 --> 00:15:37,290
In Linux, everything is going to be treated as a file,

363
00:15:37,290 --> 00:15:41,250
even a directory or an entire disk volume or partition.

364
00:15:41,250 --> 00:15:43,500
When you look at a file system, you're going to see it

365
00:15:43,500 --> 00:15:48,115
written out as a directory known as /dev, for device.

366
00:15:48,115 --> 00:15:50,700
A /dev directory is a special file

367
00:15:50,700 --> 00:15:52,740
that contains details about all the files

368
00:15:52,740 --> 00:15:55,320
and subdirectories that are housed within it.

369
00:15:55,320 --> 00:15:57,030
Linux uses naming conventions

370
00:15:57,030 --> 00:16:00,150
so that storage devices are easily located by the system

371
00:16:00,150 --> 00:16:02,850
whenever they're attached and when the system boots up.

372
00:16:02,850 --> 00:16:05,040
For storage devices, the naming convention

373
00:16:05,040 --> 00:16:07,590
is typically expressed in three parts,

374
00:16:07,590 --> 00:16:09,270
let's take a look at an example.

375
00:16:09,270 --> 00:16:13,680
If I have a device called /dev/sda1,

376
00:16:13,680 --> 00:16:16,560
this actually tells me a lot about this device.

377
00:16:16,560 --> 00:16:19,020
The first part of that, the sd portion,

378
00:16:19,020 --> 00:16:20,583
refers to the specific type of controller

379
00:16:20,583 --> 00:16:22,830
that that device is using.

380
00:16:22,830 --> 00:16:24,720
The second portion, the a,

381
00:16:24,720 --> 00:16:27,120
is going to refer to the first whole drive

382
00:16:27,120 --> 00:16:30,030
because, a, is the first letter of the alphabet.

383
00:16:30,030 --> 00:16:32,400
Then, if we had a second drive, it would be b,

384
00:16:32,400 --> 00:16:35,580
if we had a third drive, it would be c, and so on.

385
00:16:35,580 --> 00:16:37,890
The third part of this is the number one,

386
00:16:37,890 --> 00:16:39,030
and the number one refers

387
00:16:39,030 --> 00:16:41,250
to the first partition on this drive.

388
00:16:41,250 --> 00:16:43,740
If we had two partitions or three partitions,

389
00:16:43,740 --> 00:16:46,080
we would have a two or a three here.

390
00:16:46,080 --> 00:16:50,340
So, when I have something like /dev/sda1,

391
00:16:50,340 --> 00:16:52,890
we know we have the first storage device

392
00:16:52,890 --> 00:16:55,620
and the first partition on that storage device

393
00:16:55,620 --> 00:16:57,603
because it is sda1.

394
00:16:58,620 --> 00:17:00,810
In addition to using this naming convention,

395
00:17:00,810 --> 00:17:03,630
Linux also has several different persistent naming schemes

396
00:17:03,630 --> 00:17:05,640
to help us identify devices.

397
00:17:05,640 --> 00:17:08,190
Controller-based naming can sometimes be problematic

398
00:17:08,190 --> 00:17:11,520
in systems with more than one type of the same controller.

399
00:17:11,520 --> 00:17:15,030
So, instead, we can use a persistent naming scheme

400
00:17:15,030 --> 00:17:17,910
to overcome this and make it more predictable.

401
00:17:17,910 --> 00:17:20,010
If I'm using a persistent naming scheme

402
00:17:20,010 --> 00:17:22,589
that's based on the device's hardware serial number,

403
00:17:22,589 --> 00:17:27,589
I'm going to do this by using /dev/disk/ID number.

404
00:17:28,170 --> 00:17:30,240
If I'm using a persistent naming scheme

405
00:17:30,240 --> 00:17:31,530
that refers to an identifier

406
00:17:31,530 --> 00:17:34,050
based on the shortest physical path to the device,

407
00:17:34,050 --> 00:17:39,050
I might use something like /dev/disk/path.

408
00:17:39,120 --> 00:17:41,880
Finally, if I'm going to use a persistent naming scheme

409
00:17:41,880 --> 00:17:45,660
based on the universally unique identifier, or UUID,

410
00:17:45,660 --> 00:17:50,660
I would write this as /dev/disk/UUID.

411
00:17:50,730 --> 00:17:53,580
And this would refer to that universal unique identifier

412
00:17:53,580 --> 00:17:54,720
that's assigned to the device

413
00:17:54,720 --> 00:17:57,000
when the file system was first created on it.

414
00:17:57,000 --> 00:17:58,380
The last thing we need to discuss

415
00:17:58,380 --> 00:17:59,790
is some special character devices

416
00:17:59,790 --> 00:18:02,280
that exist under the /dev directory.

417
00:18:02,280 --> 00:18:07,280
This includes a /dev/null, /dev/zero, and /dev/urandom.

418
00:18:08,340 --> 00:18:10,200
As I mentioned earlier in this lesson,

419
00:18:10,200 --> 00:18:12,030
everything in Linux is created as a file

420
00:18:12,030 --> 00:18:13,980
and mounted on the file system.

421
00:18:13,980 --> 00:18:15,480
Just like we can mount a hard drive

422
00:18:15,480 --> 00:18:18,630
to the /dev/sda1 directory in the file system

423
00:18:18,630 --> 00:18:20,130
in order to interact with it,

424
00:18:20,130 --> 00:18:23,026
we can also use things like /dev/null,

425
00:18:23,026 --> 00:18:26,340
and /dev/zero, and /dev/urandom

426
00:18:26,340 --> 00:18:28,020
which are special character devices

427
00:18:28,020 --> 00:18:31,050
that are installed by default in most Linux distributions.

428
00:18:31,050 --> 00:18:33,870
And each of these are used for a specific purpose.

429
00:18:33,870 --> 00:18:36,450
The /dev/null special character device

430
00:18:36,450 --> 00:18:38,370
is a special type of virtual device

431
00:18:38,370 --> 00:18:39,870
that allows you to discard anything

432
00:18:39,870 --> 00:18:42,480
that you send to it or redirect into it.

433
00:18:42,480 --> 00:18:45,810
Think of the /dev/null as a big black hole,

434
00:18:45,810 --> 00:18:47,670
and any data streams or character streams

435
00:18:47,670 --> 00:18:50,220
that you don't want to deal with or save to a file,

436
00:18:50,220 --> 00:18:53,460
you can simply redirect those into the /dev/null

437
00:18:53,460 --> 00:18:55,380
and it's going to disappear forever.

438
00:18:55,380 --> 00:18:58,140
If you try to read from the /dev/null device,

439
00:18:58,140 --> 00:19:00,450
you're simply going to receive an End of File message

440
00:19:00,450 --> 00:19:02,700
because you've effectively reached the end of that file

441
00:19:02,700 --> 00:19:06,270
because that file is always empty and contains nothing.

442
00:19:06,270 --> 00:19:08,910
The /dev/zero special character device

443
00:19:08,910 --> 00:19:11,550
is going to be used as a special type of virtual device

444
00:19:11,550 --> 00:19:14,700
that'll return a null character anytime you read from it.

445
00:19:14,700 --> 00:19:17,970
If you redirect the output to the /dev/zero device,

446
00:19:17,970 --> 00:19:19,170
it is going to discard the data

447
00:19:19,170 --> 00:19:21,870
just like the /dev/null device did.

448
00:19:21,870 --> 00:19:23,520
But the big difference is,

449
00:19:23,520 --> 00:19:26,190
when you try to read from /dev/zero,

450
00:19:26,190 --> 00:19:29,550
it's going to act differently than /dev/null did.

451
00:19:29,550 --> 00:19:32,310
You're not going to get that End of File back immediately.

452
00:19:32,310 --> 00:19:34,050
But instead, it's going to send you back

453
00:19:34,050 --> 00:19:39,050
the ASCII null character of the hexadecimal value of 0x00.

454
00:19:39,750 --> 00:19:43,350
Why might you use /dev/zero if all it does is send you back

455
00:19:43,350 --> 00:19:46,260
an endless stream of zeros whenever you read from it?

456
00:19:46,260 --> 00:19:47,910
Well, this is actually useful

457
00:19:47,910 --> 00:19:49,770
when you're trying to sanitize a hard drive

458
00:19:49,770 --> 00:19:52,110
by overriding it with a bunch of zeros.

459
00:19:52,110 --> 00:19:54,870
To do this, you can simply use the dd command

460
00:19:54,870 --> 00:19:56,850
which stands for disk duplicator.

461
00:19:56,850 --> 00:20:01,850
You enter, dd if=/dev/zero of=dev/sda1 bs=1GB count=1024.

462
00:20:12,300 --> 00:20:15,690
And this command will overwrite a one-terabyte hard disk

463
00:20:15,690 --> 00:20:18,810
that is mounted as sda1 with a series of zeros

464
00:20:18,810 --> 00:20:22,650
across the entire drive for the entire one terabyte in size

465
00:20:22,650 --> 00:20:25,890
using block sizes of one gigabyte each.

466
00:20:25,890 --> 00:20:27,150
The next special character device

467
00:20:27,150 --> 00:20:29,163
we need to discuss is the /dev/urandom,

468
00:20:30,882 --> 00:20:34,590
/dev/urandom is a special type of virtual device

469
00:20:34,590 --> 00:20:37,770
that'll return a randomized series of pseudorandom numbers.

470
00:20:37,770 --> 00:20:39,360
For example, if you're creating

471
00:20:39,360 --> 00:20:40,947
a program or a script on a Linux system,

472
00:20:40,947 --> 00:20:43,530
and you want to generate random numbers for something

473
00:20:43,530 --> 00:20:45,480
like determining which side of a rolled dice

474
00:20:45,480 --> 00:20:47,250
would be returned by your program,

475
00:20:47,250 --> 00:20:50,730
you can use /dev/urandom to do that.

476
00:20:50,730 --> 00:20:52,590
For example, let's say I wanted to get

477
00:20:52,590 --> 00:20:54,150
five random characters.

478
00:20:54,150 --> 00:20:59,150
I can enter, head -c5 /dev/urandom,

479
00:20:59,730 --> 00:21:00,960
and then hit Enter.

480
00:21:00,960 --> 00:21:02,850
This will return five random characters

481
00:21:02,850 --> 00:21:07,260
from that special character device called /dev/urandom.

482
00:21:07,260 --> 00:21:09,540
As you can see, there are multiple different ways for us

483
00:21:09,540 --> 00:21:12,690
to reference block and character devices on a Linux system

484
00:21:12,690 --> 00:21:14,440
depending on what your use case is.

