LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 01: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, 01:43 PM   #2
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 5,872

Rep: Reputation: Disabled
The freshly created filesystem is mounted using loop device.
 
Old 05-04-2014, 02: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 03:33 PM.
 
Old 05-04-2014, 03:08 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 11:24 PM
Cannot create gfs2 filesystem : can't open device /dev/drbd1: Read-only file system ruchirarsm Linux - Newbie 0 10-21-2012 04:19 PM
RHEL5 installation error: no device found to create new filesystem. atums Red Hat 1 02-02-2012 09:44 AM
Linux on Xbox: filesystem on loop device simopal6 Linux - Software 3 11-24-2007 01:27 PM
cannot create ext3 filesystem: no such device or address kpachopoulos Linux - General 6 04-28-2007 01:55 AM


All times are GMT -5. The time now is 11:27 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration