1. 파티션 관리
리눅스에서 fdisk 명령어를 사용하여 파티션을 관리할 수 있다.
-l 옵션을 사용하여 현재 디스크를 확인하도록 한다.
fdisk -l
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0002a223
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 3917 30944256 8e Linux LVM
Disk /dev/mapper/vg_wemb-lv_root: 29.6 GB, 29603397632 bytes
255 heads, 63 sectors/track, 3599 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_wemb-lv_swap: 2080 MB, 2080374784 bytes
255 heads, 63 sectors/track, 252 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
출력된 결과를 보면 /dev/sda (30G)와 dev/sdb (10G)의 디스크가 존재함을 알 수 있다.
이번에 신규로 추가할 디스크는 /dev/sdb (10G)에 해당한다.
fdisk [디스크 경로] 명령어를 사용하여 파티션을 생성한다.
fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7cee5a6b.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won’t be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be 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 (command ‘u’).
Command (m for help):
m 또는 help를 입력하면 세부명령어를 확인할 수 있다.
신규 파티션을 생성할 것이기에 n을 입력하여 add a new partition 메뉴를 선택하도록 한다.
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)
Command (m for help): n
환경에 맞는 방법을 선택한다. 이번 예제에서는 primary partition으로 진행한다.
Command action
e extended
p primary partition (1-4)
p
파티션 번호를 선택한다.
partition number (1-4): 1
시작과 끝 실린더를 선택하는데 예제에서는 10G를 한 파티션으로 설정할 것이기에 디폴트로 진행한다.
엔터를 입력하면 디폴트로 입력된다.
First cylinder (1-1305, default 1): [Enter]
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): [Enter]
Using default value 1305
추가된 파티션을 확인하려면 print the partiton table을 메뉴를 선택한다.
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1a806c2f
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 83 Linux
확인결과 /dev/sdb1으로 신규 파티션이 생성되었다.
fdisk 모드를 종료시에는 q를 입력한다.
리눅스에서 mkfs 명령어를 사용하여 파일시스템을 생성해준다.
mkfs.[파일시스템 타입] [디스크]
예제에서는 ext4 파일시스템으로 진행한다.
mkfs.ext4 /dev/sdb
mke2fs 1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 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
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
위와 같이 생성 후 생성된 파일시스템을 확인한다.
blkid 명령어를 이용하여 보유한 파일시스템을 확인할 수 있다.
blkid | grep /dev/sdb
/dev/sdb: UUID=”f2692067-d32a-49ad-b2ff-23346a7a8000″ TYPE=”ext4″
/dev/sdb 파티션이ext4 파일시스템 형식으로 생성된 것이 확인된다.
3. 마운트 수행
파일 시스템까지 정상적으로 생성이 되었다면 이제 마운트를 수행해 줌으로써
신규 디스크를 사용할 수 있게 된다. 마운트의 기본 형식은 다음과 같다.
mount [디스크] [마운트 할 폴더]
마운트를 수행하기에 앞서 마운트 할 폴더를 생성해 주도록 한다.
mkdir mount_disk
ls -l
drwxr-xr-x. 2 root root 4096 Apr 7 16:01 mount_disk
이제 신규 디스크를 생성한 폴더에 마운트 해준다.
mount /dev/sdb mount_disk( /home2 )
별다른 성공 메시지가 출력되지는 않는다.
4. 추가된 디스크 확인
마지막으로 추가된 디스크를 확인한다.
mount 명령어로 확인이 가능하다.
mount
/dev/mapper/vg_wemb-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext=”system_u:object_r:tmpfs_t:s0″)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/sdb on /root/mount_disk type ext4 (rw)
디스크 사용량을 확인하는 df 명령어로도 추가된 디스크를 확인할 수 있다.
df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg_wemb-lv_root 28455944 9249080 17761388 35% /
tmpfs 506272 228 506044 1% /dev/shm
/dev/sda1 495844 33802 436442 8% /boot
/dev/sdb 10321208 154100 9642820 2% /root/mount_disk
참고로 -h 옵션을 사용하면 사용자가 보기 편한 Kilobyte, Megabyte, Gigabyte 단위로 표현된다.
df -h
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg_wemb-lv_root 28G 8.9G 17G 35% /
tmpfs 495M 228K 495M 1% /dev/shm
/dev/sda1 485M 34M 427M 8% /boot
/dev/sdb 9.9G 151M 9.2G 2% /root/mount_disk
위와 같이 성공적으로 신규 디스크가 추가되었다.