LINUX.ORG.RU

История изменений

Исправление kostik87, (текущая версия) :

Можно просто загрузившись с LiveCD зажать целиком весь корневой раздел, точнее просто всю систему, со всеми смонтированными /var, /usr, /opt и прочим, если они вынесены на отдельные разделы.

mkdir /mnt/system
mount /dev/sdXY /mnt/system
mksquashfs /mnt/system /<path_to_save_squashfs_image>/system.sq -comp xz

Положить образ на какую-нибудь файловую систему.

И указать в init сценарии initramfs монтировать эту файловую систему и образ на ней:


rescue_shell() {
    echo "Something went wrong. Dropping you to a shell."
    busybox --install -s
    setsid cttyhack sh
    exec sh
}


mount -t proc none /proc
mount -t sysfs none /sys

echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s


mount $(findfs LABEL=<метка файловой системы>) /livemnt/media -o ro -n || rescue_shell
mount /livemnt/media/system.sq /livemnt/squashfs -o ro -n
mount none -t tmpfs /livemnt/memory -n
mount rootfs -t aufs /mnt/root/ -o udba=reval,br:/livemnt/memory:/livemnt/squashfs

for i in livemnt/memory livemnt/squashfs livemnt/media
do
  mkdir -p /mnt/root/${i}
  mount -n --move /${i} /mnt/root/${i}
done

mv /fstab /mnt/root/etc/fstab

echo -e "\ntmpfs\t/\t\ttmpfs\t\trw\t0 0\n" >> /mnt/root/etc/fstab

umount /proc
umount /sys

exec switch_root /mnt/root /sbin/init -c /dev/tty1

Файл fstab так же помещается в initramfs, он пустой:

# /etc/fstab: static file system information.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>


Или можно убрать вывод в fstab, заранее отредактировав /etc/fstab перед запаковкой в squashfs образ:

# /etc/fstab: static file system information.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>

tmpfs		/		tmpfs			rw		0 0
/dev/sdXY	/home		<typefs>		defaults,rw	0 0

Вместо LABEL=<метка файловой системы> можно указать UUID=<UUID>

Естественно этот параметр и имя squashfs образа можно сделать передающимися через параметры, которые вы передаёте ядру и которые обрабатывает сценарий init в initramfs.

Исправление kostik87, :

Можно просто загрузившись с LiveCD зажать целиком весь корневой раздел, точнее просто всю систему, со всеми смонтированными /var, /usr, /opt и прочим, если они вынесены на отдельные разделы.

mkdir /mnt/system
mount /dev/sdXY /mnt/system
mksquashfs /mnt/system /<path_to_save_squashfs_image>/system.sq -comp xz

Положить образ на какую-нибудь файловую систему.

И указать в init сценарии initramfs монтировать эту файловую систему и образ на ней:


rescue_shell() {
    echo "Something went wrong. Dropping you to a shell."
    busybox --install -s
    setsid cttyhack sh
    exec sh
}


mount -t proc none /proc
mount -t sysfs none /sys

echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s


mount $(findfs LABEL=<метка файловой системы>) /livemnt/media -o ro -n || rescue_shell
mount /livemnt/media/system.sq /livemnt/squashfs -o ro -n
mount none -t tmpfs /livemnt/memory -n
mount rootfs -t aufs /mnt/root/ -o udba=reval,br:/livemnt/memory:/livemnt/squashfs

for i in livemnt/memory livemnt/squashfs livemnt/media
do
  mkdir -p /mnt/root/${i}
  mount -n --move /${i} /mnt/root/${i}
done

mv /fstab /mnt/root/etc/fstab

echo -e "\ntmpfs\t/\t\ttmpfs\t\trw\t0 0\n" >> /mnt/root/etc/fstab

umount /proc
umount /sys

exec switch_root /mnt/root /sbin/init -c /dev/tty1

Файл fstab так же помещается в initramfs, он пустой:

# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't 
# needed; notail increases performance of ReiserFS (at the expense of storage 
# efficiency).  It's safe to drop the noatime options if you want and to 
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>


Или можно убрать вывод в fstab, заранее отредактировав /etc/fstab перед запаковкой в squashfs образ:

# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't 
# needed; notail increases performance of ReiserFS (at the expense of storage 
# efficiency).  It's safe to drop the noatime options if you want and to 
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>

tmpfs		/		tmpfs			rw		0 0
/dev/sdXY	/home		<typefs>		defaults,rw	0 0

Вместо LABEL=<метка файловой системы> можно указать UUID=<UUID>

