[Fedora-livecd-list] persistence and "install to harddrive"

Douglas McClendon dmc.fedora at filteredperception.org
Wed Aug 6 05:14:00 UTC 2008


Jerry Vonau wrote:
>> Yeah, you could easily just do a snapshot and then set LIVE_BLOCK to
>> that.
> Got a magic string? ;-)  DMC, Can you point me in the direction please? 
> I'll play around...

Here is an example.  Note, that trying to do the below on your normal 
rootfs would not be doable (though maybe with snapshot-origin), but it 
would be doable with the livecd because you are playing with devices 
already under devicemapper's control.  Also, here is an absolute gem of 
documentation, which took me a very, very long time to truly understand 
all of.

http://linuxgazette.net/114/kapil.html

# this is the device you want to be able to write
# to without actually writing to.
base_device=/dev/sdZ

# this is the name of the new device that will be
# created which can be used as a writable version
# of the base device, without actually writing to it.
# It will show up as /dev/mapper/${cow_device}
cow_device=mycow

# /dev/shm is a tmpfs available by default.
# a file on a writable disk would work as well
overlay_file=/dev/shm/overlay

# this sets up an overlay file that is a 1G sparse
# file.  I.e. an ls -l will show, 1G, but a du -chs
# will show much of it has actually been written to
dd if=/dev/zero of=${overlay_file} bs=1k \
    count=1 seek=$(( 1024 * 1024 ))

# set up a loop/block device for the overlay file
overlay_loop_device=$( losetup -f )
losetup ${overlay_loop_device} ${overlay_file}

# this is just extra paranoia
# set the base device to read only
blockdev --setro ${base_device}

# now, create the copy-on-write device
# (wrapped for email, not sure if this wrapping
#  will actually work)
dmsetup create ${cow_device} --table \
    "0 $( blockdev --getsize ${base_device} ) \
    snapshot ${base_device} ${overlay_loop_device} p 8"

# inspect stuff
dmsetup status ${cow_device}
ls -lh ${overlay_file}
du -hs ${overlay_file}

# now, do stuff
dd if=/dev/zero of=/dev/mapper/${cow_device} bs=1M count=10

# now inspect stuff for fun
dmsetup status ${cow_device}
ls -lh ${overlay_file}
du -hs ${overlay_file}

# now, tear everything down, no harm no foul.
dmsetup remove ${cow_device}
blockdev --setrw ${base_device}
losetup -d ${overlay_loop_device}
rm -f ${overlay_file}

-dmc




More information about the livecd mailing list