In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how to create a file system in a Linux partition or logical volume". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor learn how to create a file system in a Linux partition or logical volume.
In Linux, when you create a hard disk partition or logical volume, you usually create a file system by formatting the partition or logical volume. This method assumes that you already know how to create a partition or logical volume, and you want to format it to contain the file system and mount it.
Create a file system
Suppose you add a new hard drive to your system and create a partition called / dev/sda1 on it.
1. To verify that the Linux kernel has found this partition, you can cat the contents of / proc/partitions, like this:
[root@localhost] # cat / proc/partitionsmajor minor # blocks name 253 0 10485760 vda 253 1 8192000 vda1 11 0 1048575 sr0 11 1 374 sr1 8 0 10485760 sda 81 10484736 sda1 252 03145728 dm-0 252 1 2097152 dm-1 252 1048576 dm-2 8 16 1048576 sdb
2. Decide what kind of file system you want to create, such as ext4, XFS, or something else. Here are some options:
[root@localhost ~] # mkfs.mkfs.btrfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs
3. For the purpose of this exercise, choose ext4. I like ext4 because it allows you to compress the file system if you need it, which is not easy for XFS. Here is how to do it (the output may vary depending on the device name or size):
[root@localhost] # mkfs.ext4 / dev/sda1mke2fs 1.42.9 (28-Dec-2013) Filesystem label=OS type: LinuxBlock size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=8191 blocks194688 inodes, 778241 blocks38912 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=79901491224 block groups32768 blocks per group, 32768 fragments per group8112 inodes per groupSuperblock backups stored on blocks: 32768,98304,163840,229376,294912 Allocating group tables: doneWriting inode tables: doneCreating journal (16384blocks): doneWriting superblocks and filesystem accounting information: done
4. In the previous step, if you want to create different file systems, please use different variants of the mkfs command.
Mount the file system
When you have created the file system, you can mount it in your operating system.
1. First, identify the UUID encoding of the new file system. Use the blkid command to list all recognized block storage devices and look for sda1 in the output:
[root@localhost] # blkid/dev/vda1: UUID= "716e713d-4e91-4186-81fd-c6cfa1b0974d" TYPE= "xfs" / dev/sr1: UUID= "2019-03-08-16-17-02-00" LABEL= "config-2" TYPE= "iso9660" / dev/sda1: UUID= "wow9N8-dX2d-ETN4-zK09-Gr1k-qCVF-eCerbF" TYPE= "LVM2_member" / dev/mapper/test-test1: PTTYPE= "dos" / dev/sda1: UUID= "ac96b366-0cdd-4e4c-9493-bb93531be644" TYPE= "ext4" [root@localhost ~] #
2. Run the following command to mount / dev/sd1 device:
[root@localhost ~] # mkdir / mnt/mount_point_for_dev_ sda1 [root @ localhost ~] # ls / mnt/mount_point_for_dev_ sda1 [root @ localhost ~] # mount-t ext4 / dev/sda1 / mnt/mount_point_for_dev_sda1/ [root @ localhost ~] # df-hFilesystem Size Used Avail Use% Mounted on/dev/vda1 7.9G 920m 7.0G 12% / devtmpfs 443M 0443M 0% / devtmpfs 463M 0463M 0% / dev/shmtmpfs 463m 30m 434m 7% / runtmpfs 463M 0463M 0% / sys/fs/cgrouptmpfs 93M 093M 0% / run/user/0/dev/sda1 2.9G 9.0M 2.7G 1% / mnt/mount_point_for_dev_ sda1 [root @ localhost ~] #
The command df-h shows the mount point where each file system is mounted. Find / dev/sd1. The device name used by the mount command above is / dev/sda1. Replace it with the UUID code in the blkid command. Notice that / dev/sda1 is mounted under / mnt by the newly created directory.
3. There is a problem with using the mount command directly from the command line (as in the previous step), that is, the mount will not exist after the device is rebooted. To mount the file system *, edit the / etc/fstab file to contain your mount information:
UUID=ac96b366-0cdd-4e4c-9493-bb93531be644 / mnt/mount_point_for_dev_sda1/ ext4 defaults 0 0
4. After editing the / etc/fstab file, you can umount / mnt/mount_point_for_fev_sda1 and run the mount-a command to mount all device files listed in the / etc/fstab file. If all goes well, you can use df-h to list and view your mounted file system:
Root@localhost ~] # umount / mnt/mount_point_for_dev_sda1/ [root @ localhost ~] # mount-a [root@localhost ~] # df-hFilesystem Size Used Avail Use% Mounted on/dev/vda1 7.9G 920M 7.0G 12% / devtmpfs 443M 0443M 0% / devtmpfs 463M 0463M 0% / dev/shmtmpfs 463M 30M 434M 7% / runtmpfs 463M 0463M 0% / sys/fs/cgrouptmpfs 93M 093M 0% / run/user/0/dev/sda1 2.9g 9.0m 2.7G 1% / mnt/mount_point_for_dev_sda1
5. You can also check whether the file system is mounted:
[root@localhost ~] # mount | grep ^ / dev/sd/dev/sda1 on / mnt/mount_point_for_dev_sda1 type ext4 (rw,relatime,seclabel,stripe=8191,data=ordered)
Now you know how to create a file system and mount it on your system for a long time or not.
At this point, I believe you have a deeper understanding of "how to create a file system in a Linux partition or logical volume". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.