- HDD(ext2) mount
여기서는 파일을 이용한다.
현재 디렉토리에 dd를 이용해서 30M짜리 파일명이 HDD1.dd 를 생성하시오.
# dd if=/dev/zero of=HDD1.dd bs=1024 count=30000
# yes | mkfs.ext2 HDD1.dd
# mount -o loop HDD1.dd HDD1
# df
# mount
- HDD(ext3) mount
여기서는 파일을 이용한다.
현재 디렉토리에 dd를 이용해서 50M짜리 파일명이 HDD2.dd 를 생성하시오.
# dd if=/dev/zero of=HDD2.dd bs=1024 count=50000
# yes | mkfs.ext3 HDD2.dd
# mount -o loop HDD2.dd HDD2
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 7103744 1877940 4859124 28% /
tmpfs 257440 0 257440 0% /dev/shm
/root/test/HDD1.dd 29045 365 27180 2% /root/test/HDD1
/root/test/HDD2.dd 48409 4908 41001 11% /root/test/HDD2
# mount
/dev/sda1 on / type ext3 (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)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/root/test/HDD1.dd on /root/test/HDD1 type ext2 (rw,loop=/dev/loop0)
/root/test/HDD2.dd on /root/test/HDD2 type ext3 (rw,loop=/dev/loop1)
[root@localhost test]# umount /
umount: /: device is busy
umount: /: device is busy
# mount -o remount,ro HDD1
[root@localhost test]# mount
/dev/sda1 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/root/test/HDD1.dd on /root/test/HDD1 type vfat (ro,loop=/dev/loop0)
[root@localhost test]# cp /bin/true HDD1
cp: cannot create regular file `HDD1/true': Read-only file system
[root@localhost test]# ls HDD1
lost+found
[root@localhost test]# mount -o remount,rw HDD1
[root@localhost test]# mount
/dev/sda1 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/root/test/HDD1.dd on /root/test/HDD1 type vfat (rw,loop=/dev/loop0)
- ext2 파일시스템으로 생성
# mkfs.ext2 HDD1.dd
# mke2fs HDD2.dd
- ext3 파일시스템으로 생성
# mkfs.ext3 HDD1.dd
# mke2fs -j HDD2.dd
--> 해보길...
[root@localhost test]# tune2fs -l HDD1.dd | grep count
Inode count: 7520
Block count: 30000
Reserved block count: 1500
Mount count: 0
Maximum mount count: 30
[root@localhost test]# mount -o loop HDD1.dd HDD1
[root@localhost test]# tune2fs -l HDD1.dd | grep count
Inode count: 7520
Block count: 30000
Reserved block count: 1500
Mount count: 1
Maximum mount count: 30
[root@localhost test]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 7103744 1877948 4859116 28% /
/root/test/HDD1.dd 29045 1395 26150 6% /root/test/HDD1
[root@localhost test]# tune2fs -l HDD1.dd | grep Free
Free blocks: 27650
Free inodes: 7509
[root@localhost test]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 1835008 83094 1751914 5% /
/root/test/HDD1.dd 7520 11 7509 1% /root/test/HDD1
[root@localhost test]# umount HDD1
[root@localhost test]# tune2fs -l HDD1.dd | grep count
Inode count: 7520
Block count: 30000
Reserved block count: 1500
Mount count: 1
Maximum mount count: 30
[root@localhost test]# mount -o loop HDD1.dd HDD1
[root@localhost test]# tune2fs -l HDD1.dd | grep count
Inode count: 7520
Block count: 30000
Reserved block count: 1500
Mount count: 2
Maximum mount count: 30
# tune2fs -l HDD1.dd | grep count
Inode count: 7520
Block count: 30000
Reserved block count: 1500
Mount count: 2
Maximum mount count: 30
[root@localhost test]# tune2fs -C 10 HDD1.dd
tune2fs 1.39 (29-May-2006)
Setting current mount count to 10
[root@localhost test]# tune2fs -l HDD1.dd | grep count
Inode count: 7520
Block count: 30000
Reserved block count: 1500
Mount count: 10
Maximum mount count: 30
# e2fsck HDD1.dd
e2fsck 1.39 (29-May-2006)
HDD1.dd: clean, 11/7520 files, 2350/30000 blocks
[root@localhost test]# e2fsck HDD2.dd
e2fsck 1.39 (29-May-2006)
HDD2.dd: clean, 11/12544 files, 6499/50000 blocks
# badblocks -v HDD1.dd
Checking blocks 0 to 30000
Checking for bad blocks (read-only test): done
Pass completed, 0 bad blocks found.
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 7103744 1877948 4859116 28% /
[root@localhost test]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 1835008 83094 1751914 5% /
# free
total used free shared buffers cached
Mem: 514884 346600 168284 0 90512 151972
-/+ buffers/cache: 104116 410768
Swap: 1052248 88 1052160
# cat /proc/cpuinfo
LAB> 시스템의 CPU,MEMORY,DISK 의 정보를 파일에 저장해보자.
!!! 중요 point : 리다이렉션, 각 명령어와 파일정보 !!!
# echo '## CPU info ##' > systeminfo.txt
# echo '' >> systeminfo.txt
# cat /proc/cpuinfo >> systeminfo.txt
# echo '## MEMORY info ##' >> systeminfo.txt
# echo '' >> systeminfo.txt
# free >> systeminfo.txt
# echo '## DISK info ##' >> systeminfo.txt
# echo '' >> systeminfo.txt
# df >> systeminfo.txt
# df -i >> systeminfo.txt
cat systeminfo.txt
LAB> 시스템의 CPU,MEMORY,DISK 의 정보를 파악하는 쉘스크립트를 짜보다.
!!! 중요 point : 리다이렉션, 각 명령어와 파일정보 !!!
# install /dev/null systeminfo.sh
# ls -l systeminfo.sh
-rwxr-xr-x 1 root root 0 Mar 27 16:36 systeminfo.sh*
# vi systeminfo.sh
-- systeminfo.sh --
#!/bin/sh
echo '## CPU info ##' > systeminfo.txt
echo '' >> systeminfo.txt
cat /proc/cpuinfo >> systeminfo.txt
echo '## MEMORY info ##' >> systeminfo.txt
echo '' >> systeminfo.txt
free >> systeminfo.txt
echo '## DISK info ##' >> systeminfo.txt
echo '' >> systeminfo.txt
df >> systeminfo.txt
df -i >> systeminfo.txt
-- systeminfo.sh --
- 실행 -
# rm -f systeminfo.txt
# ls systeminfo.txt
ls: systeminfo.txt: No such file or directory
# ./systeminfo.sh
# cat systeminfo.txt
===== 정리 =====
==> 해보길...
dd if=/dev/zero of=a.dd bs=1024 count=10000
[root@localhost ~]# mke2fs -j a.dd
[root@localhost ~]# mkdir A
[root@localhost ~]# mount -o loop a.dd A
[root@localhost ~]# cd A
[root@localhost A]# cp /bin/* .
[root@localhost A]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 7103744 1787764 4949300 27% /
tmpfs 257440 0 257440 0% /dev/shm
/root/a.dd 9677 9677 0 100% /root/A
[root@localhost A]# cd ..
[root@localhost ~]# cd A
[root@localhost A]# umount /root/a.dd
umount: /root/A: device is busy
umount: /root/A: device is busy
[root@localhost A]# umount /root/A
umount: /root/A: device is busy
umount: /root/A: device is busy
--> A 경로에 들어가 있기때문에 umount가 안된다.
[root@localhost A]# cd ..
--> 경로 바꾸고
[root@localhost ~]# umount /root/A
--> umount 가능
# cat a.dd > c.dd
--> cat 으로 a.dd 를 c.dd로 복사? 그런 느낌 가능
[root@localhost ~]# ls -l c.dd
-rw-r--r-- 1 root root 10240000 Mar 27 13:22 c.dd
[root@localhost ~]# mkdir C
[root@localhost ~]# mount -o loop c.dd C
-pwd 와 링크 경로
[root@localhost ~]# cd /etc/rc.d/init.d
[root@localhost init.d]# pwd
/etc/rc.d/init.d
[root@localhost init.d]# pwd -P
/etc/rc.d/init.d
[root@localhost init.d]# pwd -L
/etc/rc.d/init.d
[root@localhost init.d]# cd /etc/init.d
[root@localhost init.d]# pwd -P
/etc/rc.d/init.d
[root@localhost init.d]# pwd -L
/etc/init.d
[root@localhost init.d]# cd
[root@localhost ~]# mkdir dirA
[root@localhost ~]# ln -s dirA dirB
[root@localhost ~]# ls -l dirB
lrwxrwxrwx 1 root root 4 Mar 31 12:21 dirB -> dirA
[root@localhost ~]# cd dirB
[root@localhost dirB]# pwd -P
/root/dirA
[root@localhost dirB]# pwd -L
/root/dirB
- 사용자의 디렉토리를 명령어
# cd ~사용자명 O
# cd /home/사용자명 X
bash 쉘에서 지원하는 기능
- 자동완성 기능(tab)
-ln (하드링크) 와 아이노드 관계
--> 다음에 자세히
[root@localhost ~]# mkdir LINKTEST; cd LINKTEST
[root@localhost LINKTEST]# touch a.txt
[root@localhost LINKTEST]# ls -li
total 4
262154 -rw-r--r-- 1 root root 0 Mar 31 12:36 a.txt
[root@localhost LINKTEST]# touch b.txt
[root@localhost LINKTEST]# ls -li
total 8
262154 -rw-r--r-- 1 root root 0 Mar 31 12:36 a.txt
262155 -rw-r--r-- 1 root root 0 Mar 31 12:36 b.txt
[root@localhost LINKTEST]# ln a.txt c.txt
[root@localhost LINKTEST]# ls -li
total 12
262154 -rw-r--r-- 2 root root 0 Mar 31 12:36 a.txt
262155 -rw-r--r-- 1 root root 0 Mar 31 12:36 b.txt
262154 -rw-r--r-- 2 root root 0 Mar 31 12:36 c.txt
[root@localhost LINKTEST]#
-디렉터리와 아이노드 관계
-->나중에 자세히
[root@localhost LINKTEST]# ls -lid /
2 drwxr-xr-x 24 root root 4096 Mar 31 09:07 /
[root@localhost LINKTEST]# mkdir ../DIR1/DIR2 -p
[root@localhost LINKTEST]# ls -ld /root
drwxr-x--- 14 root root 4096 Mar 31 12:40 /root
[root@localhost LINKTEST]# ls -lid /root
229377 drwxr-x--- 14 root root 4096 Mar 31 12:40 /root
[root@localhost LINKTEST]# ls -ldi .
262153 drwxr-xr-x 2 root root 4096 Mar 31 12:37 .
[root@localhost LINKTEST]# ls -lid ../DIR1
262156 drwxr-xr-x 3 root root 4096 Mar 31 12:40 ../DIR1
[root@localhost LINKTEST]# ls -lid ../DIR1/DIR2
262157 drwxr-xr-x 2 root root 4096 Mar 31 12:40 ../DIR1/DIR2
[root@localhost LINKTEST]#