MBR Disk Partitions

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this lesson we're going to discuss managing Master Boot Record disk partitions on a Linux systems hard drive now the MBR partition formats been around for quite a while since the early 1980s and is still used a lot on Linux systems therefore you need to be familiar with managing these types of partitions but be aware that there are many newer disk partitioning schemes available that are much more robust and much more flexible than the old MBR partitioning scheme is but for the time being there's a lot of systems that still use MBR so you need to be familiar with it now you manage MBR partitions on a Linux system using the F Disk Utility now there are other utilities you could use but F disk is the one that is common across all Linux distributions you can use f disk to view disk partitions you can use it to create new partitions or you can use it to delete partitions from the shell prompt now do be aware that in order to run at this you do have to be logged in to the system as a root user because it does require root level access to the system the syntax for using F disk is shown here first we run F disk and then we specify the name of the hard disk device that we want to manage partitions on now notice in this diagram that we have three hard disks within this Linux system and you need to be familiar with the device naming syntax in order to use F disk correctly the first hard disk in the system is SDA the second hard disk in the system is SD B and the third hard disk in the system is SDC and notice that all of these hard disks are addressed using a file in the /dev directory so if I wanted to manage the partitions on this hard disk right here the second hard disk in the system then I would use this command here F disk space slash dev slash SD B now you might be wondering how the system decides which hard disk is SDA which one's SD be and which one is SDC and it's all based on which connector the particular hard disk is connected to on your hard disk controller for example on a system that uses SATA hard disk drives then the connector is connected to the lowest numbered SATA connector for example say to zero is going to be SDA the hard disconnected to the next higher numbered SATA connector such as SATA one is going to be s DB and the hard disk connected to the next highest numbered SATA connector such as SATA 2 is going to be s DC and so on so at this point you need to enter commands to tell F disk what exactly it is you want to do with the partitions on the hard disk and as you can see here once F disk is running you're provided with a command prompt and at this command prompt you enter the various f disk commands that manipulate the partitions on the disk now before you go any farther it's really a good idea at this point to enter the M command as shown here because when you do it will display a list of all the different commands you can use with F disk for example you can use in to create a new partition you can use P just to view partitions you can use T to change a partition type and notice right here you also have the option with D to delete an existing partition and you should be very careful before you use this action by the way because if you delete a partition with F disk then you're gonna lose all the data that was on that partition and once those changes are committed to disk there's no going back the changes aren't reversible so before you delete a partition make sure that doesn't have any data on it that you want to save and if it does back it up first or you're gonna be really sad now before you do anything with f disk it's really a good idea just to see what's already on the disk to see if there are already any existing partitions and the way you do that is by entering P at the command prompt for print it'll just print out a list of all the different partitions currently on the drive this will help you determine first of all if there's sufficient space on the drive to even create a new partition and if so then what numbers can needs to be assigned to that new partition when you create it on the disk as you can see here in the output of this P command there are no partitions so we can go ahead and just add new partitions to this disk without worrying about managing any existing partitions so with that in mind let's talk about then creating a new partition to do that you use the end command at the F disk prompt now when you do this you'll have to specify whether or not you want to create a primary partition or whether you want to create an extended partition here's a key thing that you have to remember when you're dealing with MBR partitions and that is the fact that any hard disk in your system the use of MBR partitions can only have four partitions maximum defined in this partition table and that can be a limitation now if you intend to just create four partitions or less maybe two then it's not a big deal you can just use primary partitions however if you need more than four partitions on the disk then we've got a problem and by the way on a Linux system it's very common to need more than four partitions on the hard disk drive in this situation what you do is include at least one extended partition in your four partitions now extended partitions are great using an extended partition you can create many logical partitions within that extended partition notice right here that it says that an extended partition is really just a container or logical partitions so let's take a look at an example let's suppose that we need six partitions on the hard drive in this Linux system well we already know that we can only have a maximum of four so we already know that one of those four partitions has to be an extended partition so to do this what we could do is create first three regular partitions right here right here right here these are just standard primary partitions and then we could take the rest of the disk space and define this as an extended partition instead of a regular partition and this is cool because what we then do is then create lots of logical partitions inside of this extended partition so we've got three primaries defined we need three more created within this extended partition so we could define a logical partition here and a logical partition here and the logical partition here so we have one two three logical partitions within the one extended partition so in effect what we have then is six partitions on the disk when we're technically only allowed to have four now please be aware that you can only have one extended partition per disk so the general rule of thumb is that create your primary partitions first however many it is you want to create one two or three and then you create your extended partition using the remaining space on the drive and then define all of the logical partitions that you want to use within that one extended partition so to create a primary partition you enter a P after entering in if you wanted to create an extended partition you would enter e instead of P in this example we used P to create a primary partition and then you have to specify what number you want to assign to that partition and by default what it's going to do is take a look at the existing partitions on the disk and then it will suggest using a number one higher than the number assigned to the last partition so in the example that you see here there are no partitions on the disk therefore the default number that's going to be assigned is one now you could use a different partition number if you wanted to I rarely do I usually just use the default because it works out beautifully fdisk knows what the next partition number probably should be so in this case I just hit enter to use the default value of one and then the next thing we have to do specify how big we want the partition to be and this is done by specifying the beginning and ending sectors that we want to use for the partition on the disk so first we have to specify the first sector that we want to begin with on the partition so by default what fdisk is going to do is specify the first available sector where partition could begin you don't have to use it if you don't want to but to use space effectively it's a good idea to do it now in this situation there are no partitions defined so it's going to suggest you use the first available sector which is 2048 and that will place our beginning sector right down around here then you have to specify what the last sector will be and notice that there are several different options that you can use for specifying the last sector you could either specify the last sector you want to use and if you're good at math you can calculate it out that's fine or you can specify a total number of sectors that you want to use and let fdisk determine what the actual ending sector number should be or what I usually do is just specify sighs how big do I want the partition to being specified in kilobytes megabytes of gigabytes terabytes and so on notice over here that I said I just want this partition to be ten gigs in size so f disks then calculated where the ending sector should be right there and set it up for me and when I'm done I've got a new 10 gigabyte partition on the hard disk drive now after you create a new partition it's a really good idea to run the P command again so you can see all the partitions on the disk and basically make sure that a the partition got created and B it got created with the parameters that you specified as you can see here we created the first partition on the SD B hard disk drive here's it's starting sector here's its ending sector here's the total number of sectors size and the partition type it's a standard Linux partition now notice over here that once we create a partition that we use a different device file to refer to that partition instead of referring to it as slash dev slash SD B which points to the hard disk itself we point to the first partition on that hard drive which has its own device file and slash dev which is slash dev slash SD b1 this indicates the first partition on the second hard drive in the system now it's important to note at this point that the partition actually hasn't been written to disk yet all the changes that we're making to the disk partitioning is only saved in memory it hasn't actually been committed to the disk yet and this is really nice because it allows you to play with the partitions before you actually make the changes and if you go through a whole partitioning scheme and realize boy I really don't like this I want to start over all you have to do is enter Q at the F disk command prompt and none of the changes that you specified will be written to disk everything will be back the way it was before you started using the F disk and when you're running f disk I always tell students q is your best friend now before you commit the partition to disk you may need to change the partition type when we created that partition just a second ago it was created as a standard Linux partition and that's the default behavior for F disk usually this is probably what you want to do because you want to store data on that partition but what would you do if you wanted to create not a data partition but instead you wanted to create a swap partition that will be used for virtual memory well to do this you have to use a different type of partition this is done by entering T at the command prompt and then entering the ID number of the partition type that you want to use now if you don't know what the ID number of the partition type you want to use is you can enter the L command and it'll bring up a list of all the possible partition types for example if we wanted to create a swap partition instead of a data partition we would change its type 282 right here notice that a standard Linux partition is type 83 that's the type of partition you store data in partition type 82 is used to create a swap partition so at this point we have defined our new partitioning scheme and we're ready to commit those partitions to disk to do this you use the W command now once you enter W things are a little more serious because it will make the changes to the partitioning and if you decided to delete a partition that partition gets deleted and if you decided to create a new partition it gets created so be very careful before you use the W command remember you can always enter q2 back out without applying the changes if you're not happy now after you've written your partitions to disk be aware that you may actually need to reboot the system before the Linux kernel will recognize the partition changes you made with F disk now that is actually kind of a pain because a lot of times you don't want to take the system down just to allow the kernel to see a new partition that's particularly true on a server system where there may be active connections going on with Network clients and you don't want to take that server out of commission even it's only for a few minutes to reboot therefore what you can do is run the part probe command the part probe command will force the kernel to see the new partition table without rebooting the system the syntax is shown here use type part probe - s the - s option causes part probe to show a summary of what it finds so as you can see here it found the new partition that was just created on / - / s dB that's it for this lesson in this lesson we discussed managing MBR partitions we talked about how to use the F disk utility to view existing partitions create new partitions change partition types and delete partitions and then we ended this lesson by talking about how you can use the part probe command update the kernel with the updated partition table
Info
Channel: The Linux Man
Views: 15,366
Rating: 4.9296188 out of 5
Keywords: Linux
Id: CfBMnb0jtp8
Channel Id: undefined
Length: 13min 35sec (815 seconds)
Published: Thu Nov 24 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.