Let's imagine we have a two Terabyte SSD,
we want to install windows on it. But also Ubuntu,
that's a problem because Windows uses the NTFS file system. And Ubuntu
uses the EXT four file system.
We can't just mix Windows and
Ubuntu.
But there's a solution for this problem,
we can simply divide the storage space on that SSD.
We reserve one Terabyte for windows and one Terabyte for
Ubuntu
dividing a storage device in this way is called partitioning.
We'd have two partitions in this scenario, each one Terabyte in size.
Now windows can use the NTFS file system on the first partition. While
Ubuntu can use ext four on the second partition,
things are now logically separated and each
operating system can freely do its thing.
Now to see what partitions exist on a Linux system,
we can use the LSBLK or list block devices, command
what we see in this output are called block devices.
We can think of these as blocks of storage space
places where Linux can store data or retrieve data from.
Not everything we see in this output are partitions,
only the ones that have the word part in the type column
in
this case SD A is the virtual disk and it contains three partitions
SD A one
SD A two and SD A three.
The last entry where we see L VM is something managed by the logical volume manager.
But we'll discuss that in depth in another lesson
in a virtual machine, virtual storage devices. Sometimes begin with the letter B
on a real computer. We might see names like SD A one SD A two, etcetera. Instead
the S comes from the word serial. If an SSD is connected to
a S ata port, which is serial A T A on the motherboard
and with N VM E storage devices, we'll see names beginning with N VM E for example,
imagine we have three virtual disks.
We may see names like these, the last letter and number at the end,
make it easy to know which disk or storage device this is and which partition
SD A is the first disk.
S db is the second disk
S DC is the third.
And we see these are in alphabetical order from AB C all the way to Z.
The last number tells us the partition number on that specific storage device.
Now we can see something like S db three and easily figure out what it is.
The letter B tells us it's a second storage device
and the number three tells us it's the third partition.
So we have the third partition of the second storage device in S db three.
But anyway, what's the use of these names? And what can we do with them?
Well,
there's a saying in Linux that everything is a file
and we'll see that this even applies to partitions.
Consider this setup,
all of these block devices are actually referenced
by files found in the slash DEV directory.
So we'll find SD A one at this file
and this will point to the first partition of our first storage device.
This basically gives us direct access to the partition.
And we'll see in our next lessons, what we can do with this access.
Now,
remember we also have files that point to the entire
storage device while DEV SD A one points to a partition
DEV SD A points to the entire device
and we can use it in a command like this.
Let's take a look at the output.
Now just like a meter can be divided into 1000 millimeters.
A storage device is divided into sectors. When we see a sector size of 512 bytes.
And that first partition starts at sector 2048. We can calculate that.
This means it starts after 5, 12 times 2048
or
1,048,556 bytes,
which is exactly one megabyte or two to the power of 20.
This means that the partition has one meg of free space before it.
In other words, sector 0 to 2047 are not partitioned.
It's just standard procedure to leave one meg
free of unpartitioned space at the beginning.
And this is done in case a special program
called a bootloader needs to be installed in that area
on some storage devices. We might see a sector size of 4096 bytes.
So we'll need to multiply the number of sectors with 4096 instead not 512.
Now F disk can be used to create and delete partitions too.
But let's look at a utility that's a little easier to use CF disk.
Now, I've added a second storage device to our machine.
So let's look at that
type in pseudo CF disk slash DEV slash S db
indicating that it's a second drive.
Now, data on a disk is just a bunch of continuous zeros and ones.
So there needs to be a way for the operating system
to know where a partition begins and where it ends.
This is one of the jobs of the partition table
with the older format that was used for decades.
This table was stored at the beginning of the disk
in what was called the MBR or master boot record.
Nowadays,
many systems have migrated to GP T which is a
good partition table because it has a lot of advantages.
The partition table in GP T is less likely to get corrupted
and we can have many more primary partitions, much larger partition sizes and so on
before we create any partition, we need to decide if we'll use MBR or GP T.
Most often GP T should be used
only if we're working with very old hardware.
Should we be forced to use MBR as older
computers can only boot with MBR partition tables?
Now, in this case, we'll pick GP T.
If you ever need MBR, pick DS D OS is equivalent to MBR in the CF disk utility. In
this exercise, we'll imagine that we want two partitions on a 10 gig drive,
18 gig partition.
For a new operating system we can install and two gig for swap,
which we'll learn about in one of the next lessons
to create a new partition.
We navigate to the free space we want to use and select the new button at the bottom.
We can just press enter in our case as both of these things are already preselected,
the default 10 gig size is not good.
So let's delete that and write eight G.
Now,
we can navigate through the partitions in free space with the up and down arrow
keys and we can navigate to other buttons with the left and right arrow keys.
Let's press down to select the remaining free space and partition that too.
We'll select new once again
and stick with the default two gig size and press enter.
Now, let's say we changed our mind. We want three partitions,
but we have no more free space.
What we can do is navigate to the first partition with the up arrow key.
Then we press the left arrow key
to select resize
and we can type four gig as our new size
and look at that. Now, we've got some free space in the middle
and we'll pick new to partition that too.
Now we notice that the partition is physically stored at the end of the disk.
It actually shows up as the second partition S db two.
We'd expect it to be third, but that's not the case
partitions are numbered according to the order in which they're created,
not where they're positioned on the storage device,
but we can fix this.
We'll press the right arrow key until we reach the sort button
and then press enter this reorders the partitions in a more natural
way according to where they are positioned on the storage device.
And now we can navigate to the third partition and delete it just to see how it works
pretty easy.
Let's Slack new and recreate it.
Now, finally, we see a type button.
Well, what does this do? Well, let's select s db three.
Before we press enter on the type button,
we mentioned that we want our two gig partition slash DEV
slash S db three to be used as a swap partition.
And we can see that we have this partition
type in our list right above our current selection.
Let's select that and press enter by default partitions created with CF disk
have a Linux file system type which is good for storing generic data,
things like operating systems, programs, personal files and so on.
We rarely need to change the partition type.
The one Exception is for the swap partition as we've seen here.
Another scenario is when we need to create a boot partition.
And in that case for the boot partition, we'll select EF I system as our file type.
Now, finally, we have the setup type that we need.
And we've learned how CF disk works.
One important thing to remember though CF disk did not actually create
any new partitions up until this point from its point of view.
This is just the plan that needs to be executed.
We tell it what partitions we want their type,
what size they should be what we want to delete and so on,
but it won't change anything until we hit the right button.
And this gives us a chance to undo accidental changes.
For example, if we realize that we modified the wrong partition,
we can just select quit and nothing will change.
But in our case, we want to apply our changes. So let's press the right button
and remember to use this button in a real scenario.
Remember to use this button in a real scenario
and we can finally type yes
and press enter to save our changes.
We need to make sure we see this message at the bottom
that the partition table has been altered.
And finally, we can press the quit button and exit the application.
And we can see in lsblk that our partition structure was created as we intended.
And this concludes our demo on listing,
creating deleting and modifying partitions.
And I'll see you in the next video.