Posted
Filed under Linux

 centos7 하드 마운트

[원문]http://zero-gravity.tistory.com/297

 추가하고 싶은 하드디스크의 용량이 2TB를 초과한다면 6번 과정으로 바로 갈 것.

 

 

 

   1. fdisk -l

   

   드라이브 목록을 확인한다.

 

# fdisk -l

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     1026047      512000   83  Linux

/dev/sda2         1026048  1469032447   734003200   83  Linux

/dev/sda3      1469032448  1510975487    20971520   83  Linux

/dev/sda4      1510975488  1953523711   221274112    5  Extended

/dev/sda5      1510977536  1531949055    10485760   83  Linux

/dev/sda6      1531951104  1552922623    10485760   83  Linux

/dev/sda7      1552924672  1560788991     3932160   82  Linux swap / Solaris

/dev/sda8      1560791040  1952958463   196083712   83  Linux

 

Disk /dev/sdb: 4000.8 GB, 4000787030016 bytes, 7814037168 sectors

Units = sectors of 1 * 512 = 512 bytes

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

 

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

 

 

   할당되지 않은 4TB 크기의 /dev/sdb 드라이브가 보인다. 이걸 파티션 할당해줘야 한다.

   (리눅스는 보통 첫번째 드라이브가 /dev/sda1,2,3...두번째 드라이브가 /dev/sdb1,2,3... 이렇게 설정된다.)

 

 

   2. fdisk /dev/[디스크명]

 

   새로운 하드디스크를 추가한다.

 

# fdisk /dev/sdb

 

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0x6ad31b53.

 

WARNING: The size of this disk is 4.0 TB (4000787030016 bytes).

DOS partition table format can not be used on drives for volumes

larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 

partition table format (GPT).

 

 

The device presents a logical sector size that is smaller than

the physical sector size. Aligning to a physical sector (or optimal

I/O) size boundary is recommended, or performance may be impacted.

 

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

   g   create a new empty GPT partition table

   G   create an IRIX (SGI) partition table

   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)

 

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

First sector (2048-4294967295, default 2048): 2048

Last sector, +sectors or +size{K,M,G} (2048-4294967294, default 4294967294):  #Enter를 치면 default로 잡힌다.  

Using default value 4294967294

 

Partition 1 of type Linux and of size 2 TiB is set 

#하드디스크의 용량은 4TB이지만, 파티션에 할당할 수 있는 최대 크기는 2TB다.

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

Syncing disks.

 

 

   3. mkfs -t [파일시스템] /dev/[디스크명]

   파일시스템 만들기.

 

mkfs -t ext4 /dev/sdb1

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

134217728 inodes, 536870655 blocks

26843532 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2684354560

16384 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, 214990848, 512000000

 

Allocating group tables: done                            

Writing inode tables: done                            

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done 

 

 

   4. mount -t [파일시스템] /dev/[디스크명] 

   마운트하기.

 

mount -t ext4 /dev/sdb1 /second

 

df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        20G   93M   19G   1% /

.

.

.

.

 

/dev/sdb1       2.0T   81M  1.9T   1% /second   # 새로 마운트한 드라이브가 보일 것이다.

 

 

   이렇게 하면 4TB의 하드디스크 중에 2TB를 할당해서 사용할 수 있다.

 

   그러나 2TB씩 쪼개서 사용하기 싫고 4TB를 통으로 사용하고 싶다면, 다르게 설정해줘야 한다. 

 

 

   5. 되돌리기

 

   우선, 추가해줬던 파티션을 삭제하고 마운트도 다시 해제하자.

 

# fdisk /dev/sdb

 

WARNING: The size of this disk is 4.0 TB (4000787030016 bytes).

DOS partition table format can not be used on drives for volumes

larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 

partition table format (GPT).

 

 

The device presents a logical sector size that is smaller than

the physical sector size. Aligning to a physical sector (or optimal

I/O) size boundary is recommended, or performance may be impacted.

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

 

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

   g   create a new empty GPT partition table

   G   create an IRIX (SGI) partition table

   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)

 

