Creating Partitions In Linux Using fdisk (and other tools)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video i'm going to show you some of the basics of fdisk what is fdisk fdisk is a partition manager it allows you to create partitions so this is typically used when you're installing linux especially using command line installations of linux so when you're installing really minimal linux distributions like arch linux gen2 many server distributions typically they involve you installing linux through the command line and you have to actually use command line tools to partition your disk now there's several command line partitioning tools out there f-disk is probably the standard tool it's typically the one that you see recommended in most linux distributions wikis so that's the one i'm going to talk about today so let me switch over to my desktop because i've got a virtual machine that i quickly spun up here so this is arch linux i'm just booting directly off the live iso for arch linux so this is the very first part of the installation which is typically the most important part of the installation of any linux distribution is the very first thing you typically want to do is partition your drives so how you typically want to do this is you want to run as root or with sudo privileges f disk dash l give it the l flag and this is for list this lists all the devices on your system so basically all of your hard drives is typically what it's going to list out so i have slash dev slash vda for virtual disk and i also have slash dev vdb because i created two virtual hard drives in this virtual machine i also have the loopback device we'll just ignore that but typically however many hard drives solid state drives nvme drives they're all going to be mounted at slash div they're going to be given a specific name so typically sd drives or sda sdb sdc etc hard drives hda hdb hdc etc and if you have nvme drives they're going to read something like slash dev slash nvme 0n1 or slash dev nvme 0n2 etc etc now i can't stress enough that it's always important to go ahead and run the fdis-l command first before getting started because you want to make sure you know the exact names of the devices in your system because you don't want to accidentally format a drive or the wrong drive you know i i don't want to accidentally format slash dev slash vdb when i meant this format slash dev slash vda you know right so make sure that you get a listing of all your devices if you have multiple drives in your system and then once you know the drive you want to format go ahead and run as root or with sudo privileges f disk space and then the name of the device so i'm going to do slash dev slash vda and then we get into this new interactive fdisk prompt where we can start typing commands that fdisk understands if you don't know the commands you can see that you can type m for help why is it m for help i'm assuming m stands for help menu so think of that you know if it's kind of weird to think of m for help but think of it as a help menu so if i type m and hit enter we get all the commands that are available for us here in this part of fdisk so before partitioning anything you need to create a empty partition table typically on linux we're either going to create a dos partition table which is for master boot record legacy bios or you're going to create a gpt partition table and that's for use with uefi so in this vm i'm going to do a legacy dos partition table so i'm going to type o because you can see the last four key bindings are the create new label key bindings and o creates a new empty dos partition table and now that we've done that the next thing i want to do is create a new partition and under the generic keybindings you see in adds a new partition so n for new partition it's going to ask what is this new partition going to be as far as the type is it a primary partition or is an extended partition so i'm going to create a swap i'm going to do like a one gig swap and it needs to be a primary partition now for a dos partition table we have up to four partitions available if you're doing uefi you have up to 128 partitions available so the very first partition i created the swap partition will be partition number one and the very first sector of that partition just needs to be the very first sector just hit enter and go with the default number for that and then the last sector how big do you want this you can give it an exact number in bytes but what i typically do is i just do plus one capital g for one gigabyte so start at the beginning and then go plus one gigabytes in size and that created a new partition and you can see by default it creates it as a linux file system as that's the type we're gonna change that to swap here in a minute and it was one gigabyte in size now that i created a one gig swap i need to create a real file system you know the the big file system for like my extend four file system so i'm gonna go ahead and type in for new partition this once again will be primary so p for primary partition number this time it'll be partition number two the first sector again is the first sector available just hit enter and then the last sector you could give it an exact size but in my case i wanted to take up the entire rest of the disk so all i have to do here is just hit enter and you can see it created partition to type linux which is correct this time size 19 gigabytes because this 20 gig device this virtual disk has a 20 gig disk and we gave one gig to the swap and then the rest of it was the 19 gigs left for what's going to be my extend 4 file system now remember partition 1 was swap but it created it as a partition type linux which isn't correct so we need to change the type if i type m you can see under generic t for change partition type so let's do that t hit enter which partition are we changing we're changing partition one and then what is the type type capital l to list all the uh partition type we need should be called linux swap and actually you can see it under aliases you see linux is 83 and swap is 82. so just type 82 for swap and now if i do m for help under the generic key bindings you can see p prints the partition table so i'm going to type p because i want to see if that actually changed yes now slash dev slash vda1 one gigabyte and you can see the type is linux swap slash dev vda2 is 19 gigs and it's type linux now you'll notice when i printed out the list here you can see there is a column for boot neither one of these partitions is bootable and of course the big partition the vda2 needs to be bootable so we can add a boot flag to that if you look at the key bindings there should be a key binding to actually make a partition bootable let me type m to get a fresh help screen here and you can see the very first key binding a toggles a bootable flag so if i type a it's going to ask which partition do we want to make bootable i'm going to do 2 because that's vda2 so now once again i'm going to type p and you can see there is a asterisk under the boot column for vda2 so all of this looks good now we're ready to actually write the changes so w would write and then it automatically quits after that now if you were didn't want to save so you had partitioned everything and you realized you made a mistake and you didn't want to write you could always cue to quit without writing the changes but in this case we wrote our changes and it's ready to go now remember i had a second drive here if i do f disk space dash l again remember we also had a slash dev vdb drive and i could certainly do something with that drive maybe what i like to do on my secondary drives i like to have them as dedicated partitions for their own directories so i like to have my music folder for example on its own partition on its own separate drive so that way i never have to worry about when i reinstall you know moving hundreds of gigabytes of music that i have you know stored on one disk in this computer that's kind of nice you may want to have your videos directory stored on its own partition on its own separate drive or your home directory some people just like having their entire home directory on a a separate partition so we certainly could do that i could go back into fdisk and we could this time do slash dev slash vdb for the second drive and this drive is 20 gigabytes in size and this time i'm going to do n for new and then primary partition and then partition number one and then the first sector will just start at the first sector and then the last sector i'm going to make the entire 20 gig uh hard drive the secondary hard drive uh just one partition and it created it as type linux which is correct i'll do another extend4 file system for this it doesn't need to be bootable because we won't be booting off of this disk this secondary disk will be something that gets auto mounted because we'll add this to our fs tab or our file system table later so this is all good i'm just going to do w to write that and now when i do f disc dash l you see we get uh some different information we actually get the actual file system tables that we've created here vda1 vda2 vdb1 and that's really everything you need to know about fdisk i mean from that point forward the rest of the installation would involve other command line tools you know we've already done the partitioning i can actually show you some of the other tools that you'd commonly want to use after fdisk so now that we've done this typically what you want to do let me clear the screen here you want to go ahead and make your file systems so what typically you want to do is as root or with sudo privileges you want to go ahead and mk swap so make swap and you need to give it a device so in my case i made my swap at slash dev slash vda1 and you can see setting up swap space then you need to turn the swap on so swap on slash dev slash vda1 so now we've made the swap and then we've turned the swap on now let's make our extend4 file systems so you want to do this as root or with sudo privileges mkfs for makefilesystem.edu and then the name of the device i'm going to do slash dev slash vda2 and we've made that file system and remember we have another drive we had vdb with just one partition so vdb1 i'm also going to make that an extend4 file system for mounting our home directory on its own partition or my music directory or video directory whatever it is i want to add to that secondary drive and then let me clear the screen now if i want to test out if that secondary drive you know the vdb drive actually would work when we mount it let's go ahead and try it here at the command line so i'm going to as root mount slash dev slash vdb 1 because it needs to be a specific partition and then where do we want to mount that to we want to mount that to slash m t slash let's assume that it's going to be my music directory it says slash m t slash music mount point does not exist so let's go ahead and make deer slash mnt slash music and then rerun the mount command so again mount slash dev slash vdb1 at slash m t slash music and now that's that drive has been mounted to that particular directory of course there's no music in that directory this is a fresh vm there's actually nothing to do here uh typically what you want to do on physical hardware on your real hardware you want to actually auto mount using your fs tab your file system table file typically what you want to do as root you want to open that with vm or whatever editor you use nano slash etsy slash fs tab and in this live environment on arch linux there actually isn't a working fs tab because that actually gets created later during the installation process and i'm not actually going to run through an entire arch installation but i will show you how i do it on my physical machine let me actually switch to a different workspace here so let me open up a terminal here and this is actual my physical machine this is on a virtual machine anymore so if i do it lsblk for list block devices you can actually see i have several drives ignore all the loopback devices these are snaps that are installed but i have actual physical drives installed several of them i have four ssd drives i have sda sdb sdc sdd so four different solid state drives i have a nvme drive as well and if i did a sudo because we need sudo privileges here blk id for block id and then give it my password here you can see i can get the uuid this is a number that is used to identify our drives or our block devices here and what i'm doing is sdb is actually my music directory so i have a drive i have a 256 gig ssd drive that is mounted to my music directory so i get the uuid using the block id command and then what i could do is then i could go into my fs tab and you can see i just add that uuid the mount point the mount point as my music directory and then it's an x104 file system defaults and then zero and two and that's all i did just add that simple line there not very complicated at all then reboot and then that secondary drive in my case sdb should auto mount you know and it definitely auto mounts because if i open you know my graphical file manager here and go to my music directory you can see it's actually here you know i actually have music here and uh it actually works and if it didn't work we actually couldn't read anything in this directory and of course it will actually play music as well if i wanted to play something for you guys let me kill that that's a little bit of me playing there so i actually got a little bit off track with fdisk you got a little bit of how to use fdisk plus some other tools now there's plenty of other command line partition managers other than f disk one i like to use sometimes is a program called cf disk which is very easy to use uh it's you've got just a few controls at the bottom you can see bootable delete resize quit type help if i move my head out of the way there's a couple more commands right it's very self-explanatory i really don't need to show you guys how to use cf disk cf disk is typically used for dos partition tables so master boot record you could also use cg disk for those of you that prefer uefi it's exactly like cf disk it's just for ufi partitions and since i created this as a dos partition table i don't actually think it would let me run this if i tried to run it on slash dev vda for example it probably will complain yeah warning non-gpt so it knows we already created this as a dos partition table so i'm actually just going to cancel that so there are other available tools f disk again it's kind of the standard so when you go to the arch wiki the gen 2 wiki pretty much anybody's wiki and they tell you hey you need to partition a drive use fdisk so it's the tool that i recommend you guys learn now before i go i need to thank a few special people i need to thank the producers of the show and of course i'm talking about absi gabe james mitchell paul scott west economy alan chuck commander angry kirk david dilling gregory heiko mike eryan alexander peace arch and fedor molly dick raver rip private stephen and willie these guys they're my high steered patrons over on patreon without these guys this quick video about the basics of the fds command line partition manager it wouldn't have been possible the show is also brought to you by each and every one of these ladies and gentlemen as well all these names you're seeing on the screen these are all my supporters over on patreon because i don't have any corporate sponsors it's just me and you guys the community if you like my work and want to help support me please subscribe to distrotube over on patreon peace and once you have the drive partition you've done half the arch installation
Info
Channel: DistroTube
Views: 12,104
Rating: undefined out of 5
Keywords: fdisk command, how to create partition in linux, linux tutorial, fdisk command in linux, fdisk command linux, linux tutorial command line, linux, gnu linux, arch linux, gentoo linux, command line linux, linux terminal, fdisk, partitioning your drives, linux installation, how to install linux, creating partitions in linux, cfdisk, cgdisk, mkfs linux, mkfs command in linux, how to partition drive, distrotube, linux commands
Id: LPYfoFSXB9A
Channel Id: undefined
Length: 16min 39sec (999 seconds)
Published: Mon Sep 20 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.