How to Partition and Format a Disk in Linux

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my name's Carrie Sims and this is Garrick space now if you add a new hard drive to a Linux system that hard drive needs to be partitioned and it needs to be formatted before you can actually start using it because today I want to go through the process of finding the name of the hard drive when it's connected how to partition it how to format it all from the command line on a Linux system so if that interests you then please let me explain ok so the first step is that once you connect up your new hard drive there's an internal drive using it's a SATA or an external drive using USB or whatever you need to find the name of that device now in Linux all devices that you connect to your the machine come under a special name in the dev folder slash dev dev for device and you need to be to find the name of that device and then you'll be able to reference it when you are partitioning it and formatting and so on so let's go over to our Linux machine and see how you list the devices that are connecting to your machine ok so here we are on one of my Linux boxes and so the first one to do we discover the hard drive now the easiest way in my opinion to do this is LS build cave folks have list block devices with a - big s - capital S which will only show the scuzzy drives and for historical reasons hard drives appear as scuzzy drives me hit enter and here we can see that there are three disks listed s da YS da s DB and s DC this is a serial ata drive and look it's a Western Digital we can see that there and it's actually this one here s DC that I'm going to be using today and it's connected actually this is a housing for USB which he tells us here here it says SATA and Saturn ok so I found the disks using that way there are a couple other ways of doing it another way would be to do a sudo Super User fdisk - L now that will show a load of stuff as you can see there that's lots of stuff so to fight to not see these loop ones that we're seeing here what we can actually do is say PI play into I've got a video on grep remember - I slash dev slash SD and then that this out the the drives and here we see SD a 300 gigabytes as the be 300 gigabytes an SDC 1 terabyte drive there so again SDC is what we want to say and there's a final way of doing it s su do part ed which we'll look at later as well as we'll look at F disk later as well - L again lists all the different things out like that and again we can probably do a grep for something there let's look for SD something and there we go SDC is you know 1 gigabyte SD B is 320 gigabytes and it's the 1 terabyte mid say-so SDC is one terabyte ok so there we go we know now for sure that we want to use slash dev slash SD see ok now you know the name of the device like dev slash SDA for example how do we now partition that partitioning means to take that raw block of all those data that's there and actually say I want to have this used for a filesystem you haven't yet put the filesystem on it but I want to use it as a file system maybe as one big block maybe as two separate partitions one for the operating system one for your data so that if you reinstall the OS you've still got your data there maybe you want one for backing up files whatever you can divide up the hard drive however you like and if your dual booting a system for example you have Windows and Linux and you might want to divide it one for Windows one for this there's lots of reasons why you want to partition it into different parts but how do you do that partitioning but let's go back to the Linux machine and find out okay so Linux has various tools for doing partitioning probably the most used one certainly in the past maybe not today but certainly in the past is fdisk so sudo fdisk slash dev slash SD what was it it was C that we were looking at okay and back then tells us this goes into the F disk utility and just gives us this thing command for help well if you do P for print that will print out some stuff about the harddrive and what we're gonna do is we're gonna use the oak of my video em here by the way you get a list of all these different commands Oh will create a new dos a new partition but a new partition table so they raise everything is there and that's now empty so if we do P now we can see there are no partitions so to create a new partition you do n the new that's easy enough what do we want P for primary is because it's an ms-dos partitions for ms-dos use of the idea of primary partitions and extended partitions we want to create the first partition will start at 204 8 that's what it's offering us as the beginning we'll take the default there one nine five three five two five one six seven which is the end of the disk okay it says here there was other stuff on this dive before we sure we want to get rid of it yes we do okay and that's it and now we do P again and we can see that we have this s dc1 now the thing to remain oat here is that the one tells you that we're dealing with partition one when you just do with SDC then you're dealing just with the hard drive as an entirety when you do SDC one or two or three then that tells you about the partition and in fact we can tell here that it's just one big long partition for Linux 93 gigabytes and what you do to get to save that out there you just do w-4 right okay and that exits you out into the command line now another program you can use is a CF disk so this is a much more of a visual program though still from the command-line slash dev slash SDC okay and here we've kind of used cursor keys and things in here we can see highlighted in green that partition we created let's delete that let's move the the cursors him doing this with the cursor keys left and right let's go to delete okay and that now says it's free space and so we can go through the different options let's go for new we'll do the whole thing primary like before okay and there we go exactly the same thing we've created a whole partition there and one thing because what I do now here is write that out are you sure you want to write the partition table we have to type here okay and that's now been written out and finally we can do quit and so there you have it so another way of creating more than one partition now let's see what happens we'll take create two partitions using this so we'll go into there again we'll delete what we've got we'll start with a new one and we won't do this we'll say well we'll have one at 400 gigabytes please and it'll be the primary one and now you can see that there is this 400 gigabyte one and then some more free space so you can see we've got two things if there's and now again we can go in and create a second one there and so now we've got two partitions and notice is SD c1 and SDC - so you've got two partitions on the drive which is known as SDC one and two to show you the partitions and again we can just write that out yes we're sure and then quit so now that's a second way of doing it now another program that's very very often used is one called partied so we can do a pseudo partied /dev / SDC again okay and it says welcome to the new or new partied okay so the first thing we're going to do is we're going to do make label which is the equivalent of creating a new partition table rather than a DOS based one so the door space ones were there way back from the days of ms-dos how did the hard drive get divided up and that's been carried through a lot through today but there is another type of partition table could a do UID - UID partition table that's what we're gonna create now everything's gonna be deleted are you sure you want to do that yes we sure we want to do that and again the same thing we can actually do P to find out what's there printed out and we can see that there's absolutely nothing there's no partitions and if you do print free that will tell you what there is so there's the free space so we can see there that it's a it's a one terabyte drive and so what we actually do is we can say m'kay part make partition and we need to give it a label so we're gonna give this one labeled one zero 100% so there you go the beginning is at zero the end is at 100% okay and that is now P for print there you go created a partition with a name of one plus we call it there you could have called it Fred you could have called it Australia you could have called it whatever you wanted to okay and we can do the same thing now also with a DOS partition if you didn't want a GUI D partition table make label ms-dos okay and yes we don't mind that everything is deleted we can do P again find out there's nothing there same thing make partition but this time we say primary that's not the label now this is telling us the type of the partition we want it to be ext4 and we want to go from 0 to 100% and we print that out and there we go n EXT for partition which is a linux the Linux file system and you just type quit and that will then write that out and that is now saved to that table and so if we call it again we can just check the partition there it is partition 1 that we have created ok so that is our how you partition your hard drive into different sections using f disk C F disk and new partied now the disc is partition Xing to do is to create a file system on that partition to format that partition so first I'm gonna show you how Ukraine ext4 file system on that partition that's the file system you'd normally use on a Linux system and also have to Crane exFAT part file system on that partition and that's useful for example if you're doing this on a USB Drive or an external drive and you want to use this on other machines like Windows or Mac OS so they can all read Because X fact will be kind of a common way that's supported by all these different operating systems ok back again to the command line ok so the final part is to create the file system that means like to format it and the way you do that in Linux is again you type mkfs make filesystem notice everything is begins with m'kay make partition make label obviously this comes from make directory way back and you know from the she'll make a FS and we want to make an ext4 filesystem and you say we're well slash dev slash SDC not just SDC SDC one because it's in that first partition and or go ahead and actually start to format that partition as an ext for as an ext4 file system and that will take a few seconds to do that one thing to notice if you are ever doing benchmarking in terms of file system IO and you format a new file system like this there is some delayed writing that goes on that you can't disable when you do that mkfs otherwise the hard disk is actually still busy in the background they're doing the reading a right which under normal circumstances just fine because you want to let it carry on with that so this was an external hard drive room on a USB flash drive and I wanted to move it between Linux and Windows and Mac OS I don't want to use ext4 because that is primarily used on Linux I want to use something like X fat which is the format or for SD cards for a high-capacity SD card and so it's kind of generally universally recognized and you might need to install exFAT fuse on your Linux machine to do this I'll just show you the command that you need to do that so you need to install dos f FS tools X fact fuse and exFAT utils I've got all those already installed and so what we first only do is it change the type of that partition from being a Linux one to being a kind of a Windows II kind of one and let's do that in fdisk let's go back to F disk slash dev slash SD see if we print out we can see here type Linux so if we type in T here we can type in a different type of for the partition we'll do L to list the codes and way up here look at this hate number seven NTFS and exFAT so we'll say we'll change that to type seven please when you do a print again you can see it's now not Linux here it says it will support exFAT so let's write that out and now what we can do is a mkfs dot X fact slash dev slash SBC one again cuts the partition and that will now create that as an X fact so that drives if you unplugged it now a USB and plug it in somewhere else you better read it on other machines okay so there you have you've learned how to find out the names of the hard drive how to partition the harddrive and how to format it all from the command line in Linux if you want to see more than its tutorials please do tell me in the comments below and maybe suggest some topics and I'll see whether they are viable okay my name is Carrie Sims this is gary explains I really hope you enjoyed this video please do give it a thumbs up don't forget to subscribe don't forget the sweet 2g channel I suppose that's about it I'll see you in the next one [Music]
Info
Channel: Gary Explains
Views: 51,311
Rating: undefined out of 5
Keywords: Gary Explains, Tech, Explanation, Tutorial, Linux, Ubuntu, hard drive, hard disk, SATA, drive, disk, fdisk, sda, sdb, sdc, /dev/sda, /dev/sdb, /dev/sdc, partition, mkfs, mkfs.ext4, command line, format, cfdisk, parted, gnu parted
Id: JCFlsslBvX8
Channel Id: undefined
Length: 13min 57sec (837 seconds)
Published: Fri Oct 18 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.