How Linux mounts new hard disks and creates swap partitions

Source: Internet
Author: User
Tags uuid

Liunx Adding a new hard drive is actually the same as windows, but one is graphical and the other is command-line action, but the steps are the same, and the following is a hands-on demonstration and explanation

Linux mount new Hard drive 1, view hard disk information

Command: Fdisk-l

[[email protected] ~]# fdisk -lDisk /dev/vda: 21.5 GB, 21474836480 bytes                                           #第一块硬盘的信息和分区信息255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x0003a7b4   Device Boot      Start         End      Blocks   Id  System     /dev/vda1   *           1        2611    20970496   83  LinuxDisk /dev/vdb: 107.4 GB, 107374182400 bytes                                        #第二块硬盘的信息和分区信息16 heads, 63 sectors/track, 208050 cylindersUnits = cylinders of 1008 * 512 = 516096 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000
2. Create a new hard disk partition

Command: FDISK/DEV/VDB

[[email protected] ~]# fdisk/dev/vdbdevice contains neither a valid DOS partition table, nor Sun, SGI or OSF Disklab Elbuilding a new DOS disklabel with disk identifier 0x1e694286. Changes'll remain in memory only, until the decide to write them. After that, of course, the previous content won ' t is recoverable. Warning:invalid flag 0x0000 of partition Table 4 would be a corrected by W (rite) warning:dos-compatible mode is deprecated. It ' s strongly recommended to switch off the mode (command ' C ') and change display units to sectors (Comman d ' u '). Command (M for help): Ncommand action E extended #e为创建扩展分区 p Primary partition (1-       4) #p为创建逻辑分区pPartition number (1-4): 1 #在这里输入1, enter the division logic partition stage; first cylinder (1-208050, default 1): 1 #分区的Start value, it is best to press ENTER directly, otherwise it may cause wasted space; Using default value 1Last cylinder, +cylinders or +size{k,m,g} (1-208050, default 208050): 208050 #分区的Over值, I'll divide one district using default value 208050ComMand (M for help): W #最后输入w回车保存退出. The partition table has been altered! Calling IOCTL () to re-read partition table. Syncing disks.

Fdisk can use the M command to see the internal commands of the FDISK command;
A: The command specifies the boot partition;
D: command to delete an existing partition;
L: command displays a list of partition ID numbers;
M: View the fdisk command help;
N: command to create a new partition;
P: command displays a list of partitions;
T: Command modifies the type ID number of the partition;
W: The command is to save changes to the partition table to make it work;

3. Confirm the new partition information

Command: Fdisk-l

[[email protected] ~]# fdisk -lDisk /dev/vda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x0003a7b4   Device Boot      Start         End      Blocks   Id  System     /dev/vda1   *           1        2611    20970496   83  LinuxDisk /dev/vdb: 107.4 GB, 107374182400 bytes16 heads, 63 sectors/track, 208050 cylindersUnits = cylinders of 1008 * 512 = 516096 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x1e694286   Device Boot      Start         End      Blocks   Id  System     /dev/vdb1               1      208050   104857168+  83  Linux           #刚创建好的分区信息
4. Format the partition

Command: MKFS.EXT4/DEV/VDB1

  [[email protected] ~]# mkfs.ext4/dev/vdb1 mke2fs 1.41.12 (17-may-2010) Filesystem label= #文件系统标签OS type:linux #操作系统类型Block size=4096 (log=2) #块大小Fragment size=4096 (log=2) #分块大小St  Ride=0 blocks, Stripe width=0 blocks6553600 inodes, 26214292 blocks1310714 blocks (5.00%) reserved for the Super Userfirst Data block=0 #第一个数据块Maximum filesystem blocks=4294967296800 block groups32768 blocks per group, 32768 fragments Per group8192 inodes per groupsuperblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 88473                           6, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872Writing inode tables:done #写入inode表Creating Journal (32768 blocks): donewriting superblocks and filesystem accounting Information:donethis Filesy  Stem would be automatically checked every-mounts or180 days, whichever comes first. Use Tune2fs-c or-i to override.  

