본문 바로가기
네트워크 수업/리눅스

[리눅스] 실습

by 6^6 2023. 3. 21.
728x90

clear

su

cd /

ls = list의 약자 = 디렉토리 목록을 보여주세요 

mount = 보조기억장치(hdd,fdd,cd-rom 등)나 파일시스템이 다른 디스크를 /의 하위 디렉터리로 연결하여 사용 가능하게 해주는 명령어

 

[root@centos7 heejae]# su
[root@centos7 heejae]# cd /
[root@centos7 /]# ls = list의 약자 = 디렉토리 목록을 보여주세요 
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
[root@centos7 /]# ls /home =자기가 쓰는 디렉토리가 보인다.

root=슈퍼유저의 디렉토리

[root@centos7 /]# mkdir /temp = make directory
[root@centos7 /]# cd /temp 
[root@centos7 temp]# pwd =현재 자신의 위치정보. print working directory

/temp

[root@centos7 temp]# mkdir c =상대경로 temp에 c가 만들어진다.

[root@centos7 temp]# mkdir /temp/d =절대경로 temp에 d가 만들어니다.

[root@centos7 temp]# cd .. =상위디렉토리로 이동

 

reboot

= shutdown -r now 와 같은 명령어이다.

= halt (root권환으로만 사용이 가능)

shutdown +3 "하고싶은말"리눅스의 관리자는 root // 윈도우의 관리자는 admin

 

[root@centos7 /]# cd boot = 상대 경로
[root@centos7 boot]# ls
System.map-3.10.0-1160.el7.x86_64  initramfs-0-rescue-ab232feb8c6443d6af66829616632b17.img
config-3.10.0-1160.el7.x86_64      initramfs-3.10.0-1160.el7.x86_64.img
efi                                symvers-3.10.0-1160.el7.x86_64.gz
grub                               vmlinuz-0-rescue-ab232feb8c6443d6af66829616632b17
grub2                              vmlinuz-3.10.0-1160.el7.x86_64

 

커널 = 리눅스 운영체제의 핵심 파일

(운영체제 = 커널)

부트스트랩 = 

img

 

cd 

[root@centos7 boot]# cd /etc =절대경로

[root@centos7 etc]# cat passwd

[root@centos7 etc]# cd /sbin
[root@centos7 sbin]# ls

[root@centos7 sbin]# ls ls
ls
[root@centos7 sbin]# ls cat
cat

 


cd /usi는 C:\Program Files 와 비슷하다.

cd /proc 

root@centos7 proc]# uptime =uptime 하면 시간정보와 몇명의 유저가 있다. 라고 정보 알려줌
 15:58:37 up 59 min,  3 users,  load average: 0.16, 0.06, 0.06

 

[root@centos7 proc]# cd ~ =사용자 홈 디렉토리로 이동
[root@centos7 ~]# pwd
/root

 

[root@centos7 ~]# cd /
[root@centos7 /]# ls -l =list 를 long타입으로 자세하게 보여달라
합계 20
lrwxrwxrwx.   1 root root    7  2월  9 12:13 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096  2월  9 12:20 boot =저렇게 앞에 d가 붙은건 directory의 약자이다.
...

...


[root@centos7 /]# 

[root@centos7 /]# cd /etc
[root@centos7 etc]# ls -l

 

[root@centos7 /]# cd /dev 사운드카드 이런거 보여줌
[root@centos7 etc]# ls -l

 

[root@centos7 dev]# ls -l |more 

lrwxrwxrwx. 1 root root           3  3월 16 17:06 cdrom -> sr0 =cd-rom에서 sr0장치에 접근하는것과 같다. windows의 바로가기와 같다

drwxr-xr-x. 2 root root          80  3월 16 17:06 centos =블록 디스크라고해서 하드디스크 플러피 디스크 같은게 들어있다.

 

 

리눅스에 하드디스크를 하나 추가해보자

 

 

SCSI = 스카시

hard disk가 리눅스에선 어떻게 인식할까

 

2023.03.21 - [네트워크 수업/리눅스] - Partition.pdf

 

 

 

 

su

암호 치고

ls sd*

sdb가 방금 우리가 만든 하드디스크이다.

sda 와 sdb 두개 파티션을 만든거다.

 

[heejae@centos7 ~]$ su
암호:
[root@centos7 heejae]# fdisk -l /dev/sdb

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

 

[root@centos7 heejae]# fdisk /dev/sdb =파티션을 나누겠다.

p는 partition

 

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-2097151, default 2048): =MBR영역이다. 건드리지 않고 걍 enter치면 2048로 됨

Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): 일단 그냥 enter(통째로 쓸거니까)

