1
00:00:00,000 --> 00:00:14,560
Hey guys and welcome back.

2
00:00:14,560 --> 00:00:18,440
So what I want to talk to you about in this nugget right here is a little bit of a change

3
00:00:18,440 --> 00:00:19,440
of pace.

4
00:00:19,440 --> 00:00:22,480
We're going to talk about the swap on command.

5
00:00:22,480 --> 00:00:28,240
Now when we're talking about swap space, what we mean is that when our RAM is being

6
00:00:28,239 --> 00:00:34,719
taxed a little bit too hard, i.e. we run out of RAM as opposed to just crashing the system,

7
00:00:34,719 --> 00:00:39,519
what the system is going to seek to do is going to seek to use this swap space.

8
00:00:39,519 --> 00:00:43,519
This is going to act as virtual memory, so to speak.

9
00:00:43,519 --> 00:00:48,599
And the way this is going to happen is it's actually going to use the hard disk.

10
00:00:48,599 --> 00:00:52,200
So really, this is not something we want to happen.

11
00:00:52,200 --> 00:00:54,679
This is more of a safety net.

12
00:00:54,679 --> 00:00:59,560
And because we are using the hard disk as opposed to the actual RAM, this is going to

13
00:00:59,560 --> 00:01:01,679
be very slow in comparison.

14
00:01:01,679 --> 00:01:07,599
So the performance will take a big hit, but it is a cheap and very useful solution.

15
00:01:07,599 --> 00:01:11,480
So before we get going, I shall just issue the free command.

16
00:01:11,480 --> 00:01:16,640
We can actually see here that we have our actual memory, which is our RAM.

17
00:01:16,640 --> 00:01:19,760
And below we actually have our swap space.

18
00:01:19,760 --> 00:01:26,520
This is how much of the disk we have allocated that can be used for this purpose of swapping.

19
00:01:26,520 --> 00:01:32,840
Now one thing to note here is with this concept of swapping, we can have a swap partition,

20
00:01:32,840 --> 00:01:38,400
which is a dedicated portion on the disk, which is used for this swapping action.

21
00:01:38,400 --> 00:01:43,920
But we can actually just create a swap file, so both solutions do work.

22
00:01:43,920 --> 00:01:49,719
So like I say, if I issue the swap on command, we can actually see we actually do have a

23
00:01:49,719 --> 00:01:50,719
swap file.

24
00:01:50,719 --> 00:01:51,719
It is a file.

25
00:01:51,719 --> 00:01:53,219
It's not a partition.

26
00:01:53,219 --> 00:01:58,560
We can see the size of the swap and we can see none of it happens to be used.

27
00:01:58,560 --> 00:02:03,719
This is a good sign for us because we don't want our swap file to be used because what

28
00:02:03,719 --> 00:02:09,199
it means, well, it means that our memory is running out and it's not a good thing.

29
00:02:09,199 --> 00:02:16,679
Now with the swap on command, we can actually create or remove a particular swap partition.

30
00:02:16,679 --> 00:02:20,799
Now as it transpires right now, I do not have a swap partition.

31
00:02:20,799 --> 00:02:26,799
Now if I actually wanted to create a swap partition, I could use a swap on command by saying swap

32
00:02:26,799 --> 00:02:32,639
on and then providing the actual device I want to make a swap partition, say for example,

33
00:02:32,639 --> 00:02:36,079
SDC2 or whatever it may be.

34
00:02:36,080 --> 00:02:42,400
Or if I wanted to remove a partition, I could say swap off and then specify the partition

35
00:02:42,400 --> 00:02:43,880
that could remove it.

36
00:02:43,880 --> 00:02:46,560
So I can do the same thing with respect to the swap file.

37
00:02:46,560 --> 00:02:49,920
I can say swap off and then give the name of the swap file.

38
00:02:49,920 --> 00:02:53,760
Oh, and of course, need that super user privilege.

39
00:02:53,760 --> 00:02:58,400
I can now say swap on and I no longer have that swap file.

40
00:02:58,400 --> 00:03:03,960
You see that now if I want to return that swap file, I just say swap on and again, just

41
00:03:04,040 --> 00:03:04,960
say swap file.

42
00:03:04,960 --> 00:03:08,400
And I don't know why I keep forgetting the super user.

43
00:03:08,400 --> 00:03:09,879
So there we go.

44
00:03:09,879 --> 00:03:13,480
Try again, swap on and it is back once again.

45
00:03:13,480 --> 00:03:18,280
Now what I could do is if I wanted to create my own swap file, so what I'll do is I'll

46
00:03:18,280 --> 00:03:23,600
just say swap off swap file and I'll just remove this swap file.

47
00:03:23,600 --> 00:03:25,159
So it's fully gone.

48
00:03:25,159 --> 00:03:29,080
If I wanted to create my own, I could use the command DD.

49
00:03:29,360 --> 00:03:36,360
So I'll say pseudo DD and I'll make the input file equal to something called dev zero.

50
00:03:36,360 --> 00:03:41,960
This is just going to create a file full of zeros and I'll make the output file equal

51
00:03:41,960 --> 00:03:43,680
to swap file.

52
00:03:43,680 --> 00:03:49,520
I'll say the bite size is equal to one meg and I'll make the count 128.

53
00:03:49,520 --> 00:03:52,960
So we'll have 128 units of one meg.

54
00:03:52,960 --> 00:03:54,840
That's going to be the size of the swap file.

55
00:03:54,920 --> 00:03:58,080
If I hit enter, we have now generated this file.

56
00:03:58,080 --> 00:04:05,039
So if I do an LS dash L or rather LS dash L on swap file, we can actually see the size

57
00:04:05,039 --> 00:04:06,719
of the file we have created.

58
00:04:06,719 --> 00:04:12,840
Now, if we want to make this a swap file, what we should do is we should change the permissions

59
00:04:12,840 --> 00:04:20,240
or make this 600 so that only the root user can actually access and modify this file.

60
00:04:20,240 --> 00:04:24,319
The reason being is that this file is going to contain RAM information.

61
00:04:24,319 --> 00:04:26,040
So that could be potentially sensitive.

62
00:04:26,040 --> 00:04:29,639
You don't want regular users to be able to access this file.

63
00:04:29,639 --> 00:04:31,439
So I'll change the permissions.

64
00:04:31,439 --> 00:04:36,319
If I add a whip, notice that the permissions have changed from here.

65
00:04:36,319 --> 00:04:39,839
We only have read writes, nothing for the other group.

66
00:04:39,839 --> 00:04:45,360
And what I now want to do is I want to actually denote that this file is going to be a swap

67
00:04:45,360 --> 00:04:46,360
file.

68
00:04:46,360 --> 00:04:51,800
Now, the way I can do this is I can say pseudo MK swap and then specify the swap file I'm

69
00:04:51,800 --> 00:04:52,800
targeting.

70
00:04:52,800 --> 00:04:54,400
I'm setting up some swap space.

71
00:04:54,400 --> 00:04:58,759
And now what I want to do is I actually want to enable it as a swap on because right now,

72
00:04:58,759 --> 00:05:01,160
if I just say swap on, we don't have anything.

73
00:05:01,160 --> 00:05:05,400
I will say pseudo swap on and then give the name of the swap file.

74
00:05:05,400 --> 00:05:06,400
There we go.

75
00:05:06,400 --> 00:05:12,720
If I now say swap on, we have now generated this swap file of 128 meg.

76
00:05:12,720 --> 00:05:18,199
If our system happens to be taxed, we can now use this space as a little backup.

77
00:05:18,199 --> 00:05:22,000
So really, as we can see here, the swap on command and the swap off command.

78
00:05:22,199 --> 00:05:23,800
In fact, let me just briefly show you.

79
00:05:23,800 --> 00:05:28,199
I can just turn this off once again, swap off for the swap file and swap on.

80
00:05:28,199 --> 00:05:30,600
It's no longer there and put it back.

81
00:05:30,600 --> 00:05:33,399
These commands are very, very useful.

82
00:05:33,399 --> 00:05:39,899
They allow you to control either swap files or if we happen to have a swap partition,

83
00:05:39,899 --> 00:05:42,199
we can do the very same thing.

84
00:05:42,199 --> 00:05:46,500
So really, I just wanted to highlight this at the end of this skill for the purposes

85
00:05:46,500 --> 00:05:47,500
of the examination.

86
00:05:47,500 --> 00:05:49,399
Really do focus on these commands.

87
00:05:49,399 --> 00:05:53,199
I recommend you read the man pages and lab this up.

88
00:05:53,199 --> 00:05:53,699
Okay, doc.

89
00:05:53,699 --> 00:05:57,299
So I hope this has been informative for you and I'd like to thank you for viewing.