Description of the Linux partition type:
With the application of Linux system in the present business, the weaknesses of Linux file system are gradually revealed, in which the system default Ext2 file system is non-log file system. This application in key industries is a deadly weakness. While the Ext3 file system is developed directly from the Ext2 file system, the Ext3 file system is now very stable and reliable. It is fully compatible with the Ext2 file system.
EXT3 Features: High availability, data integrity, data integrity, data conversion, multiple logging modes
The same EXT4 is fully compatible with EXT3, compared to EXT3, EXT4 supports larger storage, EXT3 currently supports the largest 16TB file system and maximum 2TB files, and EXT4 supports 1EB file systems, 16TB files, and EXT3 currently supports only 32 , 000 subdirectories, while EXT4 supports an unlimited number of subdirectories, EXT4 introduces the popular extents concepts in modern file systems, each extent as a contiguous set of data blocks, which is represented as "the file data is stored in the next 25,600 data blocks", Improved a lot of efficiency.

5. Create mount Directory

Command: Mkdir/data

6. Mount Partition

Command: Mount/dev/vdb1/data

7. View hard disk size and mount partitions

Command: df-th

[[email protected] ~]# df -ThFilesystem     Type   Size  Used Avail Use% Mounted on/dev/vda1      ext4    20G  1.1G   18G   6% /tmpfs          tmpfs  3.9G     0  3.9G   0% /dev/shm/dev/vdb1      ext4    99G   60M   94G   1% /data           #新挂载的分区
8. Configure auto mount on boot

Command: Vim/etc/fstab
/dev/vdb1/data EXT4 Defaults 1 1

[[email protected] ~]# blkid/dev/vda1: UUID="b7aae0d4-268c-4b60-914a-f3b48e22819c" TYPE="ext4" /dev/vdb1: UUID="5de835dd-5322-46f0-8728-3d4ae7d83b54" TYPE="ext4" [[email protected] ~]# cat /etc/fstab## /etc/fstab# Created by anaconda on Tue Mar 27 04:51:55 2018## Accessible filesystems, by reference, are maintained under ‘/dev/disk‘# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info#UUID=b7aae0d4-268c-4b60-914a-f3b48e22819c      /                       ext4      defaults      1 1UUID=5de835dd-5322-46f0-8728-3d4ae7d83b54     /data                ext4   defaults    1 1tmpfs                   /dev/shm                tmpfs   defaults        0 0devpts                  /dev/pts                devpts  gid=5,mode=620  0 0sysfs                   /sys                    sysfs   defaults        0 0proc                    /proc                   proc    defaults        0 0
Swap partition

The swap partition, like virtual memory on Windows, frees up a portion of the physical memory to be used by the currently running program when the physical memory of the system is not enough. The freed space may come from programs that have not been manipulated for a long time, and the freed space is temporarily saved to the swap partition until those programs are run and the saved data is restored to memory from the swap partition.

Here are two ways to create a swap:

    • Create a new disk partition as a swap partition
    • Use a file as a swap partition
Create a new disk partition as a swap partition
    1. Partition the disk with the Fdisk command, add a swap partition, create a new partition, and use the "T" command in Fdisk to change the newly added partition ID to 82
      (Linux swap type)

    2. Format the swap partition, where the SDB2 depends on the actual partition device name displayed after you add the P command

      Mkswap/dev/sdb1

    3. Start a new swap partition

      Swapon/dev/sdb1

    4. Allow the system to start automatically enable this swap partition, you can edit/etc/fstab, add the following line

      /DEV/SDB1 swap swap defaults 0 0

Use a file as a swap partition

1. Create a file to be a swap partition: increase the 1GB size of the swap partition, the command is written as follows, where count equals the number of blocks you want (bs*count= file size).

DD If=/dev/zero of=/root/swapfile bs=1m count=1024

2. Format the swap partition file to create the swap file system:

Mkswap/root/swapfile

3. Enable the Swap partition file:

Swapon/root/swapfile

4. Make the system self-enabled when booting, add a line in file/etc/fstab:

/root/swapfile swap swap defaults 0 0

How Linux mounts new hard disks and creates swap partitions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.