Command (m for help): d

Selected partition 1

Partition 1 is deleted

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: 장치나 자원이 동작 중.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

 

# umount /second

 

   df- h로 확인해보면 디스크를 추가하지 전의 원래 상태로 돌아옴을 확인할 수 있다. 

 

 

 

   6. 2TB를 초과하는 디스크 할당하기.

 

   2TB를 초과하는 파티션을 할당하기 위해선 parted 명령어를 사용해야 한다.

 

parted /dev/sdb

GNU Parted 3.1

Using /dev/sdb

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

  help [COMMAND]                           print general help, or help on COMMAND

  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)

  mkpart PART-TYPE [FS-TYPE] START END     make a partition

  name NUMBER NAME                         name partition NUMBER as NAME

  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a

        particular partition

  quit                                     exit program

  rescue START END                         rescue a lost partition near START and END

  rm NUMBER                                delete partition NUMBER

  select DEVICE                            choose the device to edit

  disk_set FLAG STATE                      change the FLAG on selected device

  disk_toggle [FLAG]                       toggle the state of FLAG on selected device

  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) mklabel gpt                                                      

Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?

Yes/No? yes                                                               

(parted) unit TB  # 단위를 설정한다. GB or TB                                                         

(parted) mkpart primary 0.00TB 4.00TB  # 용량 설정 start end

(parted) print                                                            

Model: ATA HGST HDN726040AL (scsi)

Disk /dev/sdb: 4.00TB

Sector size (logical/physical): 512B/4096B

Partition Table: gpt

Disk Flags: 

 

Number  Start   End     Size    File system  Name     Flags

 1      0.00TB  4.00TB  4.00TB  ext4         primary         # 정상적으로 추가됐다.

 

(parted) quit 

Information: You may need to update /etc/fstab.                                   

 

   파일시스템을 만든다.

# mkfs -t ext4 /dev/sdb1

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

244195328 inodes, 976754176 blocks

48837708 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=3124756480

29809 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, 214990848, 512000000, 550731776, 644972544

 

Allocating group tables: done                            

Writing inode tables: done                            

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done 

 

   마운트한다.

# mount -t ext4 /dev/sdb1 /second

 

# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        20G   93M   19G   1% /

.

.

.

.

 

/dev/sdb1       3.6T   89M  3.4T   1% /second   # 마운트 완료

 

 

   이 과정을 모두 마쳤다면, /second 폴더에 넣는 파일들은 모두 새로 추가한 디스크에 저장될 것이다.

 

   그러나 재부팅 시 마운트가 자동으로 해제되기 때문에, 부팅할 때 자동으로 마운트를 해주는 설정을 해줘야 한다.

 

 

   7. fstab 파일 등록

 

   재부팅 시 자동마운트가 되도록 설정한다.

 

# blkid   # 먼저 자동마운트 등록할 디스크의 UUID를 알아내야 한다.

/dev/sda1: UUID="22a87868-322e-4661-af01-93b2062044ce" TYPE="xfs" 

.

.

.

/dev/sdb1: UUID="e001a7f9-1154-129e-a916-dad0b54116f2" TYPE="ext4" PARTLABEL="primary" PARTUUID="52412c84-700e-2313-9e2f-c12b1ca1676a"

 

# vi /etc/fstab

 

 

#

# /etc/fstab

# Created by anaconda on Sat Sep 26 08:52:44 2015

#

# 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=1c407d96-e43b-4b52-af5f-b191560e8267 /                       ext4    defaults        1 1

.

.

.

.

 

UUID=e001a7f9-1154-129e-a916-dad0b54116f2 /second              ext4    defaults        1 2  # 여기에 추가한다.

 

 

 

   이렇게 하면 재부팅을 하더라도 자동마운트 된다.

 

   굳이 재부팅을 할 필요없이 자동으로 마운트가 되는지 확인하고 싶다면, 마운트를 해제하고 mount -a 을 해보면 된다.

2017/10/11 16:52 2017/10/11 16:52