How to create a multi partition SD disk image without root privileges?

后端 未结 5 772
陌清茗
陌清茗 2021-02-13 11:06

Is it possible to create a complete SD image in linux without having root privileges (that is, no loopback mount)? I\'m looking for a way to automate embedded system image creat

5条回答
  •  感动是毒
    2021-02-13 11:19

    I had this problem and couldn't find a viable solution, so I wrote this utility that we've open-sourced here.

    From the README:

    $ dd if=/dev/zero of=disk.image bs=1M count=4
    4+0 records in
    4+0 records out
    4194304 bytes (4.2 MB, 4.0 MiB) copied, 0.00470867 s, 891 MB/s
    $ parted --script disk.image \
        mktable msdos mkpart primary 2048s 100% set 1 boot on
    $ mkdir mntdir
    $ partfs -o dev=disk.image mntdir
    $ mkfs.ext4 mntdir/p1
    mke2fs 1.42.13 (17-May-2015)
    Creating filesystem with 3072 1k blocks and 768 inodes
    
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (1024 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    $ fusermount -u mntdir
    

提交回复
热议问题