만약 512를 적어준다면 ? 512MB만큼을 sdb1 으로 쓰겠다.

sdb2로 나중에 쓸수있다.

Using default value 2097151
Partition 1 of type Linux and of size 1023 MiB is set

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x2a745293

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2097151     1047552   83  Linux

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): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos7 heejae]# mkfs -t ext4 /dev/sdb1  ext3보다 ext4를 더 많이 쓴다. Linux에서 ext3, ext4, xfs 등등의 파일 시스템으로 포멧하여야 사용할 수 있으며, 포멧을 할때 사용되는 명령어가 mkfs 명령어 입니다

 

===

여기서 잠깐! NTFS란?

compmgmt.msc

windows NT계열의 파일 시스템이다.

===

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
65536 inodes, 261888 blocks
13094 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

그럼 파티션 나눠진거 확인가능

 

[root@centos7 heejae]# cd /dev
[root@centos7 dev]# ls sd*  컴퓨터에 장착된 디스크와 파티션 목록을 출력할 수 있다.
sda  sda1  sda2  sdb  sdb1

 

그럼 다시 지워보기

 

[root@centos7 dev]# fdisk /dev/sdb

Command (m for help): d

Command (m for help): p

Command (m for help): w =저장
[root@centos7 dev]# ls sd*
sda  sda1  sda2  sdb 지워졌다

 

다시 만들어보기

 

[root@centos7 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.


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-2097151, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +512M
Partition 1 of type Linux and of size 512 MiB is set
Command (m for help): w 저장


[root@centos7 dev]# fdisk -l /dev/sdb1

Disk /dev/sdb1: 536 MB, 536870912 bytes, 1048576 sectors 536MB잡힌거 확인 가능
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[root@centos7 dev]# mkfs -t ext4 /dev/sdb1 사용하기 위해 포멧함

[root@centos7 dev]# mkdir /drive2

[root@centos7 dev]# cd /
[root@centos7 /]# ls
bin   dev     etc   lib    media  opt   root  sbin  sys   tmp  var
boot  drive2  home  lib64  mnt    proc  run   srv   temp  usr

 

[root@centos7 dev]# cd /
[root@centos7 /]# ls
bin   dev     etc   lib    media  opt   root  sbin  sys   tmp  var
boot  drive2  home  lib64  mnt    proc  run   srv   temp  usr  그냥 확인절차..

 

[root@centos7 /]# mount /dev/sdb1 /drive2 dev에 sdb1을 drive2에 마운트 시키겠다.

[root@centos7 /]# cd /drive2
[root@centos7 drive2]# touch testfile 빈파일 만들겠다.

[root@centos7 drive2]# ls 확인
lost+found  testfile

[root@centos7 drive2]# df -h  df=저장공간확인  -h=파일크기 확인

Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 470M     0  470M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  8.5M  478M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   37G  4.9G   33G  14% /
/dev/sda1               1014M  172M  843M  17% /boot
tmpfs                     98M   24K   98M   1% /run/user/1000
/dev/sr0                 9.5G  9.5G     0 100% /run/media/heejae/CentOS 7 x86_64
tmpfs                     98M     0   98M   0% /run/user/0
/dev/sdb1                488M  780K  452M   1% /drive2

 

dev를 써주거나 drive2를 써주거나 그럼 mount해제된다.

[root@centos7 drive2]# cd /
[root@centos7 /]# umount /drive2

[root@centos7 /]# df -h mount 사라진거 확인
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 470M     0  470M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  8.5M  478M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   37G  4.9G   33G  14% /
/dev/sda1               1014M  172M  843M  17% /boot
tmpfs                     98M   24K   98M   1% /run/user/1000
/dev/sr0                 9.5G  9.5G     0 100% /run/media/heejae/CentOS 7 x86_64
tmpfs                     98M     0   98M   0% /run/user/0

[root@centos7 /]# mount /dev/sdb1 /drive2
[root@centos7 /]# ls /drive2  
lost+found  testfile 뺐는데도 데이터는 살아있다.

 

과제>>

sdb의 나머지 500MB를 2번 파티션으로 잡고 /drive3에 마운트시켜 보세요.

fdisk -l /dev/sdb
n p 2 enter enter w
reboot //이거 하라고 해서;;

[root@centos7 /]# mkdir /drive3
[root@centos7 /]# mount /dev/sdb2 /drive3

또는

[root@centos7 /]# mkfs.ext4 /dev/sdb3

 

질문

//모르고 sdb2에 drive2를 넣었을때 삭제방법

 

 

 

 

지금 이 상태 보관하기 (나중에 백업 가능)

 

 

728x90

댓글