1
00:00:00,810 --> 00:00:01,830
In this lesson,

2
00:00:01,830 --> 00:00:04,590
we're going to discuss how to manage file systems

3
00:00:04,590 --> 00:00:06,180
including all the tools available

4
00:00:06,180 --> 00:00:09,720
in the Linux environment to accomplish practical tasks.

5
00:00:09,720 --> 00:00:11,280
Now to manage our file systems,

6
00:00:11,280 --> 00:00:14,280
we're going to use lots of different files and configurations.

7
00:00:14,280 --> 00:00:15,600
For example, we're going to start

8
00:00:15,600 --> 00:00:19,230
by discussing the /etc/mtab file.

9
00:00:19,230 --> 00:00:20,610
This file is very similar

10
00:00:20,610 --> 00:00:23,190
to the /proc/mounts file

11
00:00:23,190 --> 00:00:24,630
in the way it reports the status

12
00:00:24,630 --> 00:00:26,760
of currently mounted file systems.

13
00:00:26,760 --> 00:00:31,050
However, the /proc/mounts file is typically more accurate

14
00:00:31,050 --> 00:00:32,670
and includes more up to date information

15
00:00:32,670 --> 00:00:37,670
about the file systems than does the /etc/mtab file.

16
00:00:37,830 --> 00:00:42,090
The /proc/partitions file is part of the virtual file system

17
00:00:42,090 --> 00:00:44,970
that contains information about each and every partition

18
00:00:44,970 --> 00:00:47,130
that is currently attached to the system.

19
00:00:47,130 --> 00:00:51,510
The format of the /proc/partition file contains columns

20
00:00:51,510 --> 00:00:54,120
including things like major, minor,

21
00:00:54,120 --> 00:00:56,160
number of blocks and name.

22
00:00:56,160 --> 00:00:58,770
The major column represents the class of device,

23
00:00:58,770 --> 00:01:01,260
so that it can be mapped to an appropriate driver.

24
00:01:01,260 --> 00:01:04,860
The minor column separates partitions into physical devices,

25
00:01:04,860 --> 00:01:06,900
while the number of blocks column refers

26
00:01:06,900 --> 00:01:08,280
to the number of physical blocks

27
00:01:08,280 --> 00:01:09,990
that the partition takes up.

28
00:01:09,990 --> 00:01:13,470
And the name column refers to the name of the partition.

29
00:01:13,470 --> 00:01:16,920
Another command we can look at is the LS block column.

30
00:01:16,920 --> 00:01:19,740
Now lsblk is the command that's going to be used

31
00:01:19,740 --> 00:01:22,890
to display all the information about block storage devices

32
00:01:22,890 --> 00:01:25,560
that are currently available on the given system.

33
00:01:25,560 --> 00:01:27,090
The output is going to be displayed

34
00:01:27,090 --> 00:01:29,730
in a tree-like format with each physical disk

35
00:01:29,730 --> 00:01:31,830
at the top of the tree and each partition

36
00:01:31,830 --> 00:01:35,010
or logical volume branching off from that device.

37
00:01:35,010 --> 00:01:37,950
The information displayed here is going to include the names,

38
00:01:37,950 --> 00:01:41,370
the major and minor numbers, the size, the device type,

39
00:01:41,370 --> 00:01:42,630
and the mount point.

40
00:01:42,630 --> 00:01:46,680
The proper way to use this command is to type lsblk,

41
00:01:46,680 --> 00:01:49,050
the options, and then the device name.

42
00:01:49,050 --> 00:01:50,730
There are lots of options in this command

43
00:01:50,730 --> 00:01:53,310
that you can choose from depending on your needs.

44
00:01:53,310 --> 00:01:55,860
For example, if you use the -a option,

45
00:01:55,860 --> 00:01:57,510
it's going to list out empty devices,

46
00:01:57,510 --> 00:02:00,150
as well as devices that have files on them.

47
00:02:00,150 --> 00:02:01,830
If you use the -r option,

48
00:02:01,830 --> 00:02:03,900
the device list is going to exclude devices

49
00:02:03,900 --> 00:02:05,490
from the output that you provide

50
00:02:05,490 --> 00:02:08,729
as a list of comma separated, major device numbers.

51
00:02:08,729 --> 00:02:10,350
If you use the -f option,

52
00:02:10,350 --> 00:02:12,960
it's going to display additional system information.

53
00:02:12,960 --> 00:02:14,880
Whereas if you use the -l option,

54
00:02:14,880 --> 00:02:17,520
it's going to display your results in a list format.

55
00:02:17,520 --> 00:02:20,040
And finally, if you use the -m option,

56
00:02:20,040 --> 00:02:21,720
it's going to display permission information

57
00:02:21,720 --> 00:02:23,610
for all of your devices.

58
00:02:23,610 --> 00:02:26,370
Another command we can look at is the block ID

59
00:02:26,370 --> 00:02:28,890
or blkid command.

60
00:02:28,890 --> 00:02:32,100
This offers similar functionality to lsblk,

61
00:02:32,100 --> 00:02:34,800
but it simply prints out each block device

62
00:02:34,800 --> 00:02:38,010
in a flat format and includes some additional information

63
00:02:38,010 --> 00:02:40,350
like the device in partitioning UUID

64
00:02:40,350 --> 00:02:42,150
and the file system type.

65
00:02:42,150 --> 00:02:46,920
However, normally I like to use it as lsblk-f

66
00:02:46,920 --> 00:02:48,690
if you want this type of information

67
00:02:48,690 --> 00:02:51,300
instead of using blkid,

68
00:02:51,300 --> 00:02:54,060
but if you want to use blkid, you can do that

69
00:02:54,060 --> 00:02:58,710
by entering in blkid, the options, and the device name.

70
00:02:58,710 --> 00:03:01,590
Now, when it comes to managing file systems and partitions,

71
00:03:01,590 --> 00:03:03,540
some tools are designed to only work

72
00:03:03,540 --> 00:03:06,180
with specific file system types like FAT

73
00:03:06,180 --> 00:03:10,950
or EXT or NTFS or XFS or something like that.

74
00:03:10,950 --> 00:03:13,170
Now, some of these can work with multiple types

75
00:03:13,170 --> 00:03:16,470
or all types, but some specific tools work better

76
00:03:16,470 --> 00:03:18,450
for specific file systems.

77
00:03:18,450 --> 00:03:20,730
If you're going to work with the EXT file system,

78
00:03:20,730 --> 00:03:22,470
which is the default on Linux,

79
00:03:22,470 --> 00:03:24,180
there are several tools that you can use

80
00:03:24,180 --> 00:03:27,750
on essentially any generation of the EXT file system type,

81
00:03:27,750 --> 00:03:30,900
whether it's ext2, three, or four.

82
00:03:30,900 --> 00:03:32,670
Some of the most common and useful tools

83
00:03:32,670 --> 00:03:36,965
for managing EXT file systems include e2fsck,

84
00:03:36,965 --> 00:03:40,983
resize2fs, tune2fs, and dumpe2fs.

85
00:03:42,300 --> 00:03:45,060
At any times, a file system error can occur

86
00:03:45,060 --> 00:03:47,310
due to a power failure, a hardware failure,

87
00:03:47,310 --> 00:03:49,500
or an improper shutdown of your system.

88
00:03:49,500 --> 00:03:53,370
If this happens, you're going to use the fsck command.

89
00:03:53,370 --> 00:03:55,860
Now the fsck command is going to be used to check

90
00:03:55,860 --> 00:03:59,010
for the correctness and validity of a file system.

91
00:03:59,010 --> 00:04:01,830
Most systems automatically run the fsck command

92
00:04:01,830 --> 00:04:03,750
at boot time, so that any errors

93
00:04:03,750 --> 00:04:06,300
if they're found, can be detected and corrected

94
00:04:06,300 --> 00:04:08,160
before the system is used.

95
00:04:08,160 --> 00:04:10,170
A file system must be unmounted

96
00:04:10,170 --> 00:04:12,480
before it can be scanned with fsck

97
00:04:12,480 --> 00:04:14,580
to prevent damage to the file system.

98
00:04:14,580 --> 00:04:18,570
To run fsck, you're going to type fsck, the options,

99
00:04:18,570 --> 00:04:20,850
and the device or file system name.

100
00:04:20,850 --> 00:04:22,860
Sometimes a repair is going to be required

101
00:04:22,860 --> 00:04:25,710
in order to mount or modify a file system.

102
00:04:25,710 --> 00:04:27,540
Even if a check does not report any damage

103
00:04:27,540 --> 00:04:28,680
to the file system,

104
00:04:28,680 --> 00:04:30,780
it might still consider it damaged internally

105
00:04:30,780 --> 00:04:32,460
and require a repair.

106
00:04:32,460 --> 00:04:35,550
You can always use fsck-r

107
00:04:35,550 --> 00:04:38,880
and the device or file system name to repair a file system.

108
00:04:38,880 --> 00:04:41,100
However, this option should not be used

109
00:04:41,100 --> 00:04:44,520
when checking multiple file systems simultaneously.

110
00:04:44,520 --> 00:04:45,930
If you're a system administrator

111
00:04:45,930 --> 00:04:47,848
and you're working on a Linux system,

112
00:04:47,848 --> 00:04:50,040
resizing or growing a file system

113
00:04:50,040 --> 00:04:52,110
can be a challenging task for you.

114
00:04:52,110 --> 00:04:54,300
You're going to need to resize an existing partition

115
00:04:54,300 --> 00:04:57,000
when your partition gets full and you need more space.

116
00:04:57,000 --> 00:05:00,930
In that case, you can use something like resize2fs.

117
00:05:00,930 --> 00:05:03,000
This utility will allow you to increase

118
00:05:03,000 --> 00:05:05,700
or decrease a file system size.

119
00:05:05,700 --> 00:05:09,630
The resize2fs command allows you to resize ext2,

120
00:05:09,630 --> 00:05:12,900
ext3, or ext4 file systems.

121
00:05:12,900 --> 00:05:14,100
It can be used to enlarge

122
00:05:14,100 --> 00:05:17,910
or shrink an unmounted file system locate on a device.

123
00:05:17,910 --> 00:05:20,250
If the file system is mounted, it can be used

124
00:05:20,250 --> 00:05:22,500
to expand the size of the mounted file system,

125
00:05:22,500 --> 00:05:25,650
assuming the kernal supports online resizing.

126
00:05:25,650 --> 00:05:28,650
The size parameter is going to specify the requested new size

127
00:05:28,650 --> 00:05:30,210
of that file system.

128
00:05:30,210 --> 00:05:33,660
If no units are specified, the units of the size perimeter

129
00:05:33,660 --> 00:05:35,850
should be the file system block size

130
00:05:35,850 --> 00:05:37,440
for the entire file system,

131
00:05:37,440 --> 00:05:39,330
and it will use that by default.

132
00:05:39,330 --> 00:05:41,700
The size of the file system may never be larger

133
00:05:41,700 --> 00:05:43,620
than the size of the partition though.

134
00:05:43,620 --> 00:05:45,810
If the size perimeter is not specified,

135
00:05:45,810 --> 00:05:47,910
it's going to default to the size of the partition

136
00:05:47,910 --> 00:05:50,130
and fill up all remaining space.

137
00:05:50,130 --> 00:05:51,600
If you want to use this command,

138
00:05:51,600 --> 00:05:54,870
simply type resize2fs, the options,

139
00:05:54,870 --> 00:05:56,610
and the device or file system name

140
00:05:56,610 --> 00:05:59,370
and the desired size to be able to run this command

141
00:05:59,370 --> 00:06:01,380
and resize your partition.

142
00:06:01,380 --> 00:06:04,380
The next one we're going to talk about is tune2fs.

143
00:06:04,380 --> 00:06:06,810
This command is one of the advanced Linux commands

144
00:06:06,810 --> 00:06:09,330
that allows you to adjust various tuneable parameters

145
00:06:09,330 --> 00:06:12,630
to the ext2 and ext3 file systems.

146
00:06:12,630 --> 00:06:15,690
Tuneable parameters enable you to remove reserve blocks,

147
00:06:15,690 --> 00:06:17,340
alter reserve block counts,

148
00:06:17,340 --> 00:06:19,710
specify the number of mounts between checks,

149
00:06:19,710 --> 00:06:22,830
specify the time intervals between checks, and more.

150
00:06:22,830 --> 00:06:25,680
Naturally, it also helps you confirm the existing parameters

151
00:06:25,680 --> 00:06:27,720
configured for your file systems.

152
00:06:27,720 --> 00:06:30,540
You can also use tune2fs to add a journal

153
00:06:30,540 --> 00:06:34,230
to an existing ext2 or ext3 file system.

154
00:06:34,230 --> 00:06:36,090
If the file system is already mounted,

155
00:06:36,090 --> 00:06:37,200
the journal will be visible

156
00:06:37,200 --> 00:06:39,780
in the root directory of that file system.

157
00:06:39,780 --> 00:06:41,610
If the file system is not mounted,

158
00:06:41,610 --> 00:06:43,200
the journal will be hidden.

159
00:06:43,200 --> 00:06:45,300
To run the tune2fs command,

160
00:06:45,300 --> 00:06:48,090
you need to enter tune2fs, the options,

161
00:06:48,090 --> 00:06:50,100
and the device or file system name.

162
00:06:50,100 --> 00:06:53,220
The tune2fs command has various different options

163
00:06:53,220 --> 00:06:56,910
including -j, which is used as an ext3 journal

164
00:06:56,910 --> 00:06:58,710
to an existing file system.

165
00:06:58,710 --> 00:07:00,810
If you use -I, it's going to be used

166
00:07:00,810 --> 00:07:02,760
to specify the maximum time interval

167
00:07:02,760 --> 00:07:04,350
between file system checks,

168
00:07:04,350 --> 00:07:06,270
and you can give it the parameter of days,

169
00:07:06,270 --> 00:07:10,110
months or weeks using d, m, or w.

170
00:07:10,110 --> 00:07:13,050
If you use -c and the maximum mounts count,

171
00:07:13,050 --> 00:07:15,720
you can use this to specify the maximum number of mounts

172
00:07:15,720 --> 00:07:17,760
between file system checks.

173
00:07:17,760 --> 00:07:21,150
If you use the option -C and the mount count,

174
00:07:21,150 --> 00:07:23,250
it's going to be used to specify the number of times

175
00:07:23,250 --> 00:07:25,410
the file system can be mounted.

176
00:07:25,410 --> 00:07:28,710
If you use the option -r, reserve block counts,

177
00:07:28,710 --> 00:07:30,450
it's going to be used to specify the number

178
00:07:30,450 --> 00:07:32,520
of reserved file system blocks.

179
00:07:32,520 --> 00:07:35,580
If you use the option -e and the word continue,

180
00:07:35,580 --> 00:07:38,700
remountro, or panic, you're going to be able to specify

181
00:07:38,700 --> 00:07:40,470
the behavior of the kernel code,

182
00:07:40,470 --> 00:07:41,672
whether the file system should continue

183
00:07:41,672 --> 00:07:43,380
with normal execution,

184
00:07:43,380 --> 00:07:44,498
whether it should remount the file system

185
00:07:44,498 --> 00:07:46,080
in read-only mode,

186
00:07:46,080 --> 00:07:48,540
or whether it should cause a kernel panic

187
00:07:48,540 --> 00:07:50,550
whenever an error is detected.

188
00:07:50,550 --> 00:07:52,470
If you use the option -l,

189
00:07:52,470 --> 00:07:54,000
it's going to be used to list the contents

190
00:07:54,000 --> 00:07:56,430
within the superblock of the file system.

191
00:07:56,430 --> 00:08:00,720
And finally, if you use the option -u with the UUID,

192
00:08:00,720 --> 00:08:03,630
you can specify the UUID for the file system

193
00:08:03,630 --> 00:08:05,340
that you want set.

194
00:08:05,340 --> 00:08:08,700
A file system superblock is something that contains metadata

195
00:08:08,700 --> 00:08:11,550
about the file system including its size,

196
00:08:11,550 --> 00:08:13,530
its type, and its status.

197
00:08:13,530 --> 00:08:14,940
The superblock is critical

198
00:08:14,940 --> 00:08:17,040
to the function of the file system.

199
00:08:17,040 --> 00:08:19,650
If it becomes corrupted, you're going to be unable

200
00:08:19,650 --> 00:08:22,140
to mount and work with that file system.

201
00:08:22,140 --> 00:08:25,020
So, you need to use a tool like fsck

202
00:08:25,020 --> 00:08:28,110
to repair the superblock if it becomes corrupted.

203
00:08:28,110 --> 00:08:31,860
Another command that we need to talk about is dumpe2fs.

204
00:08:31,860 --> 00:08:35,010
Now dumpe2fs is using a Linux system

205
00:08:35,010 --> 00:08:39,870
that allows you to dump the ext2, ext3, or ext4 data.

206
00:08:39,870 --> 00:08:41,460
It'll actually print the superblock

207
00:08:41,460 --> 00:08:44,610
and the block group information for your selected device.

208
00:08:44,610 --> 00:08:46,260
This can be useful when you're troubleshooting

209
00:08:46,260 --> 00:08:47,880
a faulty file system.

210
00:08:47,880 --> 00:08:51,660
To use it, just type dumpe2fs, the options,

211
00:08:51,660 --> 00:08:53,940
and the device or file system name.

212
00:08:53,940 --> 00:08:57,360
As you do this, the dumpe2fs command is going to have

213
00:08:57,360 --> 00:08:58,920
a lot of different options.

214
00:08:58,920 --> 00:09:01,320
For example, if you use -x,

215
00:09:01,320 --> 00:09:02,970
it's going to print a detailed report

216
00:09:02,970 --> 00:09:05,430
about block numbers in the file system.

217
00:09:05,430 --> 00:09:08,490
If you use -b, it's going to print out the bad blocks

218
00:09:08,490 --> 00:09:09,930
in that file system.

219
00:09:09,930 --> 00:09:13,290
If you use -f, it's going to be used to force the utility

220
00:09:13,290 --> 00:09:15,120
to display the file system status

221
00:09:15,120 --> 00:09:18,180
regardless of whether the file system flags are set or not.

222
00:09:18,180 --> 00:09:20,280
And if you use -i, it's going to be used

223
00:09:20,280 --> 00:09:21,870
to display the file system data

224
00:09:21,870 --> 00:09:25,740
from an image file created using the e2image command.

225
00:09:25,740 --> 00:09:28,260
Now just like our EXT file system types,

226
00:09:28,260 --> 00:09:29,760
there's also tools that allow you

227
00:09:29,760 --> 00:09:32,460
to work with XFS file system types.

228
00:09:32,460 --> 00:09:35,996
The XFS_info command is used to display details

229
00:09:35,996 --> 00:09:40,440
about the XFS file system including its block information.

230
00:09:40,440 --> 00:09:42,982
The XFS_admin command is used

231
00:09:42,982 --> 00:09:46,170
to change the parameters of an XFS file system

232
00:09:46,170 --> 00:09:48,960
including its label and its UUID.

233
00:09:48,960 --> 00:09:51,600
If you use XFS_metadump,

234
00:09:51,600 --> 00:09:54,090
it's going to be used to copy the superblock metadata

235
00:09:54,090 --> 00:09:57,300
of the XFS file system and put that in a file.

236
00:09:57,300 --> 00:10:01,110
If you use XFS_growfs, it's going to be used

237
00:10:01,110 --> 00:10:05,160
to expand the XFS file system to fill the drive size.

238
00:10:05,160 --> 00:10:09,420
If you use XFS_copy, it's going to be used to copy the contents

239
00:10:09,420 --> 00:10:12,750
of the XFS file system to another location.

240
00:10:12,750 --> 00:10:15,284
If you use XFS_repair it's going to be used to repair

241
00:10:15,284 --> 00:10:19,380
and recover a corrupt XFS file system.

242
00:10:19,380 --> 00:10:23,220
And finally, the XFS_db is going to be used

243
00:10:23,220 --> 00:10:26,100
to debug an XFS file system.

244
00:10:26,100 --> 00:10:29,850
Another you should be aware of is the lsscsi command,

245
00:10:29,850 --> 00:10:32,310
also known as the LS SCSI command.

246
00:10:32,310 --> 00:10:34,020
This command is used to list information

247
00:10:34,020 --> 00:10:37,080
about SCSI devices that are connected to a Linux system.

248
00:10:37,080 --> 00:10:38,970
The most common type of SCSI device used

249
00:10:38,970 --> 00:10:40,980
in Linux systems these days is storage

250
00:10:40,980 --> 00:10:42,540
and external hard disk drives,

251
00:10:42,540 --> 00:10:44,580
which is why I'm bringing it up here.

252
00:10:44,580 --> 00:10:48,540
If you simply enter lsscsi at the command line interface

253
00:10:48,540 --> 00:10:51,180
and hit Enter, it's can respond with one line

254
00:10:51,180 --> 00:10:53,880
for each SCSI device attached to your system.

255
00:10:53,880 --> 00:10:55,440
For example, it can tell you

256
00:10:55,440 --> 00:10:59,400
that there is a SCSI hard drive connected at 0080,

257
00:10:59,400 --> 00:11:02,160
and it's mounted at /dev/SDA,

258
00:11:02,160 --> 00:11:05,640
and that drive is manufactured by Fujitsu in this example.

259
00:11:05,640 --> 00:11:08,040
If you want to display the size of the disk as well,

260
00:11:08,040 --> 00:11:13,040
you can do that by using the -s option with lsscsi as well.

261
00:11:13,800 --> 00:11:15,510
Most of us, though, aren't really going to be using

262
00:11:15,510 --> 00:11:17,752
a lot of SCSI devices, because they're fairly old

263
00:11:17,752 --> 00:11:19,590
and antiquated by now.

264
00:11:19,590 --> 00:11:21,960
Instead, though, you may come across fiber channel

265
00:11:21,960 --> 00:11:23,760
connected devices instead.

266
00:11:23,760 --> 00:11:26,490
To interact with these devices and display their statistics,

267
00:11:26,490 --> 00:11:29,610
you can use the fcstat command.

268
00:11:29,610 --> 00:11:32,550
By entering fcstat at the command line interface,

269
00:11:32,550 --> 00:11:34,500
you're going to be able to display general statistics

270
00:11:34,500 --> 00:11:36,120
about fiber channel devices

271
00:11:36,120 --> 00:11:37,620
that are connected to your system,

272
00:11:37,620 --> 00:11:39,450
and this usually represents high speed

273
00:11:39,450 --> 00:11:42,960
and large capacity external storage area network arrays.

274
00:11:42,960 --> 00:11:44,790
If you want more detailed statistics,

275
00:11:44,790 --> 00:11:49,790
you can also enter fcstat-e at your command line interface,

276
00:11:49,980 --> 00:11:52,290
and this way you'll display all the statistics

277
00:11:52,290 --> 00:11:55,530
including device specific statistics, link statistics,

278
00:11:55,530 --> 00:11:58,350
and fiber channel for statistic types.

279
00:11:58,350 --> 00:12:00,540
As I said before, you don't have to memorize

280
00:12:00,540 --> 00:12:02,400
every single one of these commands,

281
00:12:02,400 --> 00:12:04,200
but I just wanted to introduce you to them,

282
00:12:04,200 --> 00:12:06,540
because you may come across them in the real world

283
00:12:06,540 --> 00:12:08,013
in working on Linux systems.

