๐Ÿ–ฅ๏ธ Computer Science/Linux

[Linux] Virtual Device (๊ฐ€์ƒ ์žฅ์น˜)

Rosieblue 2023. 9. 4. 10:19
728x90

 

Virtual Device

์‹ค์ œ ์‹œ์Šคํ…œ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ VM์—์„œ๋Š” ์„ฑ๋Šฅ, ๋ฉ”๋ชจ๋ฆฌ, ์Šคํ† ๋ฆฌ์ง€, ๋„คํŠธ์›Œํ‚น ๋˜๋Š” ๊ทธ๋ž˜ํ”ฝ๊ณผ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ์‹œ์Šคํ…œ์— ์ œ๊ณตํ•˜๋Š” ํŠน์ˆ˜ ์žฅ์น˜๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ๋ฌผ๋ฆฌ์  ์‹œ์Šคํ…œ์€ ์ผ๋ฐ˜์ ์œผ๋กœ ์ด๋Ÿฌํ•œ ๋ชฉ์ ์œผ๋กœ ํ•˜๋“œ์›จ์–ด ์žฅ์น˜๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ VM์€ ์†Œํ”„ํŠธ์›จ์–ด ๊ตฌํ˜„์œผ๋กœ ์ž‘๋™ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ€์ƒ ์žฅ์น˜๋ผ๊ณ  ํ•˜๋Š” ์ด๋Ÿฌํ•œ ์žฅ์น˜์— ๋Œ€ํ•œ ์†Œํ”„ํŠธ์›จ์–ด ์ถ”์ƒํ™”๋ฅผ ํ•œ๋‹ค.
 
๋ฆฌ๋ˆ…์Šค์—์„œ virtual device๋ž€, ์‹ค์ œ๋กœ ์—ฐ๊ฒฐ๋œ ํ•˜๋“œ์›จ์–ด๊ฐ€ ์—†๋Š” ๋””๋ฐ”์ด์Šค ํŒŒ์ผ์„ ๋งํ•œ๋‹ค.
virtual device๋Š” sw ํ˜•ํƒœ๋กœ ์กด์žฌํ•˜๋‚˜ hw์ธ ์ฒ™(?)์„ ํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ์‹œ์Šคํ…œ์œผ๋กœ ํ•˜์—ฌ๊ธˆ ํŠน์ • hw๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์ฐฉ๊ฐํ•˜๊ฒŒ ํ•œ๋‹ค. 
 
๊ทธ๋Ÿผ ์ด๋Ÿฌํ•œ virtual device๋Š” ์™œ ์กด์žฌํ•˜๋ƒ?
 
๋ณดํ†ต OS์—์„œ ์—๋Ÿฌ๋ฅผ ๊ณ ์น˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค๊ณ  ํ•œ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด external device๊ฐ€ ๋ชจ๋‹ˆํ„ฐ๋ง ํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๊ณ  ๋ฒ„๊ทธ๋‚˜ ๋ฐ”์ด๋Ÿฌ์Šค๋“ค์„ ํƒ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.
 
https://www.techopedia.com/definition/12632/virtual-device#:~:text=A%20virtual%20device%2C%20in%20operating,exists%20only%20in%20software%20form.

 

Virtual Device

This definition explains the meaning of Virtual Device and why it matters.

www.techopedia.com

 

์˜ˆ์‹œ

 

 ๊ฐ€์ƒ  ์žฅ์น˜ ์„ค๋ช… 
 /dev/null ๋„(null) ๋””๋ฐ”์ด์Šค
์ด ๊ฐ€์ƒ์žฅ์น˜๋Š” ์žฅ์น˜๋กœ ๋ณด๋‚ด๋Š” ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ๋ฌด์‹œํ•ด๋ฒ„๋ฆด ๋ชฉ์ ์œผ๋กœ ๋งŒ๋“ค์–ด์ง.
์ด์žฅ์น˜์— ์“ฐ๊ธฐ ์ž‘์—…์„ ํ•˜๋ฉด ์–ธ์ œ๋‚˜ ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋˜๋ฉฐ,
์ด ์žฅ์น˜๋กœ๋ถ€ํ„ฐ ์ฝ๊ธฐ ์ž‘์—…์„ ํ•˜๋ฉด ์•„๋ฌด ๋ฐ์ดํ„ฐ๋„ ๋„˜์–ด์˜ค์ง€ ์•Š๋Š”๋‹ค.
ํ”„๋กœ๊ทธ๋žจ์˜ ์ถœ๋ ฅ์„ ๋ฌด์‹œํ•จ์œผ๋กœ์จ ํ™”๋ฉด์ƒ์— ์•„๋ฌด๋Ÿฐ ํ…์ŠคํŠธ๋„ ํ‘œ์‹œํ•˜์ง€ ์•Š๊ฒŒ ํ• ๋•Œ ํŠนํžˆ ์œ ์šฉ.
 /dev/random ๋‚œ์ˆ˜(random number) ๋ฐœ์ƒ๊ธฐ 
 /dev/urandom ๋‚œ์ˆ˜ ํ๋ฆ„์„ ๋ฐœ์ƒ์‹œํ‚ค๋Š” ์ŠคํŠธ๋ฆผ. /dev/random์ด ์ง„์งœ ๋‚œ์ˆ˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋Š” ๋ฐ˜๋ฉด์— /dev/urandom์€ ์˜์‚ฌ๋‚œ์ˆ˜(pseudorandom number)๋ฅผ ์ œ๊ณตํ•œ๋‹ค.
์—”ํŠธ๋กœํ”ผ ํ’€์„ ์ฑ„์šฐ๊ธฐ ์œ„ํ•œ ๋ชฉ์ ์œผ๋กœ ์ด ์žฅ์น˜์— ์“ฐ๊ธฐ ์ž‘์—…์„ ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.
๋ฐœ์ƒ๋˜๋Š” ๋ฐ์ดํ„ฐ๋Š” ๋ฐ”์ด๋„ˆ๋ฆฌ์ด๊ธฐ ๋•Œ๋ฌธ์— /dev/random๊ณผ /dev/urandom์œผ๋กœ๋ถ€ํ„ฐ ์˜ค๋Š” ์ˆซ์ž๋Š” ์ฝ˜์†” ํ„ฐ๋ฏธ๋„์— ํ‘œ์‹œํ• ์ˆ˜ ์—†์Œ!
์ด ์žฅ์น˜๋“ค์€ ๋Œ€๋ถ€๋ถ„ ์‹ ๋ขฐ์„ฑ ์žˆ๋Š” ๋‚œ์ˆ˜๋ฅผ ์ˆ˜์ง‘ํ•˜๋ ค๋Š” ๊ฐœ๋ฐœ์ž์— ์˜ํ•ด ์‚ฌ์šฉ.
 /dev/full ์ด ๊ฐ€์ƒ์žฅ์น˜๋Š” ํ•ญ์ƒ ๊ฝ‰์ฐฌ ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ด ์žฅ์น˜์— 
์“ฐ๊ธฐ๋ฅผ ํ•˜๋ฉด ์—๋Ÿฌ๊ฐ€ ๋ฆฌํ„ด
์ฝ๊ธฐ๋ฅผ ํ•˜๋ฉด null ๋ฌธ์ž๊ฐ€ ๋ฌดํ•œํžˆ ๋ฆฌํ„ด
/dev/full ์žฅ์น˜์˜ ๋ชฉ์ ์€ ํ”„๋กœ๊ทธ๋ž˜๋จธ์™€ ๊ด€๋ฆฌ์ž์—๊ฒŒ ์˜๋„์ ์ธ ์—๋Ÿฌ๋ฅผ ์œ ๋ฐœํ•˜๋Š” ์ž‘์—… ์ œ๊ณตํ•œ๋‹ค.
 /dev/zero  null ๋””๋ฐ”์ด์Šค์™€ ๋น„์Šทํ•จ. 
์“ฐ๊ธฐ๋ฅผ ํ–ˆ์„๋•Œ๋Š” ํ•ญ์ƒ ์„ฑ๊ณต
์ฝ๊ธฐ๋ฅผ ํ–ˆ์„๋•Œ๋Š”  null ๋ฌธ์ž๋ฅผ ๋ฌดํ•œํžˆ ์ถœ๋ ฅ

์ดˆ๊ธฐํ™”๋œ ํŠน์ • ํฌ๊ธฐ์˜ ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๊ฑฐ๋‚˜
์ €์žฅ ์žฅ์น˜๋ฅผ ํฌ๋งทํ•˜๊ธฐ ์œ„ํ•ด ์“ฐ๊ธฐ ์ž‘์—…์„ ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์— ์ž…๋ ฅ ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต๊ธ‰ํ•˜๋Š” ๊ฒฝ์šฐ ๋“ฑ..

 
 ์ฐธ๊ณ ๋กœ /dev/null์„ ํŒŒ์ผ๋กœ ์—ด์–ด์„œ ์“ด ์ ์ด ์žˆ๋Š”๋ฐ ๊ฑ”๋„ flush ๋˜๊ธฐ ์ „๊นŒ์ง€๋Š” ์ค‘๊ฐ„ ๋ฒ„ํผ์— ๊ฐ’์ด ๋‚จ์•„์žˆ๋‹ค. ์•„์˜ˆ ์“ฐ์ž๋งˆ์ž ๋ฟ…!์€ ์•„๋‹Œ ๊ฒƒ ๊ฐ™๋‹ค. 

 

(์•„๋ž˜๋Š” /dev/null์— 1234๋ฅผ fprintf ํ•ด์คฌ์„ ๋•Œ์ž„. ์•„์ง ๋ฒ„ํผ๊ฐ€ flush๋˜์ง€ ์•Š์•„์„œ ๋‚ด์šฉ์ด ๋‚จ์•„์žˆ์Œ)

 


 

 Reference

 
https://mungi.kr/430
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_virtualization/managing-virtual-devices_configuring-and-managing-virtualization