00:00:00 - Okay, welcome to Nugget 104.1. Here we're going to learn
00:00:04 - how to create partitions and file systems on a hard drive or a
00:00:08 - block device in the Linux system. Now, this shouldn't be a really
00:00:11 - long nugget because it's not terribly involved to do this. But I'm going to
00:00:14 - try to explain some concepts so that you understand not only
00:00:17 - how to do it but what exactly you're doing. We're going to
00:00:20 - cover partitioning hard drives, creating a file system on there,
00:00:24 - and then we're also going to mention swap space. So before we get started
00:00:27 - on actually how to do it, let's talk about the hard drive
00:00:30 - itself. So if the hard drive is represented by this giant square
00:00:35 - here, let's say that this is all the space like ones and
00:00:40 - zeros, magnetic media, whatever inside. Now, before the computer,
00:00:44 - the operating system can recognize it we have to chop it up into
00:00:48 - pieces. Now, it can just be one giant piece. So this is going
00:00:53 - to be a rough concept, but let's see. You just divide it
00:00:57 - up into one piece, and this is just one partition of the hard
00:01:01 - drive. Now, you can also divide it into four pieces.
00:01:07 - This is, would be a primary partition can be divided or a hard
00:01:11 - drive can be divided into four primary partitions. Now, you can
00:01:14 - also do some other work called with extended partition so
00:01:18 - that you can divide it into more and more pieces of different
00:01:22 - sizes if you want.
00:01:24 - But basically, you need to know that the hard drive is like
00:01:28 - this big square and we need to divide up the area on the hard
00:01:31 - disk into partitions and then those partitions like this
00:01:37 - could be formatted in a way that
00:01:41 - Windows recognizes and this one could be something that
00:01:48 - Linux recognizes and this could be OS or 022. That's supposed
00:01:55 - to be OS2.
00:01:58 - But this could be OS2. This could be Solaris. This
00:02:02 - could be another Windows. So you just chop it up into these
00:02:06 - pieces and on those individual pieces or partitions that's where
00:02:12 - you write
00:02:14 - a file system and a file system is actually where the operating
00:02:18 - system will store your data. So your hard drive is this giant
00:02:22 - storage media, and I know I'm just drawing a bunch of circles now, but
00:02:24 - it's a giant storage media that is divided up into partitions
00:02:28 - and each individual partition is formatted with a file system
00:02:32 - that the operating system can understand, alright. So let's talk
00:02:36 - about how we actually do that to a hard drive.
00:02:39 - Okay, so here we are at the command line. Now, on this computer
00:02:42 - what I have done is I've inserted a blank drive. Now, it's a virtual
00:02:46 - machine. So really it's not a drive, but it's a blank drive
00:02:49 - container just as if I put a blank hard drive in a computer. So
00:02:53 - if we want to see what's in the computer, if you type sudo,
00:02:56 - because we have to do this as root, fdisk -l,
00:02:59 - it will list all of the drives
00:03:03 - that are in the computer. So we'll see what we have here.
00:03:07 - This tells you what disk we have, dev/sda, we talked about what
00:03:12 - these devices are before. But basically, this is the first hard drive.
00:03:15 - It's 10.7 gigabytes and it's divided into these
00:03:20 - different partitions,okay. So now you may be wondering why does it go 1, 2, 5?
00:03:25 - Well, that's because it's, there's one partition, this
00:03:29 - sda slice 1 and that is
00:03:34 - formatted as the Linux partition. This is actually the, the root
00:03:37 - partition. And then what we've done is the, it generally makes
00:03:42 - any additional partitions what we call extended partitions.
00:03:47 - Now, there's only two real partitions here. So you know, we didn't
00:03:51 - have to make an extended partition, but what this allows us
00:03:54 - to do is have many, many more partitions outside of the four
00:03:59 - that a hard drive normally supports. So sda2 is really
00:04:03 - just a partition telling the, the computer where the other
00:04:07 - partitions are, if that makes any sense. By default it only supports
00:04:11 - four partitions. So if we make an extended partition in one
00:04:15 - of the first four, it allows us to do many more. So five, six,
00:04:19 - seven, eight, nine, ten, that kind thing, alright. So there's
00:04:22 - only two partitions here. This, there is this third one, but
00:04:25 - it's just the extended partition telling the computer where
00:04:28 - the ones past four are. That's also why it skipped three and four. One,
00:04:33 - two, three and four are primary partitions.
00:04:36 - Sda5 or partition 5 is one of the extended
00:04:40 - partitions outside of that. So hopefully, that makes sense. Another thing it
00:04:45 - shows us here is that the first partition is bootable. Now,
00:04:49 - Linux honestly doesn't care if a partition is bootable or not. It will
00:04:52 - boot that partition regardless. But Windows requires that it's flagged
00:04:56 - as bootable if it's a, if it's a Windows partition that we're, that we're
00:04:59 - looking at. This one of course is just Linux. So the other
00:05:04 - hard drive that I put in is completely blank. It's dev/sdb
00:05:09 - and it's a 20-gig hard drive. And it says here that
00:05:14 - disk can't, does not contain a valid partition table. Okay, that's
00:05:18 - because it's just a raw disk. If you get a disk from the store
00:05:21 - and you put it in there, that's generally what you would expect to
00:05:24 - see is that there's no partition table at all or it's possible
00:05:27 - that there is an existing partition table on there and you would
00:05:30 - just want to wipe that before you install your, your operating
00:05:33 - system, okay. But this shows you what's on the computer. The partition
00:05:37 - I didn't talk about too much, this is a swap partition. Now, we know
00:05:41 - what swap space is because we've learned it before. That's where your computer,
00:05:44 - the memory that your computer uses if it runs out of actual memory,
00:05:48 - rather than crashing it will write things into swap space which is
00:05:51 - like a page file or virtual memory, okay. And it's just a partition
00:05:55 - and we'll, we'll see in a few minutes here how to go about making that. But again,
00:05:59 - it just shows up as another partition on the hard drive, alright.
00:06:03 - So if we want to actually edit and create partitions in sdb,
00:06:08 - we again use the fdisk command.
00:06:12 - This time since we know the hard drive, what we're going to do is type sudo
00:06:16 - fdisk and then the device we want to edit which is
00:06:20 - sdb, okay. So we do that, and it warns us of a couple
00:06:24 - things. It says there's no partition table which we already know.
00:06:27 - It says that if you're going to do anything bigger than 124
00:06:31 - cylinders, old operating systems like OS2 and MS-DOS won't understand it.
00:06:36 - Okay, that's fine. That's fine. We're going to be using
00:06:39 - Linux and we're going to be using GRUB. We're not going to be using LILO
00:06:43 - anyway so, anyway, this is, this is how we start fdisk. I would
00:06:47 - suggest, first of all, typing m
00:06:50 - and this shows us all the commands that we can do. Now, the very first
00:06:54 - thing you do in fdisk
00:06:56 - is press p
00:06:57 - because that's going to show you the specifications of the
00:07:00 - drive that you're editing. And this is just to make sure that
00:07:03 - we didn't accidentally type in the wrong drive or we remembered
00:07:06 - incorrectly which device that we wanted to edit. And sure enough
00:07:09 - this is our device, 20 gigs or 21.4 gigs.
00:07:13 - There are no partitions set up so, you know, there's nothing
00:07:17 - set up on this one so we know that it's the correct one.
00:07:21 - So press m again and see what, what options we have. We're going
00:07:24 - to create a partition or two. So let's add a new partition.
00:07:29 - Well, n for add a new partition. Now, do we want it to be extended or
00:07:32 - primary? Now, I talked a little bit about what that means, and for our
00:07:35 - purposes right now, a primary partition is going to be fine.
00:07:39 - We'll say partition number one.
00:07:42 - And where do we want the first cylinder to start? So this is basically
00:07:45 - saying, where on the hard drive do you want it to start? If you remember
00:07:48 - the picture of our hard drive, just imagine the cylinders
00:07:51 - are numbered like one through 2610, okay.
00:07:55 - Well, the first one is at the beginning of the drive and that's
00:07:57 - actually where we, where we want this. So let's say one, and then we get
00:08:01 - to say how big to make the partition. Now, you can do it by cylinder.
00:08:06 - You can say the last cylinder which is what it's defaulting
00:08:09 - to here, and that will use the entire drive as one partition.
00:08:12 - But that's not what we want. I actually want to make a couple of
00:08:15 - partitions here. So we have a couple other options. We could just try
00:08:18 - and guess which cylinder we'd want to stop at and that's fine. But you can
00:08:21 - be more specific and say just how big you want it to be in kilobytes,
00:08:25 - megabytes or gigabytes. And that's what I'm going to do.
00:08:29 - Now, you have to put the plus because that tells it that we're
00:08:31 - going to do it by a size or, you know, specify a number here. And
00:08:36 - let's see. It's 8 or it's 20 gigs or 21.4
00:08:39 - gigs. So let's do 18 and then G for gig, okay. So we're following
00:08:45 - this plus the size is 18G for gigabytes. So +18G
00:08:50 - and it should be done. Let's press p again and print, and sure enough
00:08:55 - we have this sdb slice 1 partition 1 that starts
00:09:01 - here and ends here.
00:09:03 - How many blocks it is. And it gave it an Id. Now, now, that's
00:09:07 - important, okay. So let's look at m help again. It's Id in
00:09:12 - hexadecimal 83 which means it's going to be a Linux partition, alright.
00:09:15 - Let's say we wanted to, where is that?
00:09:21 - Change a partition system Id, alright. Say, we wanted to install
00:09:25 - Windows on that. Well, press t.
00:09:29 - Now, if you know the hex code, that's great. And there's
00:09:32 - a couple that are common, but it's nice to type l and get
00:09:35 - the list of different codes because as you can see there's
00:09:38 - a whole bunch of them. Now, as default it does 83 which is the
00:09:42 - Linux type, okay. So we could change it to something like,
00:09:48 - what if we wanted Windows 95 FAT32 or
00:09:52 - Windows 95 FAT32 with large block access, right,
00:09:56 - for something over two gigabytes? Alright, so that's what we would do
00:10:00 - there or there's all these different kinds of partitions
00:10:03 - that you can specify. Generally, you only do a few. You might make
00:10:07 - a Windows FAT32 partition. You will very likely
00:10:12 - make this LINUX partition. You could do a Linux swap partition
00:10:18 - which is actually the other one that we're going to do or you
00:10:20 - may want to do something like Linux RAID if you're doing software
00:10:23 - RAID. But for us right now the first partition, I want that
00:10:26 - to be what it is. I want it to be the Linux partition code 83.
00:10:29 - Let's type code 83, alright.
00:10:33 - And now it already was code 83. But that's fine
00:10:37 - because we're going to make another partition. So new,
00:10:40 - going to be another primary partition.
00:10:43 - This time let's do partition number 2.
00:10:46 - And now it says the first cylinder. Now, it can be anywhere from
00:10:49 - 2352 to 2610, okay, because one through
00:10:53 - 2351 are used up by our first partition.
00:10:56 - So you can see that right here. So we're going to start with the
00:10:59 - next cylinder. We don't want to waste any of the hard drive. So we'll just take the
00:11:03 - default of 2352. Press enter. And now we
00:11:07 - could figure out exactly how many gigabytes are left. But I basically
00:11:11 - just want to use the rest of the hard drive, right? I just,
00:11:14 - I have that one partition that's my Linux system, and I want
00:11:16 - to use the rest for swap. So I'm just going to take the
00:11:19 - default of the last cylinder. So just hit enter to take that default
00:11:23 - again. See, it's done. And now if we press p to print the partition
00:11:27 - table, we'll see we now have two partitions. We have one that
00:11:32 - is around 18 gigabytes and it's Id 83 which is
00:11:37 - a Linux type. And then we have slice 2 which is, oh,
00:11:43 - it looks like right around two gigabytes, a little bit more. That
00:11:46 - makes sense. But this is type 83 Linux. That's not
00:11:50 - what we want, right?
00:11:52 - So press m. What is our command to change the partition system
00:11:56 - Id? It's t. So press t.
00:11:59 - Which partition? Two, the one that we just did. And I don't remember the
00:12:04 - code. Actually, I do but
00:12:06 - let's type l again, and we know that we want it to be Linux swap, alright.
00:12:11 - That's the type of partition. Now, it's important to note that
00:12:14 - what we're doing here is setting the partition type. We're not
00:12:16 - putting a file system on it.
00:12:18 - That's coming next, but just keep that straight that there's
00:12:22 - types of partitions and then there's file systems in those
00:12:25 - partitions. Right now we're just setting
00:12:27 - the type of partition. We want that to be
00:12:31 - 82 Linux swap.
00:12:34 - If we press p, we'll see now it's just what we want. See, we have this
00:12:38 - as Linux. This is Linux swap. Two slices on our, on our hard drive
00:12:43 - there. So now we're ready to quit. But you want to make sure
00:12:49 - that we write, alright.
00:12:52 - And that's what we want to do. So we type w and what it's going to do is write that
00:12:56 - to the partition table. Syncing disks. This is normal. And now, if we type sudo
00:13:03 - fdisk -l,
00:13:06 - now we should see things from two different
00:13:09 - hard drives. Our original one, this is what Ubuntu did
00:13:12 - when it was installed originally. It decided to make an extended
00:13:15 - partition in case I wanted to make a bunch of different partitions
00:13:18 - later. I didn't do that. I just made two in the primary partition or
00:13:22 - two primary partitions. And we have a Linux and a Linux swap, also
00:13:26 - Solaris swap. These are the same type of
00:13:29 - partition Id, alright. So that's how we go about partitioning
00:13:33 - our drive. But now we need to put a file system on there
00:13:37 - or we'll never be able to mount it and use it.
00:13:41 - The next step is actually pretty painless. Now, the LPIC and CompTIA
00:13:44 - exams, they will, they specify five different file
00:13:48 - systems that you have to be able to know how to format and
00:13:52 - then one that's not really a file system. We'll, we'll do that one first and that one
00:13:55 - is Linux swap. Now, it's basically just as easy as typing sudo
00:14:02 - mkswap for make swap and then the partition that you
00:14:07 - want to make a swap file which for us is dev/sdb2.
00:14:13 - See, dev/sdb2
00:14:16 - is our Linux swap, okay. So you type that.
00:14:20 - It will go through and that's really all it took. It's that quick because
00:14:23 - it doesn't really have a file or a file system format, but
00:14:27 - this is how you create swap space, okay.
00:14:31 - So it's two gigabytes. It's there. That's the UUID. And I
00:14:34 - won't show you how to activate this on,
00:14:38 - on a system. I won't show you how to do that because that's a later
00:14:41 - nugget, how you activate it, how you mount it automatically when
00:14:44 - the system boots up. But it's pretty painless. Yeah, I mean really quickly.
00:14:48 - If you type sudo swapon /dev/sdb2,
00:14:53 - that's all there is to it. And now that swap space is active, okay.
00:14:58 - So it's, it's pretty painless.
00:15:01 - And if you to make sure that it's being used, just type
00:15:04 - swapon -s and it will show all the different partitions that
00:15:11 - are currently being used to swap space, okay. Actually, it is using
00:15:15 - a little bit of our initial swap space, but none of the swap
00:15:18 - space we just activated, okay. So that's how you do swap. Now,
00:15:22 - the other parts we're going to actually format actual file systems
00:15:26 - on our, on our system. So let's make sure we know what we're looking at,
00:15:30 - sudo fdisk -l again, and we know that these are our
00:15:37 - partitions. Now, we use similar commands to make all the different,
00:15:42 - the five different file systems that we need to know how
00:15:44 - to do. So we'll just go through them fairly quickly here. The
00:15:48 - command that you use is first you have to be root. So sudo
00:15:51 - mkfs for make file system -t and then
00:15:56 - the type of file system. Now, we're going to do ext2, that's the
00:16:00 - first one that we need to make, and then where you want it to be,
00:16:03 - dev/sdb1, see, because that's the partition that we set up, right?
00:16:09 - sdb1 is the Linux partition. So we do that
00:16:13 - and it goes through and writes in the file system and it's
00:16:16 - all created. It's okay if it takes a long time if your disk is
00:16:19 - bigger. Again, this is only an 18-gig drive so it goes pretty
00:16:22 - quick. But the next thing that we do is very similar. We'll
00:16:27 - say sudo and mkfs -t
00:16:33 - ext3 because now we're going to use the next file system,
00:16:37 - ext2. The next one is ext3 that we have
00:16:40 - to learn. The difference being that ext3 is a journaling
00:16:43 - file system which we'll learn about later. You don't have to worry about
00:16:46 - that right now. Dev/sdb1
00:16:50 - and it went through then formatted in ext3 file
00:16:53 - system. And like I said, it's a journaling file system so sure enough
00:16:57 - it created a journal.
00:16:59 - Now, the third one that we need to learn, what, there is a different
00:17:02 - way that you can do this as well, sudo mkfs. Now, normally, you do
00:17:07 - -t and then the next type of file system which is going
00:17:10 - to be f or xfs. But you can also, there's a little
00:17:15 - command.xfs. Now, I don't know that that's a lot simpler. I guess it's
00:17:20 - a couple fewer keystrokes. So if you prefer to just do that,
00:17:23 - this is a program that instead of mkfs and then dash t
00:17:26 - the, the type, just mkfs.xfs is a program
00:17:30 - that will create an xfs file system. So if you prefer it that
00:17:34 - way, go right ahead and then where you want to do it, sdb1.
00:17:39 - Now for some reason xfs is much more careful
00:17:43 - about how it, if it, but it doesn't want you to overwrite something
00:17:47 - that's there. It says, whoa, there's already a file system, ext3,
00:17:51 - that exists on dev/sdb1 which we know because we just
00:17:55 - made that, right? So we do just like it says. We'll add the -f flag.
00:18:01 - Basically, sudo mkfs.xfs -f for force,
00:18:06 - just like it told us to do on
00:18:08 - that partition and it did. Now, it made the, the xfs file
00:18:14 - system on that partition, okay.
00:18:18 - Actually, let's retype it, sudo mkfs. I usually use the -t
00:18:25 - for some reason. I don't know why I just like it, but the last
00:18:27 - one we need to know is reiserfs, okay;
00:18:32 - dev/sdb1, and this should look pretty similar. Oh, no,
00:18:37 - all of your data is going to be lost. Yes, we're sure, wahaha.
00:18:43 - So now it's done the same thing. It's formatted our drive.
00:18:47 - It gives you a warning that you want to make sure you have
00:18:49 - kernel 2.4.18 or later if you're going
00:18:52 - to use reiserfs version 3. This is version 3,
00:18:55 - by the way, of reiserfs. That's what comes by default.
00:19:00 - I don't think you can get an older version right now
00:19:02 - on a modern operating system. But anyway, that's how you do reiserfs.
00:19:06 - Now, the one other file system that we need to create is VFAT,
00:19:11 - which is one that Windows and DOS can read. But before we do
00:19:15 - that, we have to make a change with
00:19:18 - fdisk. Since in fdisk, I will show you, sudo fdisk -l. Now,
00:19:24 - if you remember when we did this,
00:19:27 - sdb1 is a Linux type of partition which means that we can't
00:19:32 - put a DOS file system on there, can we? So what we do, sudo
00:19:37 - fdisk
00:19:40 - dev/sdb. Alright. Now what do I always
00:19:42 - say to do? Press p. Make sure you're working on the right partition, right?
00:19:46 - And we are. This is the partition. No, we don't need to make
00:19:49 - the partition again. We're just going to change the Id, okay.
00:19:55 - So if you remember,
00:19:57 - type the help command to change a partition system Id, press t,
00:20:00 - partition number. Well, we want to do it on sdb1,
00:20:05 - and the hex code that we want. Well, I don't remember all of
00:20:09 - them. So press or type l to get the list of codes, and
00:20:13 - let's see. We need it to be a Windows type file system, right?
00:20:17 - So let's go and make it
00:20:21 - Windows 95 FAT32 with large block support, okay.
00:20:24 - So c is the hex code that we need. So down here type c.
00:20:29 - And now it should be, if we type p, changed, okay. Now, it's a Windows 95
00:20:35 - FAT32 type partition. So if we type w to write that, it's
00:20:41 - going to resync our disks,
00:20:45 - alright, sync the disks, alright. So now if we type mk sudo, we
00:20:50 - can't forget sudo, mkfs -t vfat, this is
00:20:56 - one that Windows will be able to read,
00:20:59 - dev/sdb1.
00:21:03 - That's it. It's done. It created an MS-DOS file system or Windows
00:21:07 - file system on that partition, alright. So that's all there
00:21:11 - is to making partitions. Let's go over to make sure we remember
00:21:15 - which ones that we need to remember how to make and how to activate,
00:21:19 - some swap partitions. And we're just about done.
00:21:22 - See, I told you this was going to be an easy one, alright. We learned
00:21:26 - how to partition using the tool fdisk.
00:21:30 - And then we learned how to create different file systems and
00:21:34 - the ones you need to learn are the ext2,
00:21:39 - ext3, xfs, reiserfs, and vfat, alright.
00:21:45 - And then you need to remember how to make swap space which was
00:21:48 - just mkswap,
00:21:51 - that's a k right there, mkswap and to turn it on,
00:21:57 - swapon, alright. Now, we're going to learn how to mount all
00:22:01 - these things and mount them automatically in a later nugget.
00:22:03 - But for this that's all you have to know. See, that nugget wasn't
00:22:07 - too bad at all.
00:22:08 - I hope that this has been informative for you, and I'd like to
00:22:11 - thank you for viewing.