Естественно этот параметр и имя squashfs образа можно сделать передающимися через параметры, которые вы передаёте ядру и которые обрабатывает сценарий init в initramfs.

Исправление kostik87, :

Можно просто загрузившись с LiveCD зажать целиком весь корневой раздел, точнее просто всю систему, со всеми смонтированными /var, /usr, /opt и прочим, если они вынесены на отдельные разделы.

mkdir /mnt/system
mount /dev/sdXY /mnt/system
mksquashfs /mnt/system /<path_to_save_squashfs_image>/system.sq -comp xz

Положить образ на какую-нибудь файловую систему.

И указать в init сценарии initramfs монтировать эту файловую систему и образ на ней:

mount $(findfs LABEL=<метка файловой системы>) /livemnt/media -o ro -n || rescue_shell
mount /livemnt/media/system.sq /livemnt/squashfs -o ro -n
mount none -t tmpfs /livemnt/memory -n
mount rootfs -t aufs /mnt/root/ -o udba=reval,br:/livemnt/memory:/livemnt/squashfs

for i in livemnt/memory livemnt/squashfs livemnt/media
do
  mkdir -p /mnt/root/${i}
  mount -n --move /${i} /mnt/root/${i}
done

mv /fstab /mnt/root/etc/fstab

echo -e "\ntmpfs\t/\t\ttmpfs\t\trw\t0 0\n" >> /mnt/root/etc/fstab

umount /proc
umount /sys

exec switch_root /mnt/root /sbin/init -c /dev/tty1

Файл fstab так же помещается в initramfs, он пустой:

# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't 
# needed; notail increases performance of ReiserFS (at the expense of storage 
# efficiency).  It's safe to drop the noatime options if you want and to 
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>


Или можно убрать вывод в fstab, заранее отредактировав /etc/fstab перед запаковкой в squashfs образ:

# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't 
# needed; notail increases performance of ReiserFS (at the expense of storage 
# efficiency).  It's safe to drop the noatime options if you want and to 
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>

tmpfs		/		tmpfs			rw		0 0
/dev/sdXY	/home		<typefs>		defaults,rw	0 0

Вместо LABEL=<метка файловой системы> можно указать UUID=<UUID>

Естественно этот параметр и имя squashfs образа можно сделать передающимися через параметры, которые вы передаёте ядру и которые обрабатывает сценарий init в initramfs.

Исходная версия kostik87, :

Можно просто загрузившись с LiveCD зажать целиком весь корневой раздел, точнее просто всю систему, со всеми смонтированными /var, /usr, /opt и прочим, если они вынесены на отдельные разделы.

mkdir /mnt/system
mount /dev/sdXY /mnt/system
mksquashfs /mnt/system /<path_to_save_squashfs_image>/system.sq -comp xz

Положить образ на какую-нибудь файловую систему.

И указать в init сценарии initramfs монтировать эту файловую систему и образ на ней:

mount $(findfs LABEL=<метка файловой системы>) /livemnt/media -o ro -n || rescue_shell
mount /livemnt/media/system.sq /livemnt/squashfs -o ro -n
mount none -t tmpfs /livemnt/memory -n
mount rootfs -t aufs /mnt/root/ -o udba=reval,br:/livemnt/memory:/livemnt/squashfs

for i in livemnt/memory livemnt/squashfs livemnt/media
do
  mkdir -p /mnt/root/${i}
  mount -n --move /${i} /mnt/root/${i}
done

mv /fstab /mnt/root/etc/fstab

echo -e "\ntmpfs\t/\t\ttmpfs\t\trw\t0 0\n" >> /mnt/root/etc/fstab

Файл fstab так же помещается в initramfs, он пустой:

# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't 
# needed; notail increases performance of ReiserFS (at the expense of storage 
# efficiency).  It's safe to drop the noatime options if you want and to 
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>


Или можно убрать вывод в fstab, заранее отредактировав /etc/fstab перед запаковкой в squashfs образ:

# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't 
# needed; notail increases performance of ReiserFS (at the expense of storage 
# efficiency).  It's safe to drop the noatime options if you want and to 
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>

tmpfs		/		tmpfs			rw		0 0
/dev/sdXY	/home		<typefs>		defaults,rw	0 0

Вместо LABEL=<метка файловой системы> можно указать UUID=<UUID>

Естественно этот параметр и имя squashfs образа можно сделать передающимися через параметры, которые вы передаёте ядру и которые обрабатывает сценарий init в initramfs.