Linux Essentials - Formatting & Mounting Storage Volumes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello again everyone and welcome back to my linux essentials series in today's video we're going to take a look at storage specifically how to add or mount additional storage volumes to our linux workstation or server in addition to that i'm also going to show you my favorite utility for finding out what is using up all the space on your linux installation so it's definitely a tool that you will want to learn how to use and i'm going to show you all about that at the end of today's video but before we get into the content at hand today i want to take a moment to mention the sponsor for today's video the node lenote has been doing cloud computing since 2003 which is actually before amazon web services was even a thing on the node's platform you can get your server up and running in minutes and they include all of the popular distributions such as debian fedora ubuntu and get this even arch linux and let's be honest what could be better than a linux focused cloud server provider that allows you to tell all your friends i run arch the node has multiple server plans available to make any app scalable and flexible you can use it to host a blog a vpn server a minecraft server and much more in fact lenode is the chosen platform that's used to host the entire web presence of learn linux tv and lenode offers 24x7 365 support regardless of plan size so you can get live help from a real person when you need it new users can get started right now with one hundred dollars in credit towards a new account and i highly recommend you check them out because lenode is awesome the note has been a sponsor of learnlinuxtv for quite a while now and i really appreciate it so let's go ahead and dive into storage and see how we can mount additional storage volumes to our linux workstation or server so what you're seeing on my screen right now is my local linux laptop running popos when it comes to storage and linux it's handled a bit differently on desktop linux versus server linux and i want to make sure that i let you guys know about that distinction specifically when i insert a flash drive into my laptop which i'll do right now just saw a message appear at the top of the screen letting me know that the flash drive is available for use if i open up a file manager we can see that my cleverly named flash drive that i named disk is right here if i click on it and then click inside the window i could do whatever i'd like to do i can copy files over to this flash drive i can create a new folder you get the idea when it comes to desktop linux storage is handled pretty much automatically for the most part if i was to plug in an external hard disk or a flash drive as i just did then it's automatically going to mount that device and give me access to it i didn't even have to do anything a message just appeared up here and then in the file manager the flash drive was available but of course as with all things linux there's a lot more to it than that here on the command line i can use the lsblk command to list all of the block devices that are attached to my computer now right here i have a mount point of slash media slash j disk i'll talk a little bit more about the directory structure later but just keep in mind that the lsblk command will give you a list of blocked devices that are attached to your linux workstation or server now in my case this particular storage device has a device name of sdb this is something that's going to vary from one computer or server to another this naming convention does change and actually we see a perfect example of a different name for a storage device just a few lines down we have this nvme drive this is my internal storage device you can see that it has a completely different naming scheme than the first one here now let's cover this naming scheme first sdb is a very common name to give to a storage device when you plug a storage device in it's automatically applied a device name and it makes it available at slash dev and then whatever that device name happens to be and we can see that right here it looks like a file and technically in linux everything's a file but this file represents an actual device other device names are sda sdb like you see here sdc sdd and so on so basically every storage device that you plug in or add to your computer or server that's running linux the kernel is going to provide it with its own name and to prove that what i'm going to do right now is plug in yet another flash drive we should see a message appear at the top of the screen and there it is and now if i execute the lsblk command again as i just did we now have sdc available as well you can see it right there in the dev directory and then we have it right here as well now what's up with sdb1 sdc1 and so on what does that mean and these refer to partitions and this first device right here only has one partition sdb1 under sdc which is the second flash drive that i plugged in we actually have four partitions on that flash drive sdc1 through sdc4 so these are partitions and that's important to understand because in linux when we are working with block devices if we target the device name without a number we are targeting the entire disk essentially but if we do add a number at the end of the device name then we are targeting a very specific partition so as you can see down here i use the ls command again sdc but we also have like i mentioned sdc1 as well sdc2 and so on and the same holds true down here for the nvme storage again this is my internal disk we have partition one partition two three and four a very similar naming scheme but also different different types of storage devices have a different naming scheme so on your end your boot device might be sda for example or maybe it's something like what i have here if you have an nvme disk now the lsblk command is not the only command that we can use to see what partitions are available on a storage device we can use the fdisk command for that as well so for example i can run sudo because i will need sudo for this command in particular and then fdisk and then i'll add dash l and that should give me an information listing for the storage devices on my machine here so like i mentioned earlier we have slash dev sdc it's a storage device that's around 30 gigabytes or so then we have a listing of the partitions down here for sdb we only have this one partition that you see here so what i'm going to do right now is remove one of the flash drives and on desktop linux that's very easy we just open up a file manager and we can see that we have the second flash drive here this is a flash drive that i used to install zubuntu for a review that i did some time ago and right next to it we have an eject button so like the message showed at the top of the screen i can remove the flash drive and i just did that's a method that you can use to disconnect a storage volume from a system running desktop linux however if you are running linux on a server then generally speaking you don't actually have a gui or graphical user environment available so what i'm going to do right now is give you some additional examples for managing storage but i'm going to do everything on the command line so for this next example we need to have a disk that we can work with a disk that we don't mind if it gets completely wiped out so if you have an empty disk like a flash drive for example or maybe a storage device that isn't empty but you don't care about the contents then we can continue and the type of storage device doesn't really matter if you're using something like virtualbox for example you could create a new virtual disk if you're using lenode you can add a new block storage device if you have a physical laptop desktop or server then you can attach a usb hard drive or flash drive so what i like to do first is run lsblk before i actually attach any storage device and what that's going to do is just give me a list of the current storage volumes that i have and now i'm going to insert a flash drive and now that i've inserted a flash drive i'll run lsblk again and i now have sdb right here on the list now again the reason why i like to run the lsblk command before and after inserting a flash drive or some sort of storage device is because it makes it extremely obvious which one is the new one now there's no question because we have sdb right here and we didn't have that before so that can only mean that this device right here is the one that i inserted now there's another command that i would like to show you and it's a very easy one it's just simply mount just like that when i press enter this is going to list all of the mounted storage devices on the system there's going to be quite a few believe it or not as you can see so there's going to be quite a few system devices as well and we're going to ignore those but what we can do to narrow down the output here a little bit further since we know what the device name is from the lsblk command we can actually grab for that name and what this is going to do is show us every volume that is mounted that matches that criteria there's only one in this case but if you have more than one partition you might see more than one entry here in the mount table this is just another helpful command that you might use to check what is mounted on your system now what i want to do is actually wipe out my disk i'm going to wipe out my flash drive and create a brand new partition table on it now again this is going to wipe out everything and i do mean everything on that flash drive so don't continue unless you actually do want to remove everything on that device and also make sure that you take your time with all of the commands that i'm about to give you because some of these could actually cause your machine not to boot if you make a typo but as long as we use the proper device name we should never run into that problem and i showed you earlier how to tell what the new device name actually is again you just run the lsblk command before and after you add the storage device and it should be fine in my case the storage device that i'm going to be working with is sdb on your end is probably going to be named something else just make sure that you substitute the device name that you see on my screen with the proper device name on your system anytime i run a command just to make sure that you are targeting the correct disk now before i wipe out this disk it's a good idea to unmount it in the case of desktop linux i showed you that we have an eject button right here but we don't want to click on that the thing is on some desktop environments if we click the eject button it'll actually remove the disk from the bus and we won't even be able to work with it at all so instead of clicking this here what we're going to do instead is unmount the drive through the command line so in my case we have sdb1 right here and it's mounted at slash media j disk so what i can do is run sudo u-mount and yes the n is missing it's supposed to be missing we are going to un-mount a device but the command is u-mount a little confusing but the u-mount command will unmount a device what we could do is run that against the device that we want to remove so slash dev slash and then the device name or we can actually run it against the path that we see right here and if i run lsblk again we can see that there's no longer a directory path here which means that that device is no longer mounted and we could prove that by running mount and then we can grep for the device name we get no output so we know for sure that that device is not mounted so now what we can do is run the fdisk command with sudo and we can run that against the device that we want to create a new file system on so slash dev sdb in my case so now we have the fdisk prompt here and one thing that we can do here is print the current partition table by simply pressing p and then enter as we already know we only have this one partition right here but if you are curious what partitions you currently have on your storage device the one that you executed the fdisk command against well now you know as it says here we could type m and then enter for help and it actually gives us a list of commands that we can use so we can scroll up to see the others and what i want to do is create a new partition table and the type of partition table that i recommend is gpt as you can see here we could type g and then press enter and that's going to create a new partition table and it's going to be the gpt type gpt is basically recommended in almost every use case the alternative is mbr but we're not going to use that anymore we're going to use gpt especially considering gpt can handle larger disks so it's pretty important in my case it doesn't really matter because my flash drive is only around 30 gigabytes but you get the idea so now if i press p and then enter as you remember that gives us a listing of the partitions that we have on our disk we have none currently because i created a new partition table but even though i created a new partition table i didn't yet create a partition i could create a partition by pressing n for new and then enter and it's going to walk me through the process of creating a new partition table on my disk for the partition number that i want to create this is the very first partition i just created the partition table so a default of one is appropriate the first sector there's probably no reason to change this i'll press enter and the last sector here we can make this a fixed size or we can simply press enter to make it take up the entirety of the disk i'll press enter because i do want it to take the entirety of the disk and it's letting me know that it already has a partition on the disk yes i did tell it to create a new partition table but none of these changes are actually final unless i finalized them at the end so it still detects that i have a partition here it's just trying to make sure that i'm okay with removing it which i am and at the end here is telling us that if we were to write the changes it's going to make the signature final which is actually going to be what removes all the data from the flash drive so what i'm going to do right now is type w for write and then enter and that's what's going to make the changes final but we're not actually done yet the thing is we can't really use a storage device unless we have a file system on that device and we just created a brand new partition table and partition but we didn't actually format the partition so right now the disk is pretty much useless now thankfully we have the mkfs command at our disposal and what this command will do is allow us to format the partition with whatever file system type we want and as far as which one to go with because there's quite a few what you want to focus on is which operating systems you plan on using your storage device with if you are formatting an internal hard disk then you should probably format it with a linux file system type if it's an external storage device for example a flash drive and you plan on inserting that into a windows computer or a mac for example then you'll probably want to choose expat for that if it's a linux file system meaning you want to use the storage device on a linux machine then you're going to want to type the command out as mkfs.ext4 and then the path to the device name for that device i'm not going to press enter just yet but i wanted to make sure that you have the command that you would use to format it as a linux partition which is what this will do now when it comes to windows systems and macs those operating systems are not able to see linux file systems by default so in any situation where you plan on using your storage device on multiple operating systems you might want to consider expat for that but unfortunately on my end this command will not work so as you can see here is telling me that that command is not found and that's actually very common because expat is a microsoft technology and a lot of linux distributions are a little cautious when it comes to adding support for proprietary things in their distribution so in order for us to be able to use xfat we're going to have to install the appropriate packages on debian and ubuntu that's simple we can run sudo apt install and then the packages that we want to install our exfat hyphen utils and exfat hyphen fuse goes right there i'll press enter it takes no time at all to get those installed so if i recall the previous command the one that originally failed and told me command not found it's working this time so all we had to do was add support for expat and then we were able to format the flash drive with the expat file system which should make it cross-platform and work on other operating systems and again this is the command right here that i used to install those packages if you are not running on a debian or ubuntu system then that command is going to be a bit different on centos and fedora for example you're going to use the dnf command instead of apt and the packages on those distributions are going to be fuse hyphen xfat and expat utils i'm not going to press enter here because if i did that command would fail there's no such thing as dnf on an ubuntu based distribution but if you are running on fedora sent to us or something like that then this is the command that you would use to get x fast support on your system now the thing is this command right here might fail and the reason for that is because you might have to add a separate repository in order to get access to these packages on fedora you'll probably end up needing to add the rpm fusion repository and on centos more than likely it's going to be apple e-p-e-l but anyway we have sdb-1 i'm going to remove the flash drive it's not mounted i reinserted it and now that i've reinserted the flash drive you can see that it is mounted i didn't give it a label so i actually got a random label on that device as an aside with the mkfs.exfat command you can use the dash n option to give it a label so what i could have done is i could have added dash n right here and then i can call the disk whatever i'd like where we have the double quotes there you just put whatever your label should be for that device that way it's not going to get a generic name now one of the more important commands that you should know when it comes to managing storage is the df-h command and that's going to show you how much space is used up on any of the mounted file systems so for example my root file system we know it's a root file system because we have a single forward slash i covered this in a previous video you can see here that i have 875 gigabytes free so i'm not in any danger whatsoever of losing space on this volume anytime soon now if you are on a server this disk would not have been mounted automatically so what i'm going to do right now is show you guys how to mount storage devices manually but currently i'm running linux on a laptop so it automatically mounted the flash drive as soon as i inserted it so before i go any further in simulating this workflow i'm going to need to unmount it like we went over earlier the u-mount command is the command that we would use to unmount a file system so the onmount command looks just like that again the lack of an n is intentional and now that's unmounted so the act of mounting a storage volume is essentially attaching it to a folder on the file system and that'll most likely lead you to ask which folder in particular should you attach your storage volume to the short answer is any folder you want really however there's a few folders that are considered the appropriate places to mount a storage volume linux will suggest where you should do that but not enforce it so what i'm going to do is just list the storage of the root file system we have slash right here we also have slash media as well right here those are the two folders that are considered the most appropriate when you go to mount a storage volume to your linux workstation or server but now you'll probably want to know when to use media and when to use mnt the short answer is slash media and i say slash because the media folder is at the beginning of the root file system which is designated by a slash slash media is for basically temporary storage volumes and what i mean by temporary is any storage volume that is not actually going to be attached all the time for example maybe you want to back up your server so in that case maybe you'll attach an external hard drive you run some kind of backup utility it'll back up all your files and then you'll unmount that file system as soon as you're done with it that's an example of a temporary file system mnt is more for the permanent file systems things you generally want to be available all the time an example of that is adding a second hard drive to a desktop or perhaps a server perhaps that hard disk is going to be something that you always want to have installed in that case that drive is probably most appropriate to be mounted in slash m t but you know what it's your workstation or server so you can mount it wherever the heck you want to nobody's going to yell at you if you mount it in a very weird spot but i think overall it's generally a good idea to mount things under mnt or slash media so what i'm going to do right now is show you how to mount a file system and in my case i'm going to mount the flash drive that we just formatted and i'm going to mount it to a subfolder of slash m t we don't even have a subfolder in mnt at this time so what i'll do is i will actually make a new directory i'm just going to call it disk one and as you can see we have the folder right there again the lsblk command will show you a list of storage volumes that you have attached in my case i know it's slash dev slash sdb1 that's the first and only partition of disk sdb so what i'm going to do is run sudo and then mount i'm going to mount slash dev slash sdb1 and i'm going to mount that to the subdirectory that i created in slash mnt slash mnt slash disc one and it was literally that simple you can see right here that we have a mount point listed four slash dev sdb1 we see the storage name right here and we mounted it right here so if i run df-h you can see that it's listed down here mnt slash disc one there it is it's mounted and it's ready to go now in my case you could argue that this flash drive is probably more of a temporary device and should have been mounted underneath slash media but this is just a hypothetical situation it's up to you where you want to mount your storage devices just think about the use case and then make the appropriate decision now what i'd like to do is show you my favorite utility for checking out the storage space on your server this utility will actually scan your file system and let you know what is using the most space it's indispensable in a situation where you have a server that is running out of space and in that situation you have to find out what in particular is using up all your space and for that i like to use the ncdu command now it's often not installed by default though and in my case you can see that it is not installed on debian or ubuntu or any distribution based on debian or ubuntu you can run sudo apt install and cdu and i highly recommend that you install this on every single linux installation that you have reason being if you run into a situation where your disk is 100 full then you won't be able to install this because you need some available disk space in order to install a package and if you don't already have this installed when your hard disk gets full then you won't be able to add it so it's just better to install it before it becomes a problem and hope that you don't end up needing it on fedora centos and related distributions you would basically just change apt to dnf those distributions use a different package manager and on those you might have to add another repository such as apple on centos and rpm fusion on fedora i don't have a fedora system right now to test it on so if you run this command on one of those distributions and it doesn't work that probably means that you need to add another repository when you execute ncdu i recommend that you do that with sudo and the reason for that is because the ncdu command will only have access to the directories that the user that called the command has access to so if you don't use sudo there's going to be a ton of directories that you don't have access to c so the results of ncdu will not be correct in that case now in my case this command actually ran very quickly if you have a workstation or server with a lot of data then it's not uncommon for ncdu to take a few minutes to complete as you can see here i don't really have that much used on this computer that makes sense i actually just installed linux on this machine earlier today i haven't even had a chance to store anything yet but what i like about this tool is that it gives you a listing of everything that is using the most space so at the top i have the dot cache directory and that's not using all that much space but it is the number one biggest folder in my home directory we can see up here the scan is being run from my home directory so what i should have done was add the single forward slash here to tell ncdu that i wanted to scan my entire file system let's try that again so we see that the scan is taking a little bit longer this time so from this output we can actually see that the folder that has the most inside it is the slash usr directory at 6.2 gb if i press enter on that it's actually going to allow me to drill down and see the contents of that directory and i could just keep going so for example i can arrow down to share and i could just keep drilling down even further until i find something that i can delete if i run into a situation where i'm running out of space when you're done you just press q to quit out and then that takes you back to the command line you could also consider using dash x at the end and what dash x allows you to do is exclude attached file systems other than the main file system so the dash x option will not show anything that you have mounted only the local file system will be shown with this option in my case the output isn't going to be any different i don't really have anything on my flash drive so yeah this will exclude the flash drive but the flash drive is empty it's not going to make a difference but if you have a very large network drive mounted and you don't want to scan it you want to just focus on the local file system then use dash x it'll make the entire process that much quicker again when you're done just type q and that brings you back to the command line now the last thing that i want to show you guys in this video is the slash etsy slash fstab file this is a very very very important file on your linux system if you edit this file and you make a mistake your system might not boot so just keep that in mind but what this file allows you to do is automatically mount something every time your machine starts generally there's already going to be content inside this file as you can see here we have the root file system uuids are beyond the scope of this particular video but just think of those as a more specific name for the device names that we went over earlier this name here is going to be a universally unique identifier which is better so i'm not going to cover the fstab file in this particular video i think that's probably better in a dedicated video but for now i just wanted you to be aware of its existence because when your linux system boots it looks at this file and it's going to mount everything that's included here line by line so in the case of a brand new hard disk if you want that to be mounted automatically then adding a line to this file is the way to do it so there you go i showed you guys how to add additional storage volumes to your linux system i hope this tutorial was helpful and taught you what you needed to know to get started with managing storage volumes on your system if you like this video make sure you click that like button because that lets youtube know that you want to see more content just like this and also make sure to subscribe because i have some awesome content coming very soon so stay tuned for that anyway thanks for watching i really appreciate [Music] it [Music] you
Info
Channel: LearnLinuxTV
Views: 17,568
Rating: 4.9966216 out of 5
Keywords: Linux, Tutorial, Howto, Guide, Distro, Learn Linux, operating system, os, gnu/linux, LearnLinuxTV, storage, linux storage, volumes, store, disk, virtual disk, mount command, mount, lsblk, fdisk, ext4, exfat, mkfs, mkfs.ext4, mkfs.exfat command not found, mkfs.exfat install, mkfs.exfat ubuntu, information technology, how to, linux tutorial, linux commands, for beginners, linux for beginners 2021, open source software, linux tutorial ubuntu, block storage, volume, how to partition a disk in linux
Id: 2Z6ouBYfZr8
Channel Id: undefined
Length: 32min 28sec (1948 seconds)
Published: Tue Jul 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.