Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Installing Gentoo
  • Search

What is the loop device in the installation iso image?

Having problems with the Gentoo Handbook? If you're still working your way through it, or just need some info before you start your install, this is the place. All other questions go elsewhere.
Post Reply
Advanced search
6 posts • Page 1 of 1
Author
Message
marclop
n00b
n00b
Posts: 3
Joined: Sat Apr 04, 2020 11:39 am

What is the loop device in the installation iso image?

  • Quote

Post by marclop » Sat Apr 04, 2020 12:08 pm

I'm doing a fresh install from a USB drive, and I noticed there is a loop device in the result of lsblk named loop0

Code: Select all

# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0    7:0    0 314.1M  1 loop /mnt/livecd
I noticed there is an entire root directory under /mnt/livecd, like

Code: Select all

# ls /mnt/livecd
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  sys  tmp  usr  var
It seems this directory is not mentioned in the handbook, and is not used during the installation? I want to know why there is such a loop device?

P.S. This is my first time gentoo try, and as you might already noticed, English is not my native language. Hope I made myself clear enough, thanks in advance! :wink:
Top
pjp
Administrator
Administrator
User avatar
Posts: 20668
Joined: Tue Apr 16, 2002 10:35 pm

  • Quote

Post by pjp » Sat Apr 04, 2020 5:38 pm

man loop wrote:DESCRIPTION
The loop device is a block device that maps its data blocks not to a physical device such as a hard disk or optical disk drive, but to
the blocks of a regular file in a filesystem or to another block device. This can be useful for example to provide a block device for a
filesystem image stored in a file, so that it can be mounted with the mount(8) command. You could do

$ dd if=/dev/zero of=file.img bs=1MiB count=10
$ sudo losetup /dev/loop4 file.img
$ sudo mkfs -t ext4 /dev/loop4
$ sudo mkdir /myloopdev
$ sudo mount /dev/loop4 /myloopdev
See also: https://en.wikipedia.org/wiki/Loop_device
Quis separabit? Quo animo?
Top
NeddySeagoon
Administrator
Administrator
User avatar
Posts: 56078
Joined: Sat Jul 05, 2003 9:37 am
Location: 56N 3W

  • Quote

Post by NeddySeagoon » Sat Apr 04, 2020 8:06 pm

marclop,

Welcome to Gentoo.

The liveCD/USB requires its own root filesystem. Its actually a whole root filesystem inside a file.
When you boot the liveCD/USB that file is mounted using a loopback mount as root.

Look at the files and directories on the USB drive when its not in use for installing Gentoo.

That answers the question you asked.

The file is compressed, I think its squashfs, to make it faster to download and more importantly, fit onto a CD.

I'm sure that raises more questions than it actually answers.
On to your next Gentoo learning opportunity. :)
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Top
marclop
n00b
n00b
Posts: 3
Joined: Sat Apr 04, 2020 11:39 am

  • Quote

Post by marclop » Sun Apr 05, 2020 4:42 am

Thanks for your reply!

Now I understand where this loop device come from: when my computer boot from usb drive, grub(or another program?) mount the image.squashfs to /mnt/livecd.

But I do have some new questions: What is the relation between / and /mnt/livecd? I guess / is based on /mnt/livecd and during the booting process, some program added some change to /mnt/livecd (like /etc/portage/make.conf) and made it the new /. And maybe that's why everytime I boot from usb drive, changes I made would lost. If I understand it right, which program(s) did these jobs?
Top
NeddySeagoon
Administrator
Administrator
User avatar
Posts: 56078
Joined: Sat Jul 05, 2003 9:37 am
Location: 56N 3W

  • Quote

Post by NeddySeagoon » Sun Apr 05, 2020 9:47 am

marclop,

My explanation above was a bit simplistic.
The root filesystem is a file is both compressed and read only. Even though its on a USB stick, it can't be modified in place.
The file its in is a fixed size. There is no room to add files or even make an existing file bigger.
Files are usually updated by makind the new file under a temporary name, deleting the old file then renaming the new file.

Files on a block storage device always take an integer number of blocks. A block is usually 4kB on disk these days. Thus even a one byte file is allocated a whole 4kB block.
This leads to a lot of unusable space. On average, 2kB per file. With a squashfs filesystem in a file, this unusable space is not stored.

You are correct about the boot loader role.
It passes the root filesystem location to the kernel on the kernel command line, then the kernel performs the mount as it starts up.

I said above that the filesystem in a file is read only. That would not be very satisfactory for performing a Gentoo install. Its correct as far as it goes but it doesn't go far enough.
The make it appear writeable, an overlay filesystem is used. That's a part of RAM used to store changes to the filesystem in a file.
Think of the changes in RAM being a layer over the top of the read only filesystem.

When a file is written, the existing file is copied to RAM (this is called copy on write, CoW for short), and the changes are made in the normal way.
When the changed file is read, the RAM is checked first. I'll gloss over directories, which are just files too but the same thing happens.
As you say, because the changes are never saved to your USB stick, they are lost at reboot.
Keep in mind that all this is intended to work with read only media.

Its possible to add a persistence mode, so the changes can be saved across reboots but that feature is not on the minimal CD.
It involves saving the overlay somewhere that has read/write access and restoring during next boot.

Lots of things make use of the overlay filesystem. Logs are written there, look in /var/log/
Changes you make to /etc go there and many more.
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Top
marclop
n00b
n00b
Posts: 3
Joined: Sat Apr 04, 2020 11:39 am

  • Quote

Post by marclop » Sun Apr 05, 2020 11:59 am

Thanks for your comprehensive information! I have used other linux distributions for two years but never think about these questions, seems I need more fundamental OS knowledges :P
Top
Post Reply

6 posts • Page 1 of 1

Return to “Installing Gentoo”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic