Linux mount new hard drive to directory, and automatically mount example

Source: Internet
Author: User
Tags uuid


Today, as you organize your pictures, found that the root directory hard disk space has been left, and the site and all related files are mainly placed in the root of the data directory (/data), but the/home is there is room, and do not want to put the file under/home, only add a new hard drive, for later/ The file management of the data directory is also better.

Then turn off the host, plus a new hard drive (other computer used 500G hard disk), plug in and then start the computer.

Next, we start to work:

1. View Hard Drive information:

feigo@figo:~$ sudo df-h


File system capacity used available% mount point


Rootfs 102G 92G 4.7G 96%/


Udev 10M 0 10M 0%/dev


Tmpfs 799M 1.8M 798M 1%/run


/dev/disk/by-uuid/3640f24a-4870-42e2-ae07-109cb9c35164 102G 92G 4.7G 96%/


Tmpfs 5.0M 0 5.0M 0%/run/lock


Tmpfs 4.6G 224K 4.6G 1%/RUN/SHM


/dev/sda7 92M 26M 62M 30%/boot


/DEV/SDA9 201G 23G 169G 12%/home


feigo@figo:~$ sudo fdisk-l





disk/dev/sdb:500.1 GB, 500107862016 bytes


255 heads, Sectors/track, 60801 cylinders, total 976773168 sectors


Units = sectors of 1 * the bytes


Sector size (logical/physical): bytes/512 bytes


I/O size (minimum/optimal): bytes/512 bytes


Disk identifier:0x3f1e271a





Device Boot Start End Blocks Id System


/DEV/SDB1 102414374 51207156 7 Hpfs/ntfs/exfat


/DEV/SDB2 102414375 976768064 437176845 f W95 Ext ' d (LBA)


/DEV/SDB5 102414438 409625369 153605466 b W95 FAT32


/DEV/SDB6 409625433 716836364 153605466 b W95 FAT32


/DEV/SDB7 716836428 976768064 129965818+ 7 Hpfs/ntfs/exfat





disk/dev/sda:500.1 GB, 500107862016 bytes


255 heads, Sectors/track, 60801 cylinders, total 976773168 sectors


Units = sectors of 1 * the bytes


Sector size (logical/physical): bytes/512 bytes


I/O size (minimum/optimal): bytes/512 bytes


Disk Identifier:0xc35aebd4





Device Boot Start End Blocks Id System


/DEV/SDA1 * 104872319 52436128+ 7 Hpfs/ntfs/exfat


/dev/sda2 104872381 976771071 435949345+ f W95 Ext ' d (LBA)


/dev/sda5 104872383 231962534 63545076 7 Hpfs/ntfs/exfat


/dev/sda6 231962598 300929579 34483491 b W95 FAT32


/dev/sda7 300931072 301125631 97280 Linux


/dev/sda8 301127680 517726207 108299264 Linux


/DEV/SDA9 517728256 945461247 213866496 Linux


/DEV/SDA10 945463296 976771071 15653888 Linux Swap/solaris


We can see that there are two hard drives, SDA and SDB, where SDA is currently in use in the hard drive, SDB is the new plus go hard drive.

2. Create a new hard disk partition for SDB:

First of all, Fdisk can use the M command to look at the internal commands of the FDISK command:


A: command specifies the boot partition


D: command to delete an existing partition


L: command displays a list of partition ID numbers


M: View fdisk command Help


N: command to create a new partition


P: command displays partition list


T: Command modifies the partition's type ID number


W: The command is to save changes to the partition table to make it work


feigo@figo:~$ su


Password:


root@figo:/home/feigo# Fdisk/dev/sdb





Command (M for help): M


Command Action


A toggle a bootable flag


b Edit BSD Disklabel


C Toggle the DOS compatibility flag


D Delete a partition


L list known partition types


M Print this menu


n Add a new partition


o Create a new empty DOS partition table


P Print the partition table


Q Quit without saving changes


s create a new empty Sun Disklabel


t change a partition ' s system ID


U Change display/entry units


V Verify the partition table


W Write table to disk and exit


X Extra functionality (experts only)


Because there are already several partitions on the SDB hard disk, people need to remove these partitions first:


Command (M for help): D # Delete partitions, and then enter numbers


Partition number (1-7): 7





Command (M for help): D


Partition number (1-6): 6





Command (M for help): D


Partition number (1-5): 5





Command (M for help): D


Partition number (1-5): 2





Command (M for help): D


Selected partition 1





Command (M for help): W # Save


The partition table has been altered!





Calling IOCTL () to re-read partition table.


Syncing disks.

View the hard disk partition information again, and you will see that all partitions have been deleted:


root@figo:/home/feigo# fdisk-l





disk/dev/sdb:500.1 GB, 500107862016 bytes


255 heads, Sectors/track, 60801 cylinders, total 976773168 sectors


Units = sectors of 1 * the bytes


Sector size (logical/physical): bytes/512 bytes


I/O size (minimum/optimal): bytes/512 bytes


Disk identifier:0x3f1e271a





Device Boot Start End Blocks Id System





disk/dev/sda:500.1 GB, 500107862016 bytes


255 heads, Sectors/track, 60801 cylinders, total 976773168 sectors


Units = sectors of 1 * the bytes


Sector size (logical/physical): bytes/512 bytes


I/O size (minimum/optimal): bytes/512 bytes


Disk Identifier:0xc35aebd4





Device Boot Start End Blocks Id System


/DEV/SDA1 * 104872319 52436128+ 7 Hpfs/ntfs/exfat


/dev/sda2 104872381 976771071 435949345+ f W95 Ext ' d (LBA)


/dev/sda5 104872383 231962534 63545076 7 Hpfs/ntfs/exfat


/dev/sda6 231962598 300929579 34483491 b W95 FAT32


/dev/sda7 300931072 301125631 97280 Linux


/dev/sda8 301127680 517726207 108299264 Linux


/DEV/SDA9 517728256 945461247 213866496 Linux


/DEV/SDA10 945463296 976771071 15653888 Linux Swap/solaris

See on the previous list of commands, n represents creating a new hard disk partition, then we enter the n command to create a new partition:


root@figo:/home/feigo# Fdisk/dev/sdb





Command (M for help): N


Partition Type:


P Primary (0 primary, 0 extended, 4 free)


E Extended


Select (default p): P


Partition number (1-4, default 1): 1


The sector (2048-976773167, default 2048):


Using Default Value 2048


Last sector, +sectors or +size{k,m,g} (2048-976773167, default 976773167):


Using Default Value 976773167





Command (M for help): W


The partition table has been altered!





Calling IOCTL () to re-read partition table.


Syncing disks.


Completed, and then viewed, has found a SDB1 partition:


root@figo:/home/feigo# fdisk-l





disk/dev/sdb:500.1 GB, 500107862016 bytes


Bayi heads, Sectors/track, 191411 cylinders, total 976773168 sectors


Units = sectors of 1 * the bytes


Sector size (logical/physical): bytes/512 bytes


I/O size (minimum/optimal): bytes/512 bytes


Disk identifier:0x3f1e271a





Device Boot Start End Blocks Id System


/DEV/SDB1 2048 976773167 488385560 Linux





disk/dev/sda:500.1 GB, 500107862016 bytes


255 heads, Sectors/track, 60801 cylinders, total 976773168 sectors


Units = sectors of 1 * the bytes


Sector size (logical/physical): bytes/512 bytes


I/O size (minimum/optimal): bytes/512 bytes


Disk Identifier:0xc35aebd4





Device Boot Start End Blocks Id System


/DEV/SDA1 * 104872319 52436128+ 7 Hpfs/ntfs/exfat


/dev/sda2 104872381 976771071 435949345+ f W95 Ext ' d (LBA)


/dev/sda5 104872383 231962534 63545076 7 Hpfs/ntfs/exfat


/dev/sda6 231962598 300929579 34483491 b W95 FAT32


/dev/sda7 300931072 301125631 97280 Linux


/dev/sda8 301127680 517726207 108299264 Linux


/DEV/SDA9 517728256 945461247 213866496 Linux


/DEV/SDA10 945463296 976771071 15653888 Linux Swap/solaris

3. Format the partition as EXT4:

root@figo:/home/feigo# MKFS.EXT4/DEV/SDB1


MKE2FS 1.42.5 (29-jul-2012)


File System label =


OS Type:linux


Block size =4096 (log=2)


Chunking size =4096 (log=2)


Stride=0 blocks, stripe width=0 blocks


30531584 inodes, 122096390 blocks


6104819 blocks (5.00%) reserved for the Super user


First block of data =0


Maximum filesystem blocks=4294967296


3727 block Groups


32768 blocks per group, 32768 fragments per group


8192 inodes per group


Superblock backups stored on blocks:


32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,


4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,


102400000





Allocating group tables: completing


Writing to Inode table: completing


Creating journal (32768 Blocks): complete


Writing Superblocks and filesystem accounting information: Complete


Formatting is complete, you can use the parted command to view the partition format of the/DEV/SDB:


root@figo:/home/feigo# parted


GNU Parted 2.3


Using/dev/sda


Welcome to GNU parted! Type ' help ' to view a list of commands.


(parted) Help


Align-check type N check partition N for TYPE (min|opt) alignment


Check number do a simple check on the file system


CP [From-device] from-number to-number Copy file system to another partition


Help [command] print general help, or the command


Mklabel,mktable Label-type Create a new Disklabel (partition table)


MKFS number Fs-type make a fs-type the file system on partition number


Mkpart Part-type [Fs-type] START to make a partition


Mkpartfs part-type fs-type START end make a partition with a file system


Move number START and move partition number


Name Number name name partition number as NAME


Print [devices|free|list,all| Number] Display the partition table, available devices, free spaces, all found partitions, or a particular partition


Quit Exit Program


Rescue start end rescue a lost partition near start and end


Resize number START End Resize partition number and its file system


RM Number Delete Partition number


Select DEVICE Choose the DEVICE to edit


Set number FLAG state change the FLAG on partition number


Toggle [Number [FLAG]] toggle the state of FLAG on partition number


Unit unit Set the default unit to unit


Version display the version number and copyright information of GNU Parted


(parted) Select/dev/sdb


Using/dev/sdb


(parted) Print


Model:ata st3500413as (SCSI)


disk/dev/sdb:500gb


Sector size (logical/physical): 512b/512b


Partition Table:msdos





Number Start End Size Type File system Flags


1 1049kB 500GB 500GB primary Ext4





(parted) quit


The internal commands above parted:


Help on behalf of all internal commands will be printed


Select/dev/sdb on behalf of the hard drive SDB


Print represents the type of partition file system


Quit rep quits

So we already know that SDB has been formatted as EXT4, and then we need to mount the hard drive to the directory:

root@figo:/home/feigo# mkdir/data1


root@figo:/home/feigo# mount/dev/sdb1/data1


root@figo:/home/feigo# df-th


File system type capacity used available% mount point


Rootfs rootfs 102G 93G 4.5G 96%/


Udev devtmpfs 10M 0 10M 0%/dev


Tmpfs tmpfs 799M 3.0M 796M 1%/run


/dev/disk/by-uuid/3640f24a-4870-42e2-ae07-109cb9c35164 ext4 102G 93G 4.5G 96%/


Tmpfs tmpfs 5.0M 0 5.0M 0%/run/lock


Tmpfs tmpfs 4.6G 376K 4.6G 1%/RUN/SHM


/dev/sda7 ext4 92M 26M 62M 30%/boot


/dev/sda9 ext4 201G 23G 169G 12%/home


/DEV/SDB1 ext4 459G 198M 435G 1%/data1


You can see that the/DEV/SDB1 has been mounted under/DATA1, and the rest of the work is migrating the data.

4. The final step is to achieve the Power-on automatic mount/DEV/SDB1 to/data1:

Edit the/etc/fstab file and add the following two lines:

root@figo:/home/feigo# Vi/etc/fstab
# LOAD/DEV/SDB1 TO/DATA1 when the system startup
/dev/sdb1/data1 EXT4 Defaults 1 2

Then use MOUNT-A to determine if the/etc/fstab settings are correct, and then use mount to view the mounted devices:

root@figo:/home/feigo# mount-a


root@figo:/home/feigo# Mount


Sysfs On/sys type SYSFS (rw,nosuid,nodev,noexec,relatime)


Proc On/proc type proc (rw,nosuid,nodev,noexec,relatime)


Udev On/dev type DEVTMPFS (rw,relatime,size=10240k,nr_inodes=1020978,mode=755)


Devpts on/dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)


Tmpfs on/run type TMPFS (rw,nosuid,noexec,relatime,size=818060k,mode=755)


/dev/disk/by-uuid/3640f24a-4870-42e2-ae07-109cb9c35164 On/type Ext4 (rw,relatime,errors=remount-ro,user_xattr, barrier=1,data=ordered)


Tmpfs on/run/lock type TMPFS (rw,nosuid,nodev,noexec,relatime,size=5120k)


Tmpfs on/run/shm type TMPFS (rw,nosuid,nodev,noexec,relatime,size=4766880k)


/DEV/SDA7 on/boot type EXT4 (rw,relatime,user_xattr,barrier=1,data=ordered)


/DEV/SDA9 on/home type EXT4 (rw,relatime,user_xattr,barrier=1,data=ordered)


Rpc_pipefs on/var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)


Binfmt_misc on/proc/sys/fs/binfmt_misc type Binfmt_misc (rw,nosuid,nodev,noexec,relatime)


/DEV/SDB1 on/data1 type EXT4 (rw,relatime,user_xattr,barrier=1,data=ordered)

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.