LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-04-2014, 12:37 PM   #1
david_8274
Member
 
Registered: Jun 2013
Location: California
Distribution: Ubuntu, Fedora
Posts: 75

Rep: Reputation: Disabled
Using loop device to create a filesystem out of a file


Hi All,

I read online an article about using loop device to create a filesystem out of a file. The procedure is as following:

"
Create a file of a hundred mega-bytes:
dd bs=1M count=100 if=/dev/zero of=output
Format the file:
mkfs.ext2 output
Mount the file with a loop device:
mkdir loop-mount
mount -o loop output loop-mount
When using the option ”-o loop” the first available loop device is taken. It is possible to select the loop device to use by giving the option ”-o loop=/dev/loop0”.
"

After mounting the newly created fs, I am able to go into the fs and do things such as creating a new directory. My question is, even though the title is "Using loop device to create a filesystem", I don't see any involvement of the loop device here when I am using the fielsystem. Could someone explain what role the loop device plays here?

Thanks,
Wei Xu
 
Old 05-04-2014, 12:43 PM   #2
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
The freshly created filesystem is mounted using loop device.
 
Old 05-04-2014, 01:55 PM   #3
linuzfreak
LQ Newbie
 
Registered: Apr 2014
Posts: 21

Rep: Reputation: Disabled
Quote:
Originally Posted by david_8274 View Post
It is possible to select the loop device to use by giving the option ”-o loop=/dev/loop0”.
"
After creating the filesystem for the file called output, create or use a loop device like so. In this example I will be using using loop1. Must be root.

Code:
losetup /dev/loop1 output
To mount the filesystem, type
Code:
mount /dev/loop1 /mnt
/mnt is use here as an example of the mount point.

When done using the filesystem, unmount it and unmap the loop device.
Code:
umount /mnt
losetup -d /dev/loop1
I use this method myself but I use an encrypted file to mount with a loop device.

Hope this helps

Last edited by linuzfreak; 05-04-2014 at 02:33 PM.
 
Old 05-04-2014, 02:08 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by david_8274 View Post
Hi All,

I read online an article about using loop device to create a filesystem out of a file. The procedure is as following:

"
Create a file of a hundred mega-bytes:
dd bs=1M count=100 if=/dev/zero of=output
Format the file:
mkfs.ext2 output
Mount the file with a loop device:
mkdir loop-mount
mount -o loop output loop-mount
When using the option ”-o loop” the first available loop device is taken. It is possible to select the loop device to use by giving the option ”-o loop=/dev/loop0”.
"

After mounting the newly created fs, I am able to go into the fs and do things such as creating a new directory. My question is, even though the title is "Using loop device to create a filesystem", I don't see any involvement of the loop device here when I am using the fielsystem. Could someone explain what role the loop device plays here?

Thanks,
Wei Xu
The loop device is used to translate block read/write requests into offsets into the file. Effectively it maps the file into the definition of a partition.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] create file in for loop. picstruck Linux - Newbie 5 04-29-2013 10:24 PM
Cannot create gfs2 filesystem : can't open device /dev/drbd1: Read-only file system ruchirarsm Linux - Newbie 0 10-21-2012 03:19 PM
RHEL5 installation error: no device found to create new filesystem. atums Red Hat 1 02-02-2012 08:44 AM
Linux on Xbox: filesystem on loop device simopal6 Linux - Software 3 11-24-2007 12:27 PM
cannot create ext3 filesystem: no such device or address kpachopoulos Linux - General 6 04-28-2007 12:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration