课程: Linux: Storage Systems

Basic commands for storage partitions - Linux教程

课程: Linux: Storage Systems

Basic commands for storage partitions

- [Instructor] Let's talk about discs and partitions. So you might have lots of discs and lots of partitions. You can find out about the partitions on your Linux system by looking at the proc file slash proc slash partitions. And of course, things in proc are information direct from the colonel. So this is what the colonel sees. So we cat that out. And in the slide here, we see some partitions with names like SDA, SDA1, SDA2. Really, the partitions are the one and the two. The column major is which device driver, eight is scuzzy. The minor number is used by the device driver to identify the disc and the controller. So we can see partitions have different minor numbers, and the blocks are the size of the disc or the partition. Toward the bottom of the list, we see an SR0 Notice it has a different major number, a different driver and that, turns out, it's for a CD drive. And then we have a second scuzzy disc. And scuzzy is used for lots of kinds of things besides scuzzy these days. And that disc is disc B and has one partition. A handy command to work with discs and partitions is F disk. There are some other commands like parted is popular, but let's look a little bit at F disk. So notice what the example there, F disk /dev SD. We got the hash or pound sign prompt, reminding us this is a privilege command and you could use SUDU or just switch over to have your shell running as root. Then in F disk, we get a prompt, command M for help, and we typed in the letter P for partition and it listed out the partitions and information about that disc. So we see different partitions here start and end sectors, size and type. So we'll see that you can label a partition with a type and that can be handy for Linux to know a little bit more about what to do with it. And we can create new partitions if there's space left, unpartitioned space left. And both F disk and parted could be used for creating partitions. And like we mentioned, it's kind of a good idea to set the partition type, but there will be a default. And these days, system D is the most common and a big system demon on your Linux system. And it can take advantage of having the proper label set on a partition. So let's take a look at using F disk a little bit. So here I am, I'm in a VM running Ubuntu, and I'm already as root with my prompt there. If I do F disk minus L, we get all kinds of things. So loop devices aren't really discs. The real discs are dev SD and we have B and C and A. We see the bottom on top. So this particular VM has three discs. Let's do a little bit of experimentation with dev SDB. Double, triple check your type in here because if you did A, that's your system disc and messing with that could cause you lots of pain and suffering. So on this system, I'm not using B currently for anything. So I could do whatever I want, and I'm not going to be shooting myself in the foot. I'll type P, they'll list what we got, and what does it say we have? It doesn't list any partitions. So let's create a partition. We'll do N. Partition number default is one. So we'll go with that first sector. We'll just take the default, that's where it's going to start. Last sector or size, so I'm just going to make a little partition here. I'm going to go 100. I know you got to do the plus sign there. A hundred M, only a hundred meg. Tiny little partition. Create a new partition, one of type Linux file system. So it gave a label by default of, it's going to be a Linux file system. And it turns out I had experimented with this before and I had created a partition and I had formatted it with EXT 4. So now it's in red here, warning us, hey, this already has an EXT four file system, it looks like. Are you sure you want to do this? Do you want to remove that signature and all? And yeah, I do in this case, but it's nice to get warnings before you do something terrible. Okay, and it says the signature will be removed by a write command, but let's do the P again. And we have one partition now, SDB one, and it's saying the signature will be wiped. That's okay. Let's make another partition. And we do N, default will be two. First sector ends where the last one starts. Let's do another little one. We'll do 200 meg, and it says Linux file system. Let's do an L to see what kind of partitions we can have. And it does a big list here. And notice all kinds of Linux things for different operating systems or different architectures. We're going to scroll through and we see lots of Linux ones. And then we see at the bottom, some aliases, including swap and Linux and RAID and LVM. Those are nice for Linux. So let's make a swap partition for number two. So I'm going to go type T default, that's the newest partition number two, and let's type swap. And now if we do a P for listing them, we see our two partitions and we see one is to put a Linux file system on and one is for swap. We will write it out with W. And it rewrote everything and it overwrote that disc and we really want to be sure that was the right disc. It was. And there we go.

内容